Faster Expandable Text calculator.

This commit is contained in:
Vitor Pamplona
2024-02-05 19:37:21 -05:00
parent b13b832696
commit 845c99b798
3 changed files with 52 additions and 27 deletions

View File

@@ -24,6 +24,7 @@ import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.vitorpamplona.amethyst.commons.ExpandableTextParser
import com.vitorpamplona.amethyst.commons.nthIndexOf
import junit.framework.TestCase
import org.junit.Rule
import org.junit.Test
@@ -38,18 +39,38 @@ class ExpandableViewComputationBenchmark {
fun computeTestCase1() {
benchmarkRule.measureRepeated {
TestCase.assertEquals(
294,
ExpandableTextParser().computeWhereToCutIfPostIsTooLong(testCase1),
293,
testCase1.nthIndexOf('\n', 10),
)
}
}
@Test
fun computeTestCase2() {
benchmarkRule.measureRepeated {
TestCase.assertEquals(
423,
testCase2.nthIndexOf('\n', 10),
)
}
}
@Test
fun computeTestCase1All() {
benchmarkRule.measureRepeated {
TestCase.assertEquals(
293,
ExpandableTextParser.computeWhereToCutIfPostIsTooLong(testCase1),
)
}
}
@Test
fun computeTestCase2All() {
benchmarkRule.measureRepeated {
TestCase.assertEquals(
355,
ExpandableTextParser().computeWhereToCutIfPostIsTooLong(testCase2),
ExpandableTextParser.computeWhereToCutIfPostIsTooLong(testCase2),
)
}
}