Fix prerelease test function

This commit is contained in:
firelight 2024-07-29 00:58:35 +02:00 committed by GitHub
parent 04dda008c4
commit 82f8ab489e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 19 deletions

View file

@ -33,7 +33,8 @@ import java.text.DecimalFormat
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.log10 import kotlin.math.log10
import kotlin.math.pow import kotlin.math.pow
import org.junit.Test
import org.junit.Assert
data class PluginViewData( data class PluginViewData(
val plugin: Plugin, val plugin: Plugin,
@ -96,13 +97,23 @@ class PluginAdapter(
} }
companion object { companion object {
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) private tailrec fun findClosestBase2(target: Int, current: Int = 16, max: Int = 512): Int {
tailrec fun findClosestBase2(target: Int, current: Int = 16, max: Int = 512): Int {
if (current >= max) return max if (current >= max) return max
if (current >= target) return current if (current >= target) return current
return findClosestBase2(target, current * 2, max) return findClosestBase2(target, current * 2, max)
} }
// DO NOT MOVE, as running this test will result in ExceptionInInitializerError on prerelease due to static variables using Resources.getSystem()
// this test function is only to show how the function works
@Test
fun testFindClosestBase2() {
Assert.assertEquals(16, findClosestBase2(0))
Assert.assertEquals(256, findClosestBase2(170))
Assert.assertEquals(256, findClosestBase2(256))
Assert.assertEquals(512, findClosestBase2(257))
Assert.assertEquals(512, findClosestBase2(700))
}
private val iconSizeExact = 32.toPx private val iconSizeExact = 32.toPx
private val iconSize by lazy { private val iconSize by lazy {
findClosestBase2(iconSizeExact, 16, 512) findClosestBase2(iconSizeExact, 16, 512)

View file

@ -1,16 +0,0 @@
package com.lagradost.cloudstream3
import com.lagradost.cloudstream3.ui.settings.extensions.PluginAdapter.Companion.findClosestBase2
import org.junit.Assert
import org.junit.Test
class PluginAdapterTest {
@Test
fun testFindClosestBase2() {
Assert.assertEquals(16, findClosestBase2(0))
Assert.assertEquals(256, findClosestBase2(170))
Assert.assertEquals(256, findClosestBase2(256))
Assert.assertEquals(512, findClosestBase2(257))
Assert.assertEquals(512, findClosestBase2(700))
}
}