-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathIterableMultipliationTest.kt
54 lines (47 loc) · 2.63 KB
/
IterableMultipliationTest.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
50
51
52
53
54
package com.marcinmoskala.math.tests
import com.marcinmoskala.math.times
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
internal class IterableMultipliationTest {
@Test fun `When one list empty then multiplication is also returning empty`() {
assertEquals(listOf<Int>(), listOf<Int>() * listOf<Int>())
assertEquals(listOf<Int>(), listOf<Int>(1) * listOf<Int>())
assertEquals(listOf<Int>(), listOf<Int>() * listOf<Int>(1))
assertEquals(listOf<Int>(), listOf<Int>(1, 2) * listOf<Int>())
}
@Test fun `When size of one list is 1 then multiplication of it with other list returns list with size of second with element of it paired with element from other list`() {
assertEquals(listOf("A" to 1, "A" to 2), listOf("A") * listOf(1, 2))
assertEquals(listOf("A" to 1, "A" to 2, "A" to 3), listOf("A") * listOf(1, 2, 3))
assertEquals(listOf("A" to 1, "A" to 2, "A" to 2), listOf("A") * listOf(1, 2, 2))
}
@Test fun `Simple list multiplication returns each combination of pairs from lists`() {
assertEquals(listOf("A" to 1, "A" to 2, "B" to 1, "B" to 2), listOf("A", "B") * listOf(1, 2))
}
@Test fun `Multiplication of tree lists is returning triple with each combination of each lists`() {
assertEquals(listOf(
Triple("A", 1, 'a'),
Triple("A", 1, 'b'),
Triple("A", 2, 'a'),
Triple("A", 2, 'b'),
Triple("B", 1, 'a'),
Triple("B", 1, 'b'),
Triple("B", 2, 'a'),
Triple("B", 2, 'b')
), listOf("A", "B") * listOf(1, 2) * listOf('a', 'b'))
}
@Test fun `Size of result of list multipication is equeal to multiplication of list sizes`() {
val list1 = (1..5).toList()
val list2 = (1..10).toList()
val list3 = (1..25).toList()
assertEquals(list1.size * list2.size, (list1 * list2).size)
assertEquals(list1.size * list3.size, (list1 * list3).size)
assertEquals(list2.size * list3.size, (list2 * list3).size)
assertEquals(list1.size * list1.size, (list1 * list1).size)
assertEquals(list2.size * list2.size, (list2 * list2).size)
assertEquals(list3.size * list3.size, (list3 * list3).size)
assertEquals(list1.size * list2.size * list3.size, (list1 * list2 * list3).size)
assertEquals(list1.size * list1.size * list1.size, (list1 * list1 * list1).size)
assertEquals(list2.size * list2.size * list2.size, (list2 * list2 * list2).size)
assertEquals(list3.size * list3.size * list3.size, (list3 * list3 * list3).size)
}
}