-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathCoinChangeTest.java
60 lines (51 loc) · 2.19 KB
/
CoinChangeTest.java
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
package com.thealgorithms.greedyalgorithms;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
public class CoinChangeTest {
@Test
public void testCoinChangeProblemWithValidAmount() {
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(500, 50, 20, 20, 1));
ArrayList<Integer> coins = CoinChange.coinChangeProblem(591);
assertEquals(expected, coins);
}
@Test
public void testCoinChangeProblemWithLargeAmount() {
List<Integer> expected = singletonList(2000);
ArrayList<Integer> coins = CoinChange.coinChangeProblem(2000);
assertEquals(expected, coins);
}
@Test
public void testCoinChangeProblemWithPartialCoins2() {
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(500, 50, 20));
ArrayList<Integer> coins = CoinChange.coinChangeProblem(570);
assertEquals(expected, coins);
}
@Test
public void testCoinChangeProblemWithSmallAmount() {
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(2, 1));
ArrayList<Integer> coins = CoinChange.coinChangeProblem(3);
assertEquals(expected, coins);
}
@Test
public void testCoinChangeProblemWithLargeAmountAndMultipleDenominations() {
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(2000, 2000, 2000, 2000, 500, 500, 500, 100, 100, 100, 100, 50, 20, 20, 5, 2, 2));
ArrayList<Integer> coins = CoinChange.coinChangeProblem(9999);
assertEquals(expected, coins);
}
@Test
public void testCoinChangeProblemWithAllDenominations() {
ArrayList<Integer> expected = new ArrayList<>(Arrays.asList(2000, 500, 100, 100, 100, 50, 20, 10, 5, 2, 1));
ArrayList<Integer> coins = CoinChange.coinChangeProblem(2888);
assertEquals(expected, coins);
}
@Test
public void testCoinChangeProblemWithZeroAmount() {
ArrayList<Integer> expected = new ArrayList<>();
ArrayList<Integer> coins = CoinChange.coinChangeProblem(0);
assertEquals(expected, coins);
}
}