1
exercism fetch kotlin change

src/test/kotlin/ChangeCalculatorTest.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
import org.assertj.core.api.Assertions.assertThat
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException

class ChangeCalculatorTest {

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

    @Test
    fun singleCoinChange() {
        val computedChange = ChangeCalculator(listOf(1, 5, 10, 25, 100)).computeMostEfficientChange(25)
        assertThat(computedChange).containsExactly(25)
    }

    @Ignore
    @Test
    fun multipleCoinChange() {
        val computedChange = ChangeCalculator(listOf(1, 5, 10, 25, 100)).computeMostEfficientChange(15)
        assertThat(computedChange).containsExactly(5, 10)
    }

    @Ignore
    @Test
    fun changeWithLilliputianCoins() {
        val computedChange = ChangeCalculator(listOf(1, 4, 15, 20, 50)).computeMostEfficientChange(23)
        assertThat(computedChange).containsExactly(4, 4, 15)
    }

    @Ignore
    @Test
    fun changeWithLowerElboniaCoins() {
        val computedChange = ChangeCalculator(listOf(1, 5, 10, 21, 25)).computeMostEfficientChange(63)
        assertThat(computedChange).containsExactly(21, 21, 21)
    }

    @Ignore
    @Test
    fun largeTargetValues() {
        val computedChange = ChangeCalculator(listOf(1, 2, 5, 10, 20, 50, 100)).computeMostEfficientChange(999)
        assertThat(computedChange)
                .containsExactly(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100)
    }

    @Ignore
    @Test
    fun possibleChangeWithoutUnitCoinsAvailable() {
        val computedChange = ChangeCalculator(listOf(2, 5, 10, 20, 50)).computeMostEfficientChange(21)
        assertThat(computedChange).containsExactly(2, 2, 2, 5, 10)
    }

    @Ignore
    @Test
    fun anotherPossibleChangeWithoutUnitCoinsAvailable() {
        val computedChange = ChangeCalculator(listOf(4, 5)).computeMostEfficientChange(27)
        assertThat(computedChange).containsExactly(4, 4, 4, 5, 5, 5)
    }

    @Ignore
    @Test
    fun noCoinsMake0Change() {
        val computedChange = ChangeCalculator(listOf(1, 5, 10, 21, 25)).computeMostEfficientChange(0)
        assertThat(computedChange).isEmpty()
    }

    @Ignore
    @Test
    fun errorTestingForChangeSmallerThanTheSmallestCoin() {
        val changeCalculator = ChangeCalculator(listOf(5, 10))

        expectedException.expect(IllegalArgumentException::class.java)
        expectedException.expectMessage("The total 3 cannot be represented in the given currency.")

        changeCalculator.computeMostEfficientChange(3)
    }

    @Ignore
    @Test
    fun errorIfNoCombinationCanAddUpToTarget() {
        val changeCalculator = ChangeCalculator(listOf(5, 10))

        expectedException.expect(IllegalArgumentException::class.java)
        expectedException.expectMessage("The total 94 cannot be represented in the given currency.")

        changeCalculator.computeMostEfficientChange(94)
    }

    @Ignore
    @Test
    fun cannotFindNegativeChangeValues() {
        val changeCalculator = ChangeCalculator(listOf(1, 2, 5))

        expectedException.expect(IllegalArgumentException::class.java)
        expectedException.expectMessage("Negative totals are not allowed.")

        changeCalculator.computeMostEfficientChange(-5)
    }

}