1 | using System;
|
---|
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
3 | using System.IO;
|
---|
4 | using HeuristicLab.Problems.BinPacking3D.Instances;
|
---|
5 | using System.Collections.Generic;
|
---|
6 | using HeuristicLab.Problems.BinPacking3D;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Problems.BinPacking._3D.Tests {
|
---|
9 | [TestClass]
|
---|
10 | public class ThreeDInstanceParserTest {
|
---|
11 | private PackingShape _packingShape;
|
---|
12 | private IList<PackingItem> _items1;
|
---|
13 | private IList<PackingItem> _items2;
|
---|
14 |
|
---|
15 | [TestInitialize]
|
---|
16 | public void Initializes() {
|
---|
17 | _packingShape = new PackingShape(22, 23, 21);
|
---|
18 | _items1 = new List<PackingItem>();
|
---|
19 |
|
---|
20 | _items1.Add(new PackingItem(8, 10, 10, _packingShape, 800, 1)); // 0, V = 800, A = 80, h = 10
|
---|
21 | _items1.Add(new PackingItem(10, 8, 10, _packingShape, 800, 2)); // 1, V = 800, A = 100, h = 8
|
---|
22 | _items1.Add(new PackingItem(10, 10, 8, _packingShape, 800, 3)); // 2, V = 800, A = 80, h = 10
|
---|
23 | _items1.Add(new PackingItem(8, 8, 10, _packingShape, 640, 4)); // 3, V = 640, A = 80, h = 8
|
---|
24 | _items1.Add(new PackingItem(10, 8, 8, _packingShape, 640, 0)); // 4, V = 640, A = 80, h = 8
|
---|
25 | _items1.Add(new PackingItem(8, 10, 8, _packingShape, 640, 1)); // 5, V = 640, A = 64, h = 10
|
---|
26 | _items1.Add(new PackingItem(8, 8, 8, _packingShape, 512, 2)); // 6, V = 512, A = 64, h = 8
|
---|
27 |
|
---|
28 | _items1.Add(new PackingItem(10, 10, 10, _packingShape,1000,3)); // 7, V = 1000, A = 100, h = 10
|
---|
29 |
|
---|
30 | _items1.Add(new PackingItem(9, 10, 10, _packingShape, 900, 4)); // 8, V = 900, A = 90, h = 10
|
---|
31 | _items1.Add(new PackingItem(10, 9, 10, _packingShape, 900, 0)); // 9, V = 900, A = 100, h = 9
|
---|
32 | _items1.Add(new PackingItem(10, 10, 9, _packingShape, 900, 1)); // 10, V = 900, A = 90, h = 10
|
---|
33 | _items1.Add(new PackingItem(9, 9, 10, _packingShape, 810, 2)); // 11, V = 810, A = 90, h = 9
|
---|
34 | _items1.Add(new PackingItem(10, 9, 9, _packingShape, 810, 3)); // 12, V = 810, A = 90, h = 9
|
---|
35 | _items1.Add(new PackingItem(9, 10, 9, _packingShape, 810, 4)); // 13, V = 810, A = 81, h = 10
|
---|
36 | _items1.Add(new PackingItem(9, 9, 9, _packingShape, 729, 0)); // 14, V = 729, A = 81, h = 9
|
---|
37 |
|
---|
38 | _items2 = new List<PackingItem>();
|
---|
39 | _items2.Add(new PackingItem(8, 10, 10, _packingShape, 800, 1)); // 0, V = 800, A = 80, h = 10
|
---|
40 | _items2.Add(new PackingItem(10, 8, 10, _packingShape, 800, 2)); // 1, V = 800, A = 100, h = 8
|
---|
41 | _items2.Add(new PackingItem(10, 10, 8, _packingShape, 800, 3)); // 2, V = 800, A = 80, h = 10
|
---|
42 | _items2.Add(new PackingItem(8, 8, 10, _packingShape, 640, 4)); // 3, V = 640, A = 80, h = 8
|
---|
43 | _items2.Add(new PackingItem(10, 8, 8, _packingShape, 640, 0)); // 4, V = 640, A = 80, h = 8
|
---|
44 | _items2.Add(new PackingItem(8, 10, 8, _packingShape, 640, 1)); // 5, V = 640, A = 64, h = 10
|
---|
45 | }
|
---|
46 |
|
---|
47 | [TestMethod]
|
---|
48 | [TestCategory("Problems.BinPacking.3D")]
|
---|
49 | public void TestParse() {
|
---|
50 | string path = @".\..\HeuristicLab.Tests\HeuristicLab.Problems.Bin-Packing-3.3\TestInstances\Parser\3D-UnitTestParser1.txt";
|
---|
51 | ThreeDInstanceParser parser = new ThreeDInstanceParser();
|
---|
52 |
|
---|
53 | using (var fileStream = File.Open(path, FileMode.Open)) {
|
---|
54 | parser.Parse(fileStream);
|
---|
55 | }
|
---|
56 |
|
---|
57 | Assert.AreEqual(_packingShape.Width, parser.Bin.Width);
|
---|
58 | Assert.AreEqual(_packingShape.Height, parser.Bin.Height);
|
---|
59 | Assert.AreEqual(_packingShape.Depth, parser.Bin.Depth);
|
---|
60 |
|
---|
61 | Assert.AreEqual(_items1.Count, parser.Items.Count);
|
---|
62 | for (int i = 0; i < parser.Items.Count; i++) {
|
---|
63 | PackingItem expected = _items1[i];
|
---|
64 | PackingItem actual = parser.Items[i];
|
---|
65 | Assert.AreEqual(expected.Width, actual.Width);
|
---|
66 | Assert.AreEqual(expected.Height, actual.Height);
|
---|
67 | Assert.AreEqual(expected.Depth, actual.Depth);
|
---|
68 | Assert.AreEqual(expected.Material, actual.Material);
|
---|
69 | Assert.AreEqual(expected.Weight, actual.Weight);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | [TestMethod]
|
---|
74 | [TestCategory("Problems.BinPacking.3D")]
|
---|
75 | public void TestParseUncompleteFile() {
|
---|
76 | string path = @".\..\HeuristicLab.Tests\HeuristicLab.Problems.Bin-Packing-3.3\TestInstances\Parser\3D-UnitTestParser2.txt";
|
---|
77 | ThreeDInstanceParser parser = new ThreeDInstanceParser();
|
---|
78 |
|
---|
79 | using (var fileStream = File.Open(path, FileMode.Open)) {
|
---|
80 | parser.Parse(fileStream);
|
---|
81 | }
|
---|
82 |
|
---|
83 | Assert.AreEqual(_packingShape.Width, parser.Bin.Width);
|
---|
84 | Assert.AreEqual(_packingShape.Height, parser.Bin.Height);
|
---|
85 | Assert.AreEqual(_packingShape.Depth, parser.Bin.Depth);
|
---|
86 |
|
---|
87 | Assert.AreEqual(_items2.Count, parser.Items.Count);
|
---|
88 | for (int i = 0; i < parser.Items.Count; i++) {
|
---|
89 | PackingItem expected = _items2[i];
|
---|
90 | PackingItem actual = parser.Items[i];
|
---|
91 | Assert.AreEqual(expected.Width, actual.Width);
|
---|
92 | Assert.AreEqual(expected.Height, actual.Height);
|
---|
93 | Assert.AreEqual(expected.Depth, actual.Depth);
|
---|
94 | Assert.AreEqual(expected.Material, actual.Material);
|
---|
95 | Assert.AreEqual(expected.Weight, actual.Weight);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|