-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMemberClass.java
More file actions
83 lines (68 loc) · 2.05 KB
/
TestMemberClass.java
File metadata and controls
83 lines (68 loc) · 2.05 KB
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
package carpoolTestCode;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import code.Cost2;
import code.Member;
class TestMemberClass {
private Member member;
@BeforeEach
void setUp() throws Exception {
member = new Member();
}
@Test
void TestWouldNotTakeLessThan0Children() {
assertThrows(IllegalArgumentException.class, () -> member.addChildToNumChildren(-2));
}
@Test
void TestCostTotalCountsCorrectNoDeletions() {
member.addCost(new Cost2("Toll",2.01));
member.addCost(new Cost2("Toll",3.01));
member.addCost(new Cost2("Toll",4.01));
assertEquals(9.03, member.getCostTotal());
}
@Test
void TestCostTotalIs0AfterReseting() {
member.addCost(new Cost2("Toll",2.01));
member.addCost(new Cost2("Toll",3.01));
member.addCost(new Cost2("Toll",4.01));
member.resetCost();
assertEquals(0, member.getCostTotal());
}
@Test
void TestGetsCorrectCostByID() {
member.addCost(new Cost2("Toll",2.01));
member.addCost(new Cost2("Toll",4.01));
Cost2 cost3 = new Cost2("Toll",3.01);
member.addCost(cost3);
assertSame(cost3, member.getCostByID(3));
}
@Test
void TestMethodReturnsNullIfThereIsNoSuchCostByID() {
member.addCost(new Cost2("Toll",2.01));
member.addCost(new Cost2("Toll",4.01));
Cost2 cost2 = new Cost2("Toll",3.01);
member.addCost(cost2);
assertSame(null, member.getCostByID(7));
}
@Test
void TestNumOfChildrenWhenAdding() {
member.addChildToNumChildren(4);
assertEquals(4, member.getNumChildren());
}
@Test
void TestNumOfChildrenWhenRemoving() {
member.addChildToNumChildren(5);
member.removeChildrenFromNumChildren(3);;
assertEquals(2, member.getNumChildren());
}
@Test
void TestCannotRemoveMoreChildrenThanAlreadyHave() {
member.addChildToNumChildren(3);
assertThrows(IllegalArgumentException.class, () -> member.removeChildrenFromNumChildren(5));
}
}