Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 38 additions & 23 deletions exercises/practice/change/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
[canonical-tests]
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

# single coin change
"36887bea-7f92-4a9c-b0cc-c0e886b3ecc8" = true
[d0ebd0e1-9d27-4609-a654-df5c0ba1d83a]
description = "change for 1 cent"

# multiple coin change
"cef21ccc-0811-4e6e-af44-f011e7eab6c6" = true
[36887bea-7f92-4a9c-b0cc-c0e886b3ecc8]
description = "single coin change"

# change with Lilliputian Coins
"d60952bc-0c1a-4571-bf0c-41be72690cb3" = true
[cef21ccc-0811-4e6e-af44-f011e7eab6c6]
description = "multiple coin change"

# change with Lower Elbonia Coins
"408390b9-fafa-4bb9-b608-ffe6036edb6c" = true
[d60952bc-0c1a-4571-bf0c-41be72690cb3]
description = "change with Lilliputian Coins"

# large target values
"7421a4cb-1c48-4bf9-99c7-7f049689132f" = true
[408390b9-fafa-4bb9-b608-ffe6036edb6c]
description = "change with Lower Elbonia Coins"

# possible change without unit coins available
"f79d2e9b-0ae3-4d6a-bb58-dc978b0dba28" = true
[7421a4cb-1c48-4bf9-99c7-7f049689132f]
description = "large target values"

# another possible change without unit coins available
"9a166411-d35d-4f7f-a007-6724ac266178" = true
[f79d2e9b-0ae3-4d6a-bb58-dc978b0dba28]
description = "possible change without unit coins available"

# no coins make 0 change
"bbbcc154-e9e9-4209-a4db-dd6d81ec26bb" = true
[9a166411-d35d-4f7f-a007-6724ac266178]
description = "another possible change without unit coins available"

# error testing for change smaller than the smallest of coins
"c8b81d5a-49bd-4b61-af73-8ee5383a2ce1" = true
[ce0f80d5-51c3-469d-818c-3e69dbd25f75]
description = "a greedy approach is not optimal"

# error if no combination can add up to target
"3c43e3e4-63f9-46ac-9476-a67516e98f68" = true
[bbbcc154-e9e9-4209-a4db-dd6d81ec26bb]
description = "no coins make 0 change"

# cannot find negative change values
"8fe1f076-9b2d-4f44-89fe-8a6ccd63c8f3" = true
[c8b81d5a-49bd-4b61-af73-8ee5383a2ce1]
description = "error testing for change smaller than the smallest of coins"

[3c43e3e4-63f9-46ac-9476-a67516e98f68]
description = "error if no combination can add up to target"

[8fe1f076-9b2d-4f44-89fe-8a6ccd63c8f3]
description = "cannot find negative change values"
42 changes: 29 additions & 13 deletions exercises/practice/change/src/test/kotlin/ChangeCalculatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,80 @@ class ChangeCalculatorTest {
var expectedException: ExpectedException = ExpectedException.none()

@Test
fun singleCoinChange() {
fun `change for 1 cent`() {
var computedChange = ChangeCalculator(listOf(1, 5, 10, 25)).computeMostEfficientChange(1)
assertContainsExactly(computedChange, listOf(1))
}

@Ignore
@Test
fun `single coin change`() {
val computedChange = ChangeCalculator(listOf(1, 5, 10, 25, 100)).computeMostEfficientChange(25)
assertContainsExactly(computedChange, listOf(25))
}

@Ignore
@Test
fun multipleCoinChange() {
fun `multiple coin change`() {
val computedChange = ChangeCalculator(listOf(1, 5, 10, 25, 100)).computeMostEfficientChange(15)
assertContainsExactly(computedChange, listOf(5, 10))
}

@Ignore
@Test
fun changeWithLilliputianCoins() {
fun `change with Lilliputian Coins`() {
val computedChange = ChangeCalculator(listOf(1, 4, 15, 20, 50)).computeMostEfficientChange(23)
assertContainsExactly(computedChange, listOf(4, 4, 15))
}

@Ignore
@Test
fun changeWithLowerElboniaCoins() {
fun `change with Lower Elbonia Coins`() {
val computedChange = ChangeCalculator(listOf(1, 5, 10, 21, 25)).computeMostEfficientChange(63)
assertContainsExactly(computedChange, listOf(21, 21, 21))
}

@Ignore
@Test
fun largeTargetValues() {
fun `large target values`() {
val computedChange = ChangeCalculator(listOf(1, 2, 5, 10, 20, 50, 100)).computeMostEfficientChange(999)
assertContainsExactly(computedChange,
listOf(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100))
assertContainsExactly(
computedChange,
listOf(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100)
)
}

@Ignore
@Test
fun possibleChangeWithoutUnitCoinsAvailable() {
fun `possible change without unit coins available`() {
val computedChange = ChangeCalculator(listOf(2, 5, 10, 20, 50)).computeMostEfficientChange(21)
assertContainsExactly(computedChange, listOf(2, 2, 2, 5, 10))
}

@Ignore
@Test
fun anotherPossibleChangeWithoutUnitCoinsAvailable() {
fun `another possible change without unit coins available`() {
val computedChange = ChangeCalculator(listOf(4, 5)).computeMostEfficientChange(27)
assertContainsExactly(computedChange, listOf(4, 4, 4, 5, 5, 5))
}

@Ignore
@Test
fun noCoinsMake0Change() {
fun `a greedy approach is not optimal`() {
val computedChange = ChangeCalculator(listOf(1, 10, 11)).computeMostEfficientChange(20)
assertContainsExactly(computedChange, listOf(10, 10))
}

@Ignore
@Test
fun `no coins make 0 change`() {
val computedChange = ChangeCalculator(listOf(1, 5, 10, 21, 25)).computeMostEfficientChange(0)
assertEquals(0, computedChange.size)
}

@Ignore
@Test
fun errorTestingForChangeSmallerThanTheSmallestCoin() {
fun `error testing for change smaller than the smallest of coins`() {
val changeCalculator = ChangeCalculator(listOf(5, 10))

expectedException.expect(IllegalArgumentException::class.java)
Expand All @@ -79,7 +95,7 @@ class ChangeCalculatorTest {

@Ignore
@Test
fun errorIfNoCombinationCanAddUpToTarget() {
fun `error if no combination can add up to target`() {
val changeCalculator = ChangeCalculator(listOf(5, 10))

expectedException.expect(IllegalArgumentException::class.java)
Expand All @@ -90,7 +106,7 @@ class ChangeCalculatorTest {

@Ignore
@Test
fun cannotFindNegativeChangeValues() {
fun `cannot find negative change values`() {
val changeCalculator = ChangeCalculator(listOf(1, 2, 5))

expectedException.expect(IllegalArgumentException::class.java)
Expand Down