1
1
package balancer .logic .command ;
2
2
3
- import balancer .storage .Transaction ;
4
- import org .junit .jupiter .api .Test ;
3
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
5
4
6
- import java .util .ArrayList ;
7
5
import java .util .HashMap ;
8
6
import java .util .List ;
9
7
10
- import static org .junit .jupiter .api .Assertions .*;
8
+ import org .junit .jupiter .api .Test ;
9
+
10
+ import balancer .storage .Transaction ;
11
11
12
12
class CalculateCommandTest {
13
- CalculateCommand cc = new CalculateCommand ();
13
+ private CalculateCommand cc = new CalculateCommand ();
14
14
15
15
@ Test
16
- public void one_person_pay_two_persons () {
16
+ public void onePersonPayTwoPersons () {
17
17
HashMap <String , Transaction > transactions = new HashMap <>();
18
18
transactions .put ("Alice" , new Transaction ("Alice" , 40 ));
19
19
transactions .put ("Bob" , new Transaction ("Bob" , 40 ));
20
20
transactions .put ("Charlie" , new Transaction ("Charlie" , 10 ));
21
21
List <Transaction > transactionList = cc .preprocess (transactions );
22
22
23
- String expected = "Charlie has to pay Alice $10.00\n " +
24
- "Charlie has to pay Bob $10.00\n " +
25
- "\n " +
26
- "Number of transactions: 2" ;
23
+ String expected = "Charlie has to pay Alice $10.00\n "
24
+ + "Charlie has to pay Bob $10.00\n "
25
+ + "\n "
26
+ + "Number of transactions: 2" ;
27
27
String actual = cc .greedy (transactionList );
28
28
assertEquals (expected , actual );
29
29
}
30
30
31
31
@ Test
32
- public void one_person_pay_two_persons_2dp () {
32
+ public void onePersonPayTwoPersons2dp () {
33
33
HashMap <String , Transaction > transactions = new HashMap <>();
34
34
transactions .put ("Alice" , new Transaction ("Alice" , 40.105 ));
35
35
transactions .put ("Bob" , new Transaction ("Bob" , 40.105 ));
36
36
transactions .put ("Charlie" , new Transaction ("Charlie" , 10 ));
37
37
List <Transaction > transactionList = cc .preprocess (transactions );
38
38
39
- String expected = "Charlie has to pay Alice $10.04\n " +
40
- "Charlie has to pay Bob $10.03\n " +
41
- "\n " +
42
- "Number of transactions: 2" ;
39
+ String expected = "Charlie has to pay Alice $10.04\n "
40
+ + "Charlie has to pay Bob $10.03\n "
41
+ + "\n "
42
+ + "Number of transactions: 2" ;
43
43
String actual = cc .greedy (transactionList );
44
44
assertEquals (expected , actual );
45
45
}
46
46
47
47
@ Test
48
- public void four_persons_1 () {
48
+ public void fourPersons1 () {
49
49
HashMap <String , Transaction > transactions = new HashMap <>();
50
50
transactions .put ("Alice" , new Transaction ("Alice" , 10 ));
51
51
transactions .put ("Bob" , new Transaction ("Bob" , 20 ));
52
52
transactions .put ("Charlie" , new Transaction ("Charlie" , 0 ));
53
53
transactions .put ("Don" , new Transaction ("Don" , 10 ));
54
54
List <Transaction > transactionList = cc .preprocess (transactions );
55
55
56
- String expected = "Charlie has to pay Bob $10.00\n " +
57
- "\n " +
58
- "Number of transactions: 1" ;
56
+ String expected = "Charlie has to pay Bob $10.00\n "
57
+ + "\n "
58
+ + "Number of transactions: 1" ;
59
59
String actual = cc .greedy (transactionList );
60
60
assertEquals (expected , actual );
61
61
}
62
62
63
63
@ Test
64
- public void four_persons_2 () {
64
+ public void fourPersons2 () {
65
65
HashMap <String , Transaction > transactions = new HashMap <>();
66
66
transactions .put ("Alice" , new Transaction ("Alice" , 40 ));
67
67
transactions .put ("Bob" , new Transaction ("Bob" , 40 ));
68
68
transactions .put ("Charlie" , new Transaction ("Charlie" , 10 ));
69
69
transactions .put ("Don" , new Transaction ("Don" , 10 ));
70
70
List <Transaction > transactionList = cc .preprocess (transactions );
71
71
72
- String expected = "Don has to pay Alice $15.00\n " +
73
- "Charlie has to pay Bob $15.00\n " +
74
- "\n " +
75
- "Number of transactions: 2" ;
72
+ String expected = "Don has to pay Alice $15.00\n "
73
+ + "Charlie has to pay Bob $15.00\n "
74
+ + "\n "
75
+ + "Number of transactions: 2" ;
76
76
String actual = cc .greedy (transactionList );
77
77
assertEquals (expected , actual );
78
78
}
79
79
80
80
@ Test
81
- public void four_persons_with_one_significantly_more () {
81
+ public void fourPersonsWithOneSignificantlyMmore () {
82
82
HashMap <String , Transaction > transactions = new HashMap <>();
83
83
transactions .put ("Alice" , new Transaction ("Alice" , 200 ));
84
84
transactions .put ("Bob" , new Transaction ("Bob" , 80 ));
85
85
transactions .put ("Charlie" , new Transaction ("Charlie" , 50 ));
86
86
transactions .put ("Don" , new Transaction ("Don" , 20 ));
87
87
List <Transaction > transactionList = cc .preprocess (transactions );
88
88
89
- String expected = "Don has to pay Alice $67.50\n " +
90
- "Charlie has to pay Alice $37.50\n " +
91
- "Bob has to pay Alice $7.50\n " +
92
- "\n " +
93
- "Number of transactions: 3" ;
89
+ String expected = "Don has to pay Alice $67.50\n "
90
+ + "Charlie has to pay Alice $37.50\n "
91
+ + "Bob has to pay Alice $7.50\n "
92
+ + "\n "
93
+ + "Number of transactions: 3" ;
94
94
String actual = cc .greedy (transactionList );
95
95
assertEquals (expected , actual );
96
96
}
97
97
98
98
@ Test
99
- public void four_persons_with_two_significantly_more () {
99
+ public void fourPersonsWithTwoSignificantlyMore () {
100
100
HashMap <String , Transaction > transactions = new HashMap <>();
101
101
transactions .put ("Alice" , new Transaction ("Alice" , 160 ));
102
102
transactions .put ("Bob" , new Transaction ("Bob" , 120 ));
103
103
transactions .put ("Charlie" , new Transaction ("Charlie" , 50 ));
104
104
transactions .put ("Don" , new Transaction ("Don" , 20 ));
105
105
List <Transaction > transactionList = cc .preprocess (transactions );
106
106
107
- String expected = "Don has to pay Alice $67.50\n " +
108
- "Charlie has to pay Bob $32.50\n " +
109
- "Charlie has to pay Alice $5.00\n " +
110
- "\n " +
111
- "Number of transactions: 3" ;
107
+ String expected = "Don has to pay Alice $67.50\n "
108
+ + "Charlie has to pay Bob $32.50\n "
109
+ + "Charlie has to pay Alice $5.00\n "
110
+ + "\n "
111
+ + "Number of transactions: 3" ;
112
112
String actual = cc .greedy (transactionList );
113
113
assertEquals (expected , actual );
114
114
}
115
-
116
-
117
-
118
- }
115
+ }
0 commit comments