source: branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/ExtremePointCreation/TestLineProjectionBasedEPCreator.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: 6.5 KB
Line 
1using System;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using HeuristicLab.Problems.BinPacking3D.ExtremePointCreation;
4
5namespace HeuristicLab.Problems.BinPacking._3D.ExtremePointCreation.Tests {
6
7  [TestClass]
8  public class TestLineProjectionBasedEPCreator {
9
10    BinPacking3D.BinPacking3D _binPacking1;
11    BinPacking3D.BinPacking3D _binPacking2;
12    BinPacking3D.BinPacking3D _binPacking3;
13    BinPacking3D.BinPacking3D _binPacking4;
14
15    BinPacking3D.PackingItem _item1;
16    BinPacking3D.PackingItem _item2;
17    BinPacking3D.PackingItem _item3;
18    BinPacking3D.PackingItem _item4;
19
20    BinPacking3D.PackingPosition _pos1;
21    BinPacking3D.PackingPosition _pos2;
22    BinPacking3D.PackingPosition _pos3;
23    BinPacking3D.PackingPosition _pos4;
24
25    IExtremePointCreator _creator;
26
27    [TestInitialize]
28    public void Initialize() {
29      _creator = ExtremePointCreatorFactory.CreateExtremePointCreator(BinPacking3D.ExtremePointCreationMethod.LineProjection, false);
30      var packingShape = new BinPacking3D.PackingShape(20, 20, 20);
31      _item1 = new BinPacking3D.PackingItem(8, 4, 8, packingShape);
32      _item2 = new BinPacking3D.PackingItem(4, 10, 4, packingShape);
33      _item3 = new BinPacking3D.PackingItem(8, 8, 8, packingShape);
34      _item4 = new BinPacking3D.PackingItem(2, 2, 20, packingShape);
35
36      _pos1 = new BinPacking3D.PackingPosition(0, 0, 0, 0);
37      _pos2 = new BinPacking3D.PackingPosition(0, 8, 0, 0);
38      _pos3 = new BinPacking3D.PackingPosition(0, 12, 0, 0);
39      _pos4 = new BinPacking3D.PackingPosition(0, 0, 4, 0);
40
41      _binPacking1 = new BinPacking3D.BinPacking3D(packingShape);
42
43      _binPacking1.PackItem(0, _item1, _pos1);
44
45      _binPacking2 = _binPacking1.Clone() as BinPacking3D.BinPacking3D;
46      _binPacking2.PackItem(1, _item2, _pos2);
47
48      _binPacking3 = _binPacking2.Clone() as BinPacking3D.BinPacking3D;
49      _binPacking3.PackItem(2, _item3, _pos3);
50
51      _binPacking4 = _binPacking3.Clone() as BinPacking3D.BinPacking3D;
52      _binPacking4.PackItem(3, _item4, _pos4);
53
54      Assert.AreEqual(1, _binPacking1.Items.Count);
55      Assert.AreEqual(2, _binPacking2.Items.Count);
56      Assert.AreEqual(3, _binPacking3.Items.Count);
57      Assert.AreEqual(4, _binPacking4.Items.Count);
58    }
59
60    [TestMethod]
61    [TestCategory("Problems.BinPacking.3D")]
62    [TestProperty("Time", "short")]
63    public void TestUpdateExtremePoints1() {
64
65      _creator.UpdateBinPacking(_binPacking1, _item1, _pos1);
66      Assert.AreEqual(3, _binPacking1.ExtremePoints.Count);
67      Assert.IsTrue(_binPacking1.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 0, 0)));
68      Assert.IsTrue(_binPacking1.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 4, 0)));
69      Assert.IsTrue(_binPacking1.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 0, 8)));
70    }
71
72    [TestMethod]
73    [TestCategory("Problems.BinPacking.3D")]
74    [TestProperty("Time", "short")]
75    public void TestUpdateExtremePoints2() {
76      _creator.UpdateBinPacking(_binPacking2, _item2, _pos2);
77      Assert.AreEqual(7, _binPacking2.ExtremePoints.Count);
78      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 12, 0, 0)));
79      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 0, 4)));
80      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 0, 8)));
81      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 4, 0)));
82      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 4, 4)));
83      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 10, 0)));
84      Assert.IsTrue(_binPacking2.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 10, 0)));
85    }
86
87    [TestMethod]
88    [TestCategory("Problems.BinPacking.3D")]
89    [TestProperty("Time", "short")]
90    public void TestUpdateExtremePoints3() {
91      _creator.UpdateBinPacking(_binPacking3, _item3, _pos3);
92      Assert.AreEqual(8, _binPacking3.ExtremePoints.Count);
93      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 0, 4)));
94      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 0, 8)));
95      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 4, 0)));
96      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 4, 4)));
97      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 12, 8, 0)));
98
99      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 8, 4)));
100      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 10, 0)));
101      Assert.IsTrue(_binPacking3.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 10, 0)));
102    }
103
104    [TestMethod]
105    [TestCategory("Problems.BinPacking.3D")]
106    [TestProperty("Time", "short")]
107    public void TestUpdateExtremePoints4() {
108      _creator.UpdateBinPacking(_binPacking4, _item4, _pos4);
109      Assert.AreEqual(12, _binPacking4.ExtremePoints.Count);
110      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 0, 4)));
111      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 0, 8)));
112      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 2, 0, 8)));
113      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 2, 4, 0)));
114
115      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 2, 4, 4)));
116      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 6, 0)));
117      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 6, 4)));
118      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 6, 8)));
119
120      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 12, 8, 0)));
121      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 8, 4)));
122      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 0, 10, 0)));
123      Assert.IsTrue(_binPacking4.ExtremePoints.ContainsKey(new BinPacking3D.PackingPosition(0, 8, 10, 0)));
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.