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