Ejemplo n.º 1
0
        public void WaresTest()
        {
            Ship ship = new Ship(ShipLayout.Small, PlayerColor.Blue);
            //create two storages, (only the specialstorage can store red wares), with capacities 5 and 3
            Storage storage        = new Storage(Connector.Universal, Connector.Universal, Connector.Universal, Connector.Universal, 5);
            Storage specialStorage = new SpecialStorage(Connector.Universal, Connector.Universal, Connector.Universal, Connector.Universal, 3);

            ship.AddPart(storage, 5, 4);
            ship.AddPart(specialStorage, 5, 6);

            //initially the storages are empty
            Assert.Equal(0, ship.GetWaresValue());

            Assert.Equal(0, storage.Value);
            Assert.Equal(0, specialStorage.Value);

            //adding red wares, which can only be stored in the specialstorage, the excess won't be stored

            /*Ware values:
             * blue - 1
             * green - 2
             * yellow - 3
             * red - 4
             */
            ship.AddWares(Enumerable.Repeat(Ware.Red, 5));
            Assert.Equal(0, storage.Value);
            Assert.Equal(3 * 4, specialStorage.Value);
            Assert.Equal(3 * 4, ship.GetWaresValue());

            //fill the regular storage with blue wares
            ship.AddWares(Enumerable.Repeat(Ware.Blue, 5));
            Assert.Equal(5, storage.Value);
            Assert.Equal(17, ship.GetWaresValue());

            //try to add a ware more valuable than blue - blue gets replaced
            ship.AddWares(Enumerable.Repeat(Ware.Yellow, 3));
            Assert.Equal(2 * 1 + 3 * 3, storage.Value);

            //try to add a ware less valuable than yellow, but more valuable than blue - resources get partially replaced
            //so the current content of the regular storage is 3 * yellow + 2 * green (specialstorage intact)
            ship.AddWares(Enumerable.Repeat(Ware.Green, 4));
            Assert.Equal(13, storage.Value);
            Assert.Equal(12, specialStorage.Value);
            Assert.Equal(25, ship.GetWaresValue());

            //try to remove a number of resources - the most valuable ones should get removed first
            //with 4 getting removed, it should be 3 red from the special storage, and 1 yellow from the regular one
            Assert.Equal(4, ship.RemoveWares(4));
            Assert.Equal(0, specialStorage.Value);
            Assert.Equal(10, storage.Value);

            //remove a number of wares higher than the remaining(4)
            Assert.Equal(4, ship.RemoveWares(10));
            Assert.Equal(0, storage.Value);
            Assert.Equal(0, specialStorage.Value);
            Assert.Equal(0, ship.GetWaresValue());
        }
Ejemplo n.º 2
0
        public void StorageTest()
        {
            /*wares values:
             * blue - 1
             * green - 2
             * yellow - 3
             * red - 4
             */

            //by default storage is empty
            Storage regularStorage = new Storage(Connector.None, Connector.None, Connector.None, Connector.None, 3);

            Assert.Equal(0, regularStorage.Value);

            //regular storage can't store red wares
            regularStorage.AddWare(Ware.Red);
            Assert.Equal(0, regularStorage.Value);

            //fill the storage with wares of varying value
            regularStorage.AddWare(Ware.Yellow);
            regularStorage.AddWare(Ware.Blue);
            regularStorage.AddWare(Ware.Green);

            Assert.Equal(Ware.Yellow, regularStorage.Max);
            Assert.Equal(Ware.Blue, regularStorage.Min);
            Assert.Equal(6, regularStorage.Value);

            //adding another ware replaces the one with the lowest value
            regularStorage.AddWare(Ware.Yellow);
            Assert.Equal(Ware.Green, regularStorage.Min);
            Assert.Equal(8, regularStorage.Value);

            //removing the ware with the highest value
            regularStorage.RemoveMax();
            Assert.Equal(5, regularStorage.Value);

            //special storage is the same, but can store red wares too
            Storage specialStorage = new SpecialStorage(Connector.None, Connector.None, Connector.None, Connector.None, 3);

            specialStorage.AddWare(Ware.Red);
            Assert.Equal(Ware.Red, specialStorage.Max);
            Assert.Equal(4, specialStorage.Value);
        }