Skip to content

Commit 7175325

Browse files
committed
implement tests ValueCheckPointDistribution
1 parent 94ceead commit 7175325

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package io.monstarlab.mosaic.slider
2+
3+
import org.junit.Assert.*
4+
5+
import org.junit.After
6+
import org.junit.Before
7+
import org.junit.Test
8+
9+
class ValueCheckPointDistributionTest {
10+
11+
private lateinit var valueCheckPointDistribution : ValueCheckPointDistribution
12+
private val accuracy = 0.0001f
13+
14+
@Before
15+
fun setUp() {
16+
17+
valueCheckPointDistribution = ValueCheckPointDistribution(
18+
listOf(
19+
0f to 0f,
20+
25f to 25f,
21+
50f to 75f,
22+
100f to 100f,
23+
)
24+
)
25+
}
26+
27+
@After
28+
fun tearDown() {
29+
}
30+
31+
@Test
32+
fun `test create from pairs with decreasing value`() {
33+
assertThrows(ValueCheckPointDistribution.DecreasingValueException::class.java) {
34+
ValueCheckPointDistribution(
35+
listOf(
36+
0f to 0f,
37+
5f to 10f,
38+
8f to 16f,
39+
7f to 20f,
40+
)
41+
)
42+
}
43+
44+
}
45+
46+
@Test
47+
fun `create from pairs and interpolate`() {
48+
49+
val points = listOf(
50+
0.1f to 0.1f,
51+
0.2f to 0.2f,
52+
0.25f to 0.25f,
53+
0.4f to 0.55f,
54+
0.6f to 0.8f,
55+
0.75f to 0.875f,
56+
)
57+
points.forEach {
58+
assertEquals(it.second, valueCheckPointDistribution.interpolate(it.first), accuracy)
59+
}
60+
61+
}
62+
63+
@Test
64+
fun `create from pairs and inverse`() {
65+
66+
val points = listOf(
67+
0.1f to 0.1f,
68+
0.2f to 0.2f,
69+
0.25f to 0.25f,
70+
0.4f to 0.55f,
71+
0.6f to 0.8f,
72+
0.75f to 0.875f,
73+
)
74+
points.forEach {
75+
assertEquals(it.first, valueCheckPointDistribution.inverse(it.second), accuracy)
76+
}
77+
78+
}
79+
}

0 commit comments

Comments
 (0)