public void CanPackThreeItemsFitEasilyInLargerOfTwoBoxes() { var packer = new Packer(); var box = new Box() { Description = "Le Petite Box", OuterWidth = 300, OuterLength = 300, OuterDepth = 10, EmptyWeight = 10, InnerWidth = 296, InnerLength = 296, InnerDepth = 8, MaxWeight = 1000 }; var box2 = new Box() { Description = "Le Grande Box", OuterWidth = 3000, OuterLength = 3000, OuterDepth = 100, EmptyWeight = 100, InnerWidth = 2960, InnerLength = 2960, InnerDepth = 80, MaxWeight = 10000 }; var items = new ItemList(); items.Insert(new Item() { Id = "Item 1", Description = "Item 1", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 2", Description = "Item 2", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 3", Description = "Item 3", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); packer.AddBox(box); packer.AddBox(box2); packer.AddItems(items); var packedBoxes = packer.Pack(); Assert.AreEqual(1, packedBoxes.GetCount()); Assert.AreEqual(3, packedBoxes.GetBest().GetItems().GetCount()); Assert.AreEqual(box2, packedBoxes.GetBest().GetBox()); Assert.AreEqual(6100, packedBoxes.GetBest().GetWeight()); }
public void PackThreeItemsOneDoesntFitInAnyBoxThrowsTooLargeException() { var packer = new Packer(); var box = new Box() { Description = "Le Petite Box", OuterWidth = 300, OuterLength = 300, OuterDepth = 10, EmptyWeight = 10, InnerWidth = 296, InnerLength = 296, InnerDepth = 8, MaxWeight = 1000 }; var box2 = new Box() { Description = "Le Grande Box", OuterWidth = 3000, OuterLength = 3000, OuterDepth = 100, EmptyWeight = 100, InnerWidth = 2960, InnerLength = 2960, InnerDepth = 80, MaxWeight = 10000 }; var items = new ItemList(); items.Insert(new Item() { Id = "Item 1", Description = "Item 1", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 2", Description = "Item 2", Width = 25000, Length = 25000, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 3", Description = "Item 3", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); packer.AddBox(box); packer.AddBox(box2); packer.AddItems(items); Assert.Throws <ItemTooLargeException>(() => packer.Pack()); }
public void PackItemsWithoutABoxThrowsException() { var packer = new Packer(); var items = new ItemList(); items.Insert(new Item() { Id = "Item 1", Description = "Item 1", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 2", Description = "Item 2", Width = 25000, Length = 25000, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 3", Description = "Item 3", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); ; packer.AddItems(items); Assert.Throws <ItemTooLargeException>(() => packer.Pack()); }
public void CanAddItems() { var item1 = new Item() { Description = "My Cube 5x5x5", Depth = 5, Length = 5, Weight = 5, Width = 5 }; var item2 = new Item() { Description = "My Cube 10x10x10", Depth = 10, Length = 10, Weight = 10, Width = 10 }; var packer = new Packer(); var newItems = new List <Item>() { item1, item2 }; packer.AddItems(newItems); var items = packer.GetItems(); Assert.AreEqual(2, items.GetCount()); var castItems = items.GetContent().Cast <Item>().ToList(); Assert.AreEqual(2, castItems.Count); }
public void CanPackFiveItemsTwoLargeOneSmallBoxButThreeAfterRepack() { var packer = new Packer(); var box = new Box() { Description = "Le Petite Box", OuterWidth = 600, OuterLength = 600, OuterDepth = 10, EmptyWeight = 10, InnerWidth = 596, InnerLength = 596, InnerDepth = 8, MaxWeight = 1000 }; var box2 = new Box() { Description = "Le Grande Box", OuterWidth = 3000, OuterLength = 3000, OuterDepth = 50, EmptyWeight = 100, InnerWidth = 2960, InnerLength = 2960, InnerDepth = 40, MaxWeight = 10000 }; var items = new ItemList(); items.Insert(new Item() { Id = "Item 1", Description = "Item 1", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 2", Description = "Item 2", Width = 550, Length = 550, Depth = 2, Weight = 200 }); items.Insert(new Item() { Id = "Item 3", Description = "Item 3", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 4", Description = "Item 4", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); items.Insert(new Item() { Id = "Item 5", Description = "Item 5", Width = 2500, Length = 2500, Depth = 20, Weight = 2000 }); packer.AddBox(box); packer.AddBox(box2); packer.AddItems(items); var packedBoxes = packer.Pack(); Assert.AreEqual(3, packedBoxes.GetCount()); Assert.AreEqual(1, packedBoxes.GetBest().GetItems().GetCount()); Assert.AreEqual(box, packedBoxes.GetBest().GetBox()); Assert.AreEqual(210, packedBoxes.GetBest().GetWeight()); packedBoxes.ExtractBest(); Assert.AreEqual(2, packedBoxes.GetBest().GetItems().GetCount()); Assert.AreEqual(box2, packedBoxes.GetBest().GetBox()); Assert.AreEqual(4100, packedBoxes.GetBest().GetWeight()); packedBoxes.ExtractBest(); Assert.AreEqual(2, packedBoxes.GetBest().GetItems().GetCount()); Assert.AreEqual(box2, packedBoxes.GetBest().GetBox()); Assert.AreEqual(4100, packedBoxes.GetBest().GetWeight()); }