1
exercism fetch kotlin pascals-triangle

src/test/kotlin/PascalsTriangleTest.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import org.junit.Test
import org.junit.Ignore
import org.junit.Rule
import org.junit.rules.ExpectedException
import kotlin.test.assertEquals

class PascalsTriangleTest {

    @Rule
    @JvmField
    var expectedException: ExpectedException = ExpectedException.none()

    @Test
    fun zeroRows() {
        val expectedOutput = emptyList<List<Int>>()

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(0))
    }

    @Ignore
    @Test
    fun oneRow() {
        val expectedOutput = listOf(
                listOf(1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(1))
    }

    @Ignore
    @Test
    fun twoRows() {
        val expectedOutput = listOf(
                listOf(1),
                listOf(1, 1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(2))
    }

    @Ignore
    @Test
    fun threeRows() {
        val expectedOutput = listOf(
                listOf(1),
                listOf(1, 1),
                listOf(1, 2, 1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(3))
    }

    @Ignore
    @Test
    fun fourRows() {
        val expectedOutput = listOf(
                listOf(1),
                listOf(1, 1),
                listOf(1, 2, 1),
                listOf(1, 3, 3, 1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(4))
    }

    @Ignore
    @Test
    fun fiveRows() {
        val expectedOutput = listOf(
                listOf(1),
                listOf(1, 1),
                listOf(1, 2, 1),
                listOf(1, 3, 3, 1),
                listOf(1, 4, 6, 4, 1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(5))
    }

    @Ignore
    @Test
    fun sixRows() {
        val expectedOutput = listOf(
                listOf(1),
                listOf(1, 1),
                listOf(1, 2, 1),
                listOf(1, 3, 3, 1),
                listOf(1, 4, 6, 4, 1),
                listOf(1, 5, 10, 10, 5, 1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(6))
    }

    @Ignore
    @Test
    fun tenRows() {
        val expectedOutput = listOf(
                listOf(1),
                listOf(1, 1),
                listOf(1, 2, 1),
                listOf(1, 3, 3, 1),
                listOf(1, 4, 6, 4, 1),
                listOf(1, 5, 10, 10, 5, 1),
                listOf(1, 6, 15, 20, 15, 6, 1),
                listOf(1, 7, 21, 35, 35, 21, 7, 1),
                listOf(1, 8, 28, 56, 70, 56, 28, 8, 1),
                listOf(1, 9, 36, 84, 126, 126, 84, 36, 9, 1)
        )

        assertEquals(expectedOutput, PascalsTriangle.computeTriangle(10))
    }

    @Ignore
    @Test
    fun validatesNotNegativeRows() {
        expectedException.expect(IllegalArgumentException::class.java)
        expectedException.expectMessage("Rows can't be negative!")

        PascalsTriangle.computeTriangle(-1)
    }

}