Skip to content

Commit

Permalink
Update change calculator test to use assertj (#2147) (#2509)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanbaloju authored Oct 5, 2023
1 parent 438b3ed commit 633956b
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions exercises/practice/change/src/test/java/ChangeCalculatorTest.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import org.junit.Ignore;
import org.junit.Test;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

public class ChangeCalculatorTest {

@Test
public void testChangeThatCanBeGivenInASingleCoin() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 25, 100));

assertEquals(
singletonList(25),
changeCalculator.computeMostEfficientChange(25));
assertThat(changeCalculator.computeMostEfficientChange(25))
.containsExactly(25);
}

@Ignore("Remove to run test")
@Test
public void testChangeThatMustBeGivenInMultipleCoins() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 25, 100));

assertEquals(
asList(5, 10),
changeCalculator.computeMostEfficientChange(15));
assertThat(changeCalculator.computeMostEfficientChange(15))
.containsExactly(5, 10);
}

@Ignore("Remove to run test")
Expand All @@ -34,9 +30,8 @@ public void testChangeThatMustBeGivenInMultipleCoins() {
public void testLilliputianCurrency() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 4, 15, 20, 50));

assertEquals(
asList(4, 4, 15),
changeCalculator.computeMostEfficientChange(23));
assertThat(changeCalculator.computeMostEfficientChange(23))
.containsExactly(4, 4, 15);
}

@Ignore("Remove to run test")
Expand All @@ -45,19 +40,17 @@ public void testLilliputianCurrency() {
public void testLowerElbonianCurrency() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 21, 25));

assertEquals(
asList(21, 21, 21),
changeCalculator.computeMostEfficientChange(63));
assertThat(changeCalculator.computeMostEfficientChange(63))
.containsExactly(21, 21, 21);
}

@Ignore("Remove to run test")
@Test
public void testLargeAmountOfChange() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 2, 5, 10, 20, 50, 100));

assertEquals(
asList(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100),
changeCalculator.computeMostEfficientChange(999));
assertThat(changeCalculator.computeMostEfficientChange(999))
.containsExactly(2, 2, 5, 20, 20, 50, 100, 100, 100, 100, 100, 100, 100, 100, 100);
}

@Ignore("Remove to run test")
Expand All @@ -66,9 +59,8 @@ public void testLargeAmountOfChange() {
public void testPossibleChangeWithoutUnitCoinAvailable() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(2, 5, 10, 20, 50));

assertEquals(
asList(2, 2, 2, 5, 10),
changeCalculator.computeMostEfficientChange(21));
assertThat(changeCalculator.computeMostEfficientChange(21))
.containsExactly(2, 2, 2, 5, 10);
}

@Ignore("Remove to run test")
Expand All @@ -77,19 +69,17 @@ public void testPossibleChangeWithoutUnitCoinAvailable() {
public void testAnotherPossibleChangeWithoutUnitCoinAvailable() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(4, 5));

assertEquals(
asList(4, 4, 4, 5, 5, 5),
changeCalculator.computeMostEfficientChange(27));
assertThat(changeCalculator.computeMostEfficientChange(27))
.containsExactly(4, 4, 4, 5, 5, 5);
}

@Ignore("Remove to run test")
@Test
public void testZeroChange() {
ChangeCalculator changeCalculator = new ChangeCalculator(asList(1, 5, 10, 21, 25));

assertEquals(
emptyList(),
changeCalculator.computeMostEfficientChange(0));
assertThat(changeCalculator.computeMostEfficientChange(0))
.isEmpty();
}

@Ignore("Remove to run test")
Expand Down

0 comments on commit 633956b

Please sign in to comment.