예제 #1
0
        public void LargeSetOfContainers_ShouldBeDividedWithinLimits()
        {
            // Arrange
            CargoShip        ship       = new CargoShip(4, 3, 4000);
            List <Container> containers = new List <Container>()
            {
                new Container(225, ContainerType.Normal),
                new Container(50, ContainerType.Normal),
                new Container(150, ContainerType.Coolable),
                new Container(100, ContainerType.Normal),
                new Container(100, ContainerType.Normal),
                new Container(175, ContainerType.Valuable),
                new Container(150, ContainerType.Normal),
                new Container(100, ContainerType.ValuableAndCoolable),
                new Container(100, ContainerType.Normal),
                new Container(100, ContainerType.Valuable),
                new Container(100, ContainerType.Normal),
                new Container(375, ContainerType.Normal),
                new Container(50, ContainerType.Valuable),
                new Container(100, ContainerType.Coolable),
                new Container(150, ContainerType.ValuableAndCoolable),
                new Container(100, ContainerType.Normal),
                new Container(250, ContainerType.Normal),
                new Container(300, ContainerType.Valuable),
                new Container(100, ContainerType.Normal),
                new Container(275, ContainerType.Coolable)
            };

            // Act
            ship.Divide(containers);
            double leftWeightRatio = ship.GetLeftWeightRatio();

            // Assert
            Assert.AreEqual(0.5d, leftWeightRatio, 0.2d);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("(this is one row on the ship)");
            Console.WriteLine("stacked, values, here");
            Console.WriteLine("each, one, is, a, column");
            Console.WriteLine("bottom, to, top");
            Console.WriteLine();


            List <Container> containers = new List <Container>()
            {
                new Container(346, ContainerType.Normal),
                new Container(873, ContainerType.Normal),
                new Container(182, ContainerType.Normal),
                new Container(784, ContainerType.Normal),
                new Container(505, ContainerType.Normal),
                new Container(133, ContainerType.Normal),
                new Container(126, ContainerType.Coolable),
                new Container(173, ContainerType.Coolable),
                new Container(284, ContainerType.Valuable),
                new Container(183, ContainerType.Valuable),
                new Container(177, ContainerType.Valuable),
                new Container(185, ContainerType.Valuable),
                new Container(137, ContainerType.Valuable),
                new Container(190, ContainerType.ValuableAndCoolable),
                new Container(168, ContainerType.Valuable),
                new Container(302, ContainerType.ValuableAndCoolable),
                new Container(547, ContainerType.Normal),
                new Container(284, ContainerType.Normal),
                new Container(273, ContainerType.Normal),
                new Container(941, ContainerType.Normal),
                new Container(725, ContainerType.Normal),
                new Container(825, ContainerType.Normal),
                new Container(477, ContainerType.Coolable),
                new Container(168, ContainerType.Coolable),
                new Container(294, ContainerType.Valuable),
                new Container(624, ContainerType.Valuable),
                new Container(157, ContainerType.Valuable),
                new Container(345, ContainerType.ValuableAndCoolable)
            };

            CargoShip ship = new CargoShip(5, 7, containers.Sum(c => c.Weight));

            try
            {
                ContainerRow[] rows = ship.Divide(containers);
                for (int i = 0; i < rows.Length; i++)
                {
                    Console.WriteLine($"----------- {i}:");
                    Console.Write(rows[i].ToString());
                }
                Console.WriteLine("\n\n" + GetTotalWeightString(rows));
            } catch (Exception e) { Console.WriteLine(e.Message); }
        }
        public void CargoShipContents_UnbalancedWeight()
        {
            // Arrange
            CargoShip        ship       = new CargoShip(1, 1, 200);
            List <Container> containers = new List <Container>()
            {
                new Container(75, ContainerType.Normal), new Container(25, ContainerType.Normal)
            };

            // Act, Assert
            Assert.ThrowsException <Exception>(() => ship.Divide(containers));
        }
        public void CargoShipContents_TooMuchWeight()
        {
            // Arrange
            CargoShip        ship       = new CargoShip(1, 1, 100);
            List <Container> containers = new List <Container>()
            {
                new Container(1000, ContainerType.Normal)
            };

            // Act, Assert
            Assert.ThrowsException <Exception>(() => ship.Divide(containers));
        }
예제 #5
0
        public void ValuableContainer_ShouldThrow_BecauseNotEnoughSpace()
        {
            // Arrange
            CargoShip        ship = new CargoShip(3, 1, 100);
            Container        valuableContainer = new Container(30, ContainerType.Valuable);
            List <Container> containers        = new List <Container>()
            {
                valuableContainer, valuableContainer, valuableContainer
            };

            // Act, Assert
            Assert.ThrowsException <Exception>(() => ship.Divide(containers));
        }
예제 #6
0
        public void ValuableContainer_ShouldDivide_BecauseCoolableMayBeStacked()
        {
            // Arrange
            CargoShip        ship = new CargoShip(3, 1, 100);
            Container        coolableContainer = new Container(30, ContainerType.Coolable);
            List <Container> containers        = new List <Container>()
            {
                coolableContainer, coolableContainer, coolableContainer
            };

            // Act
            ContainerRow[] rows = ship.Divide(containers);

            // Assert
            Assert.IsTrue(rows[0].GetTotalContainers() == 3);
        }
예제 #7
0
        public void CoolableContainer_ShouldBeInFront()
        {
            // Arrange
            CargoShip        ship = new CargoShip(3, 1, 100);
            Container        coolableContainer = new Container(30, ContainerType.Coolable);
            Container        normalContainer   = new Container(30, ContainerType.Normal);
            List <Container> containers        = new List <Container>()
            {
                normalContainer, normalContainer, coolableContainer
            };

            // Act
            ContainerRow[] rows = ship.Divide(containers);

            // Assert
            Assert.IsTrue(rows[0][0][0].Type == ContainerType.Coolable);
        }
예제 #8
0
        public void SmallSetOfContainers_ShouldBeDividedWithinLimits()
        {
            // Arrange
            CargoShip        ship       = new CargoShip(2, 2, 120);
            List <Container> containers = new List <Container>()
            {
                new Container(30, ContainerType.Normal),
                new Container(30, ContainerType.Normal),
                new Container(30, ContainerType.Normal),
                new Container(30, ContainerType.Normal)
            };

            // Act
            ship.Divide(containers);
            double leftWeightRatio = ship.GetLeftWeightRatio();

            // Assert
            Assert.AreEqual(0.5d, leftWeightRatio, 0.2d);
        }