-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBoxTest.java
More file actions
139 lines (127 loc) · 3.82 KB
/
BoxTest.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
package packalg;
/**
* PackAlg
* By Arwid Bancewicz, October 19, 2009
*/
// Imports
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import junit.framework.Assert;
import junit.framework.TestCase;
/**
* BoxTest.java - Unit tests for Box (Covers Shape).
*
* @author Arwid Bancewicz
* @version 1.2, (09/19/09)
* @see TestCase
* @see Box
*/
public class BoxTest extends TestCase {
private Shape ioBox1W3L3H;
private Shape ioBox2W3L4H;
private Shape ioBox3W3L3H;
private Shape ioBox3W4L5H;
private List<Shape> ioBoxes;
@Override
protected void setUp() {
ioBox1W3L3H = new Box(1, 3, 3);
ioBox2W3L4H = new Box(2, 3, 4);
ioBox3W4L5H = new Box(3, 4, 5);
ioBox3W3L3H = new Box(3, 3, 3);
ioBoxes = new ArrayList<Shape>();
ioBoxes.add(ioBox1W3L3H);
ioBoxes.add(ioBox2W3L4H);
ioBoxes.add(ioBox3W4L5H);
ioBoxes.add(ioBox3W3L3H);
}
/**
* @see Box#breakUp(Box)
*/
public void testBreakUp() {
List<Shape> loSubShapes = ioBox1W3L3H.breakUp(ioBox3W4L5H);
Assert.assertEquals(3, loSubShapes.size());
Shape loSubShapeX = loSubShapes.get(0);
Shape loSubShapeY = loSubShapes.get(1);
Shape loSubShapeZ = loSubShapes.get(2);
Assert.assertEquals(new Box(2, 4, 5, 1, 0, 0), loSubShapeX);
Assert.assertEquals(new Box(1, 1, 5, 0, 3, 0), loSubShapeY);
Assert.assertEquals(new Box(1, 3, 2, 0, 0, 3), loSubShapeZ);
}
/**
* @see Box#canContain(Box)
*/
public void testCanContain() {
Assert.assertTrue(ioBox2W3L4H.canContain(ioBox1W3L3H));
Assert.assertTrue(ioBox3W4L5H.canContain(ioBox2W3L4H));
Assert.assertFalse(ioBox2W3L4H.canContain(ioBox3W4L5H));
Assert.assertFalse(ioBox2W3L4H.canContain(ioBox3W4L5H));
}
/**
* @see Box#attemptToContain(Box)
*/
public void testAttemptToContain() {
Assert.assertTrue(ioBox3W4L5H.attemptToContain(ioBox3W3L3H));
Assert.assertTrue(ioBox3W3L3H.attemptToContain(ioBox1W3L3H));
Assert.assertFalse(ioBox3W3L3H.attemptToContain(ioBox3W4L5H));
Assert.assertFalse(ioBox2W3L4H.attemptToContain(ioBox3W4L5H));
}
/**
* @see Box#getArea()
*/
public void testGetArea() {
Assert.assertEquals(3, ioBox1W3L3H.getArea());
Assert.assertEquals(6, ioBox2W3L4H.getArea());
Assert.assertEquals(12, ioBox3W4L5H.getArea());
Assert.assertEquals(9, ioBox3W3L3H.getArea());
}
/**
* @see Box#getTotalVolume(List)
*/
public void testGetTotalVolume() {
Assert.assertEquals(120, Shape.getTotalVolume(ioBoxes));
}
/**
* @see Box#getVolume()
*/
public void testGetVolume() {
Assert.assertEquals(9, ioBox1W3L3H.getVolume());
Assert.assertEquals(24, ioBox2W3L4H.getVolume());
Assert.assertEquals(60, ioBox3W4L5H.getVolume());
Assert.assertEquals(27, ioBox3W3L3H.getVolume());
}
/**
* @see Box#rotateXY()
*/
public void testRotateXY() {
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
*/
public void testShapeAreaComparator() {
Collections.sort(ioBoxes, new shapeAreaComparator());
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
*/
public void testShapeVolumeComparator() {
Collections.sort(ioBoxes, new shapeVolumeComparator());
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());
}
}