Exemplo n.º 1
0
        private void BtnSort_Click(object sender, EventArgs e)
        {
            lbSortedContainers.Items.Clear();
            var ship = ShipLogic.SortContainers(Containers);

            for (int l = 0; l < ShipLogic.Ship.Length; l++)
            {
                for (int w = 0; w < ShipLogic.Ship.Width; w++)
                {
                    lbSortedContainers.Items.Add(l.ToString() + "." + w.ToString());
                    foreach (var container in ship.Stack[w, l].Containers)
                    {
                        lbSortedContainers.Items.Add(container);
                    }
                }
            }

            lbUnsortedContainers.Items.Clear();
            foreach (Container container in ShipLogic.UnSortedContainers)
            {
                lbUnsortedContainers.Items.Add(container);
            }

            lblCountUnsorted.Text = lbUnsortedContainers.Items.Count.ToString();
        }
Exemplo n.º 2
0
        public void IntegrationTest()
        {
            //Arrange
            Ship expected = new Ship(1, 3);

            Container container1 = new Container(4000, false, true);
            Container container2 = new Container(4000, false, false);
            Container container3 = new Container(4000, false, false);
            Container container4 = new Container(4000, true, false);

            List <Container> containers = new List <Container>();

            containers.Add(container1);
            containers.Add(container2);
            containers.Add(container3);
            containers.Add(container4);

            List <Container> stack1 = new List <Container>();

            stack1.Add(container1);

            List <Container> stack2 = new List <Container>();

            stack2.Add(container2);
            stack2.Add(container4);

            List <Container> stack3 = new List <Container>();

            stack3.Add(container3);

            expected.Stack[0, 0].Containers = stack1;
            expected.Stack[0, 1].Containers = stack2;
            expected.Stack[0, 2].Containers = stack3;
            expected.Weight = 16000;

            Ship      actual = new Ship(1, 3);
            ShipLogic logic  = new ShipLogic(1, 3);

            //Act
            actual = logic.SortContainers(containers);

            //Assert
            Assert.AreEqual(expected.Weight, actual.Weight);

            Assert.AreEqual(expected.Stack[0, 0].Containers.Count, actual.Stack[0, 0].Containers.Count);
            Assert.AreEqual(expected.Stack[0, 1].Containers.Count, actual.Stack[0, 1].Containers.Count);
            Assert.AreNotEqual(expected.Stack[0, 0].Containers.Count, actual.Stack[0, 1].Containers.Count);

            for (int i = 0; i < expected.Stack[0, 0].Containers.Count; i++)
            {
                Assert.AreEqual(expected.Stack[0, 1].Containers[i], actual.Stack[0, 1].Containers[i]);
            }

            for (int i = 0; i < expected.Stack[0, 1].Containers.Count; i++)
            {
                Assert.AreEqual(expected.Stack[0, 1].Containers[i], actual.Stack[0, 1].Containers[i]);
            }

            for (int i = 0; i < expected.Stack[0, 1].Containers.Count; i++)
            {
                Assert.AreEqual(expected.Stack[0, 1].Containers[i].TopWeight, actual.Stack[0, 1].Containers[i].TopWeight);
            }
        }