- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBoxTest.java
More file actions
Latest commit
139 lines (127 loc) · 3.82 KB
/
Copy pathBoxTest.java
File metadata and controls
139 lines (127 loc) · 3.82 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
packagepackalg;
/**
* PackAlg
* By Arwid Bancewicz, October 19, 2009
*/
// Imports
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.List;
importjunit.framework.Assert;
importjunit.framework.TestCase;
/**
* BoxTest.java - Unit tests for Box (Covers Shape).
*
* @author Arwid Bancewicz
* @version 1.2, (09/19/09)
* @see TestCase
* @see Box
*/
publicclassBoxTestextendsTestCase {
privateShapeioBox1W3L3H;
privateShapeioBox2W3L4H;
privateShapeioBox3W3L3H;
privateShapeioBox3W4L5H;
privateList<Shape> ioBoxes;
@Override
protectedvoidsetUp() {
ioBox1W3L3H = newBox(1, 3, 3);
ioBox2W3L4H = newBox(2, 3, 4);
ioBox3W4L5H = newBox(3, 4, 5);
ioBox3W3L3H = newBox(3, 3, 3);
ioBoxes = newArrayList<Shape>();
ioBoxes.add(ioBox1W3L3H);
ioBoxes.add(ioBox2W3L4H);
ioBoxes.add(ioBox3W4L5H);
ioBoxes.add(ioBox3W3L3H);
}
/**
* @see Box#breakUp(Box)
*/
publicvoidtestBreakUp() {
List<Shape> loSubShapes = ioBox1W3L3H.breakUp(ioBox3W4L5H);
Assert.assertEquals(3, loSubShapes.size());
ShapeloSubShapeX = loSubShapes.get(0);
ShapeloSubShapeY = loSubShapes.get(1);
ShapeloSubShapeZ = loSubShapes.get(2);
Assert.assertEquals(newBox(2, 4, 5, 1, 0, 0), loSubShapeX);
Assert.assertEquals(newBox(1, 1, 5, 0, 3, 0), loSubShapeY);
Assert.assertEquals(newBox(1, 3, 2, 0, 0, 3), loSubShapeZ);
}
/**
* @see Box#canContain(Box)
*/
publicvoidtestCanContain() {
Assert.assertTrue(ioBox2W3L4H.canContain(ioBox1W3L3H));
Assert.assertTrue(ioBox3W4L5H.canContain(ioBox2W3L4H));
Assert.assertFalse(ioBox2W3L4H.canContain(ioBox3W4L5H));
Assert.assertFalse(ioBox2W3L4H.canContain(ioBox3W4L5H));
}
/**
* @see Box#attemptToContain(Box)
*/
publicvoidtestAttemptToContain() {
Assert.assertTrue(ioBox3W4L5H.attemptToContain(ioBox3W3L3H));
Assert.assertTrue(ioBox3W3L3H.attemptToContain(ioBox1W3L3H));
Assert.assertFalse(ioBox3W3L3H.attemptToContain(ioBox3W4L5H));
Assert.assertFalse(ioBox2W3L4H.attemptToContain(ioBox3W4L5H));
}
/**
* @see Box#getArea()
*/
publicvoidtestGetArea() {
Assert.assertEquals(3, ioBox1W3L3H.getArea());
Assert.assertEquals(6, ioBox2W3L4H.getArea());
Assert.assertEquals(12, ioBox3W4L5H.getArea());
Assert.assertEquals(9, ioBox3W3L3H.getArea());
}
/**
* @see Box#getTotalVolume(List)
*/
publicvoidtestGetTotalVolume() {
Assert.assertEquals(120, Shape.getTotalVolume(ioBoxes));
}
/**
* @see Box#getVolume()
*/
publicvoidtestGetVolume() {
Assert.assertEquals(9, ioBox1W3L3H.getVolume());
Assert.assertEquals(24, ioBox2W3L4H.getVolume());
Assert.assertEquals(60, ioBox3W4L5H.getVolume());
Assert.assertEquals(27, ioBox3W3L3H.getVolume());
}
/**
* @see Box#rotateXY()
*/
publicvoidtestRotateXY() {
ioBox3W4L5H.rotateXY();
Assert.assertEquals(4, ((Box) ioBox3W4L5H).iiWidth);
Assert.assertEquals(3, ((Box) ioBox3W4L5H).iiLength);
Assert.assertEquals(5, ((Box) ioBox3W4L5H).iiHeight);
ioBox3W4L5H.rotateXY();
Assert.assertEquals(3, ((Box) ioBox3W4L5H).iiWidth);
Assert.assertEquals(4, ((Box) ioBox3W4L5H).iiLength);
Assert.assertEquals(5, ((Box) ioBox3W4L5H).iiHeight);
}
// Comparators
/**
* @see shapeAreaComparator
*/
publicvoidtestShapeAreaComparator() {
Collections.sort(ioBoxes, newshapeAreaComparator());
Assert.assertEquals(3, ioBoxes.get(0).getArea());
Assert.assertEquals(6, ioBoxes.get(1).getArea());
Assert.assertEquals(9, ioBoxes.get(2).getArea());
Assert.assertEquals(12, ioBoxes.get(3).getArea());
}
/**
* @see shapeAreaComparator
*/
publicvoidtestShapeVolumeComparator() {
Collections.sort(ioBoxes, newshapeVolumeComparator());
Assert.assertEquals(9, ioBoxes.get(0).getVolume());
Assert.assertEquals(24, ioBoxes.get(1).getVolume());
Assert.assertEquals(27, ioBoxes.get(2).getVolume());
Assert.assertEquals(60, ioBoxes.get(3).getVolume());
}
}