- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPackingAlgorithmTest.java
More file actions
Latest commit
84 lines (77 loc) · 2.28 KB
/
Copy pathPackingAlgorithmTest.java
File metadata and controls
84 lines (77 loc) · 2.28 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
packagepackalg;
/**
* PackAlg
* By Arwid Bancewicz, October 19, 2009
*/
// Imports
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Random;
importjunit.framework.Assert;
importjunit.framework.TestCase;
/**
* PackingAlgorithmTest.java - Unit tests for classes PackingAlgorithm.
*
* @author Arwid Bancewicz
* @version 1.2, (09/19/09)
* @see TestCase
* @see PackingAlgorithm
* @see Box
*/
publicclassPackingAlgorithmTestextendsTestCase {
privatePackingAlgorithmioAlg;
privateShapeioContainer;
privateRandomioGenerator;
@Override
protectedvoidsetUp() {
ioAlg = newPackingAlgorithm();
ioContainer = newBox(3, 4, 5);
ioGenerator = newRandom();
}
/**
* Basic pack test.
* @see PackingAlgorithm#pack(Shape, List)
*/
publicvoidtestPack() {
List<Shape> loShapes = newArrayList<Shape>();
loShapes.add(newBox(1, 3, 1));
loShapes.add(newBox(3, 1, 1));
loShapes.add(newBox(2, 2, 4));
loShapes.add(newBox(3, 2, 5));
loShapes.add(newBox(1, 1, 1));
Assert.assertTrue(ioAlg.pack(ioContainer, loShapes) > 0);
Assert.assertEquals(0, loShapes.size()); // 0 left unpacked
}
/**
* Fully pack 1 container test.
* @see PackingAlgorithm#pack(Shape, List)
*/
publicvoidtestPackFull() {
List<Shape> loShapes = newArrayList<Shape>();
loShapes.add(newBox(3, 4, 2));
loShapes.add(newBox(3, 2, 3));
loShapes.add(newBox(3, 2, 3));
Assert.assertTrue(ioAlg.pack(ioContainer, loShapes) == 1);
Assert.assertEquals(0, loShapes.size()); // 0 left unpacked
}
/**
* Advanced algorithm test (Randomly generated boxes)
*/
publicvoidtestPackAdvanced() {
intliContainerWidth = 10;
intliContainerLength = 10;
intliContainerHeight = 10;
BoxloContainer = newBox(liContainerWidth, liContainerLength, liContainerHeight);
List<Shape> loShapes = newArrayList<Shape>();
intliNumBoxes = 20000;
while (--liNumBoxes >= 0) {
loShapes.add(newBox(
1 + (int) (Math.round(ioGenerator.nextDouble() * (liContainerWidth - 1))),
1 + (int) (Math.round(ioGenerator.nextDouble() * (liContainerLength - 1))),
1 + (int) (Math.round(ioGenerator.nextDouble() * (liContainerHeight - 1)))
));
}
Assert.assertTrue(ioAlg.pack(loContainer, loShapes) > 0);
Assert.assertEquals(0, loShapes.size()); // 0 left unpacked
}
}