-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathNumberSplitTest.kt
49 lines (42 loc) · 1.46 KB
/
NumberSplitTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.marcinmoskala.math.tests
import com.marcinmoskala.math.splitsNumber
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
internal class NumberSplitTest {
@Test fun `splitsNumber function for number is throwing error when asked for groupsNum of size smaller then 0`() {
for (groupsNum in -10..-1) {
for (num in 0..10) {
assertIsThrowingError { num.splitsNumber(groupsNum) }
}
}
}
@Test
fun `n number can be only one way splitted to one or n components`() {
for (n in 1..100) {
assertEquals(1, n.splitsNumber(1))
assertEquals(1, n.splitsNumber(n))
}
}
@Test
fun `For 0 splits, number splits function is returning 1 for 0 and 0 otherwise`() {
assertEquals(1, 0.splitsNumber(0))
for (n in 1..100) {
assertEquals(0, n.splitsNumber(0))
}
}
@Test
fun `Number splits function is correct according to recurrence definition`() {
for (n in 1..10) {
for (k in 1..(n - 1)) {
assertEquals(n.splitsNumber(k), (1..k).sumBy { i -> (n - k).splitsNumber(i) })
}
}
}
@Test
fun `Simple number splits examples are calculated correctly`() {
assertEquals(3, 7.splitsNumber(4))
assertEquals(11, 11.splitsNumber(4))
assertEquals(5, 9.splitsNumber(5))
assertEquals(7, 13.splitsNumber(8))
}
}