-
Notifications
You must be signed in to change notification settings - Fork 2
/
CoinFreeTest.java
87 lines (67 loc) · 2.27 KB
/
CoinFreeTest.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
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
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
import java.util.ArrayList;
import java.util.List;
public class CoinFreeTest {
@Test
public void testUS() {
List<int[]> tests = new ArrayList<int[]>();
tests.add(new int[]{1, 1});
tests.add(new int[]{10, 1});
tests.add(new int[]{25, 1});
tests.add(new int[]{50, 2});
tests.add(new int[]{73, 7});
tests.add(new int[]{125, 5});
tests.add(new int[]{100, 4});
int[] denom = {1, 5, 10, 25};
for (int[] test : tests) {
int solution = CoinFree.solve(test[0], denom);
assertEquals("Testing for " + test[0] + " cents.", test[1], solution);
}
}
@Test
public void testRichAmericans() {
List<int[]> tests = new ArrayList<int[]>();
tests.add(new int[]{12312, 495});
tests.add(new int[]{34576, 1384});
tests.add(new int[]{129671, 5189});
tests.add(new int[]{12372, 498});
tests.add(new int[]{120201, 4809});
int[] denom = {1, 5, 10, 25};
for (int[] test : tests) {
int solution = CoinFree.solve(test[0], denom);
assertEquals("Testing for " + test[0] + " cents.", test[1], solution);
}
}
@Test
public void testStrangeCurrency() {
List<int[]> tests = new ArrayList<int[]>();
tests.add(new int[]{1, 1});
tests.add(new int[]{10, 2});
tests.add(new int[]{25, 5});
tests.add(new int[]{50, 6});
tests.add(new int[]{73, 7});
tests.add(new int[]{125, 7});
tests.add(new int[]{100, 8});
int[] denom = {1, 3, 7, 27};
for (int[] test : tests) {
int solution = CoinFree.solve(test[0], denom);
assertEquals("Testing for " + test[0] + " cents.", test[1], solution);
}
}
@Test
public void testRichStrangers() {
List<int[]> tests = new ArrayList<int[]>();
tests.add(new int[]{1232, 48});
tests.add(new int[]{346, 16});
tests.add(new int[]{1291, 51});
tests.add(new int[]{1232, 48});
tests.add(new int[]{1201, 47});
int[] denom = {1, 3, 7, 27};
for (int[] test : tests) {
int solution = CoinFree.solve(test[0], denom);
assertEquals("Testing for " + test[0] + " cents.", test[1], solution);
}
}
}