source: branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/Geometry/Vector3DTest.cs @ 15554

Last change on this file since 15554 was 15554, checked in by rhanghof, 2 years ago

#2817:

  • Unittests
  • Bugfixes on the line projection based extreme point creation method
File size: 10.0 KB
Line 
1using System;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using HeuristicLab.Problems.BinPacking3D.Geometry;
4using HeuristicLab.Problems.BinPacking3D;
5
6namespace HeuristicLab.Problems.BinPacking._3D.Geometry.Test {
7  [TestClass]
8  public class Vector3DTest {
9
10    Vector3D _point1;
11    Vector3D _point2;
12    Vector3D _point3;
13    Vector3D _point4;
14    Vector3D _point5;
15    Vector3D _point6;
16
17    PackingItem _item1;
18    PackingItem _item2;
19    PackingItem _item3;
20
21    [TestInitialize]
22    public void Initialize() {
23      _point1 = new Vector3D(3, 0, 0);
24      _point2 = new Vector3D(0, 3, 0);
25      _point3 = new Vector3D(0, 0, 3);
26
27      _point4 = new Vector3D(5, 5, 5);
28      _point5 = new Vector3D(2, 2, 2);
29      _point6 = new Vector3D(0, 0, 0);
30
31      _item1 = new PackingItem(10, 10, 10, new PackingShape());
32      _item2 = new PackingItem(20, 20, 20, new PackingShape());
33      _item3 = new PackingItem(30, 30, 30, new PackingShape());
34    }
35
36    [TestMethod]
37    [TestCategory("Problems.BinPacking.3D")]
38    [TestProperty("Time", "short")]
39    public void TestAlongX() {
40      Assert.AreEqual(new Vector3D(13, 0, 0) ,Vector3D.AlongX(_point1.ToPackingPosition(0), _item1));
41      Assert.AreEqual(new Vector3D(23, 0, 0), Vector3D.AlongX(_point1.ToPackingPosition(0), _item2));
42      Assert.AreEqual(new Vector3D(33, 0, 0), Vector3D.AlongX(_point1.ToPackingPosition(0), _item3));
43
44
45      Assert.AreEqual(new Vector3D(10, 3, 0), Vector3D.AlongX(_point2.ToPackingPosition(0), _item1));
46      Assert.AreEqual(new Vector3D(20, 3, 0), Vector3D.AlongX(_point2.ToPackingPosition(0), _item2));
47      Assert.AreEqual(new Vector3D(30, 3, 0), Vector3D.AlongX(_point2.ToPackingPosition(0), _item3));
48
49      Assert.AreEqual(new Vector3D(10, 0, 3), Vector3D.AlongX(_point3.ToPackingPosition(0), _item1));
50      Assert.AreEqual(new Vector3D(20, 0, 3), Vector3D.AlongX(_point3.ToPackingPosition(0), _item2));
51      Assert.AreEqual(new Vector3D(30, 0, 3), Vector3D.AlongX(_point3.ToPackingPosition(0), _item3));
52    }
53
54    [TestMethod]
55    [TestCategory("Problems.BinPacking.3D")]
56    [TestProperty("Time", "short")]
57    public void TestAlongY() {
58      Assert.AreEqual(new Vector3D(3, 10, 0), Vector3D.AlongY(_point1.ToPackingPosition(0), _item1));
59      Assert.AreEqual(new Vector3D(3, 20, 0), Vector3D.AlongY(_point1.ToPackingPosition(0), _item2));
60      Assert.AreEqual(new Vector3D(3, 30, 0), Vector3D.AlongY(_point1.ToPackingPosition(0), _item3));
61
62
63      Assert.AreEqual(new Vector3D(0, 13, 0), Vector3D.AlongY(_point2.ToPackingPosition(0), _item1));
64      Assert.AreEqual(new Vector3D(0, 23, 0), Vector3D.AlongY(_point2.ToPackingPosition(0), _item2));
65      Assert.AreEqual(new Vector3D(0, 33, 0), Vector3D.AlongY(_point2.ToPackingPosition(0), _item3));
66
67      Assert.AreEqual(new Vector3D(0, 10, 3), Vector3D.AlongY(_point3.ToPackingPosition(0), _item1));
68      Assert.AreEqual(new Vector3D(0, 20, 3), Vector3D.AlongY(_point3.ToPackingPosition(0), _item2));
69      Assert.AreEqual(new Vector3D(0, 30, 3), Vector3D.AlongY(_point3.ToPackingPosition(0), _item3));
70    }
71
72    [TestMethod]
73    [TestCategory("Problems.BinPacking.3D")]
74    [TestProperty("Time", "short")]
75    public void TestAlongZ() {
76      Assert.AreEqual(new Vector3D(3, 0, 10), Vector3D.AlongZ(_point1.ToPackingPosition(0), _item1));
77      Assert.AreEqual(new Vector3D(3, 0, 20), Vector3D.AlongZ(_point1.ToPackingPosition(0), _item2));
78      Assert.AreEqual(new Vector3D(3, 0, 30), Vector3D.AlongZ(_point1.ToPackingPosition(0), _item3));
79
80
81      Assert.AreEqual(new Vector3D(0, 3, 10), Vector3D.AlongZ(_point2.ToPackingPosition(0), _item1));
82      Assert.AreEqual(new Vector3D(0, 3, 20), Vector3D.AlongZ(_point2.ToPackingPosition(0), _item2));
83      Assert.AreEqual(new Vector3D(0, 3, 30), Vector3D.AlongZ(_point2.ToPackingPosition(0), _item3));
84
85      Assert.AreEqual(new Vector3D(0, 0, 13), Vector3D.AlongZ(_point3.ToPackingPosition(0), _item1));
86      Assert.AreEqual(new Vector3D(0, 0, 23), Vector3D.AlongZ(_point3.ToPackingPosition(0), _item2));
87      Assert.AreEqual(new Vector3D(0, 0, 33), Vector3D.AlongZ(_point3.ToPackingPosition(0), _item3));
88    }
89
90    [TestMethod]
91    [TestCategory("Problems.BinPacking.3D")]
92    [TestProperty("Time", "short")]
93    public void TestCross() {
94      Assert.AreEqual(new Vector3D(0, 0, 9), _point1.Cross(_point2));
95      Assert.AreEqual(new Vector3D(0, 0, -9), _point2.Cross(_point1));
96      Assert.AreEqual(new Vector3D(9, 0, 0), _point2.Cross(_point3));
97      Assert.AreEqual(new Vector3D(-9, 0, 0), _point3.Cross(_point2));
98      Assert.AreEqual(new Vector3D(0, -9, 0), _point1.Cross(_point3));
99      Assert.AreEqual(new Vector3D(0, 9, 0), _point3.Cross(_point1));
100
101
102      Assert.AreEqual(new Vector3D(0, -15, 15), _point1.Cross(_point4));
103      Assert.AreEqual(new Vector3D(15, 0, -15), _point2.Cross(_point4));
104      Assert.AreEqual(new Vector3D(-15, 15, 0), _point3.Cross(_point4));
105
106      Assert.AreEqual(new Vector3D(0, 15, -15), _point4.Cross(_point1));
107      Assert.AreEqual(new Vector3D(-15, 0, 15), _point4.Cross(_point2));
108      Assert.AreEqual(new Vector3D(15, -15, 0), _point4.Cross(_point3));
109    }
110
111    [TestMethod]
112    [TestCategory("Problems.BinPacking.3D")]
113    [TestProperty("Time", "short")]
114    public void TestIsInside() {
115      Assert.IsFalse(_point1.IsInside(_point4.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
116      Assert.IsFalse(_point2.IsInside(_point4.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
117      Assert.IsFalse(_point3.IsInside(_point4.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
118
119      Assert.IsTrue(_point1.IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
120      Assert.IsTrue(_point2.IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
121      Assert.IsTrue(_point3.IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
122      Assert.IsTrue(_point6.IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
123
124      Assert.IsTrue(_point4.IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
125      Assert.IsTrue(_point5.IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
126      Assert.IsTrue((new Vector3D(9, 9, 9)).IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
127      Assert.IsFalse((new Vector3D(11, 9, 9)).IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
128      Assert.IsFalse((new Vector3D(9, 11, 9)).IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
129      Assert.IsFalse((new Vector3D(9, 9, 11)).IsInside(_point6.ToPackingPosition(0), ResidualSpace.Create(10, 10, 10)));
130    }
131
132    [TestMethod]
133    [TestCategory("Problems.BinPacking.3D")]
134    [TestProperty("Time", "short")]
135    public void TestOperators() {
136      // static int operator *(Vector3D a, Vector3D b)
137      Assert.AreEqual(0, (_point1 * _point2));
138      Assert.AreEqual(0, (_point2 * _point1));
139      Assert.AreEqual(0, (_point4 * _point6));
140      Assert.AreEqual(0, (_point6 * _point4));
141      Assert.AreEqual(15, (_point1 * _point4));
142      Assert.AreEqual(15, (_point4 * _point1));
143      Assert.AreEqual(30, (_point5 * _point4));
144      Assert.AreEqual(30, (_point4 * _point5));
145
146      // static Vector3D operator *(int a, Vector3D b), static Vector3D operator *(Vector3D a, int b)
147      Assert.AreEqual(new Vector3D(3, 0, 0), 1 * _point1);
148      Assert.AreEqual(new Vector3D(6, 0, 0), 2 * _point1);
149      Assert.AreEqual(new Vector3D(3, 0, 0), _point1 * 1);
150      Assert.AreEqual(new Vector3D(6, 0, 0), _point1 * 2);
151      Assert.AreEqual(2 * _point1, _point1 * 2);
152
153      Assert.AreEqual(new Vector3D(9, 0, 0), _point1 * 3);
154      Assert.AreEqual(new Vector3D(0, 9, 0), _point2 * 3);
155      Assert.AreEqual(new Vector3D(0, 0, 9), _point3 * 3);
156
157      Assert.AreEqual(new Vector3D(20, 20, 20), 4 * _point4);
158      Assert.AreEqual(new Vector3D(20, 20, 20), _point4 * 4);     
159      Assert.AreEqual(4 * _point4, _point4 * 4);
160
161      // static Vector3D operator *(double a, Vector3D b), static Vector3D operator *(Vector3D a, double b)
162      Assert.AreEqual(new Vector3D(3, 0, 0), 1.1 * _point1);
163      Assert.AreEqual(new Vector3D(6, 0, 0), 2.2 * _point1);
164      Assert.AreEqual(new Vector3D(3, 0, 0), _point1 * 1.1);
165      Assert.AreEqual(new Vector3D(6, 0, 0), _point1 * 2.2);
166      Assert.AreEqual(2.2 * _point1, _point1 * 2.2);
167     
168      Assert.AreEqual(new Vector3D(9, 0, 0), _point1 * 3.3);
169      Assert.AreEqual(new Vector3D(0, 9, 0), _point2 * 3.3);
170      Assert.AreEqual(new Vector3D(0, 0, 9), _point3 * 3.3);
171
172      Assert.AreEqual(new Vector3D(22, 22, 22), 4.4 * _point4);
173      Assert.AreEqual(new Vector3D(22, 22, 22), _point4 * 4.4);
174      Assert.AreEqual(4.4 * _point4, _point4 * 4.4);
175
176      // static Vector3D operator +(Vector3D a, Vector3D b)
177      Assert.AreEqual(new Vector3D(8, 5, 5), _point1 + _point4);
178      Assert.AreEqual(new Vector3D(5, 8, 5), _point2 + _point4);
179      Assert.AreEqual(new Vector3D(5, 5, 8), _point3 + _point4);
180      Assert.AreEqual(new Vector3D(7, 7, 7), _point4 + _point5);
181      Assert.AreEqual(_point4, _point4 + _point6);
182
183      // static Vector3D operator -(Vector3D a, Vector3D b)
184      Assert.AreEqual(new Vector3D(-2, -5, -5), _point1 - _point4);
185      Assert.AreEqual(new Vector3D(-5, -2, -5), _point2 - _point4);
186      Assert.AreEqual(new Vector3D(-5, -5, -2), _point3 - _point4);
187      Assert.AreEqual(new Vector3D(3, 3, 3), _point4 - _point5);
188      Assert.AreEqual(_point4, _point4 - _point6);
189
190    }
191
192    [TestMethod]
193    [TestCategory("Problems.BinPacking.3D")]
194    [TestProperty("Time", "short")]
195    public void TestEquals() {
196      Assert.IsFalse(_point1.Equals(_point2));
197      Assert.IsFalse(_point1.Equals(new Vector3D(3, 0, 1)));
198      Assert.IsFalse(_point1.Equals(new Vector3D(3, 1, 0)));
199      Assert.IsFalse(_point1.Equals(new Vector3D(2, 0, 0)));
200
201      Assert.IsTrue(_point1.Equals(_point1));
202      Assert.IsTrue(_point5.Equals(new Vector3D(2, 2, 2)));
203    }
204   
205  }
206}
Note: See TracBrowser for help on using the repository browser.