Exemplo n.º 1
0
        public void SellDevelopableLand_Developed_Unmortgaged()
        {
            int[] rentTable = new int[6] {
                4, 20, 60, 180, 320, 500
            };
            DevelopableLand gangstersParadise = new DevelopableLand("Gangsters Paradise",
                                                                    60, Colour.Brown, rentTable);

            // develop property with 1 house
            gangstersParadise.Develop();
            Assert.AreEqual(1, gangstersParadise.GetHouses());

            // check if property can be sold
            Assert.IsFalse(gangstersParadise.CanSellProperty());

            // cannot sell, must undevelop property first
            gangstersParadise.Undevelop();
            Assert.AreEqual(0, gangstersParadise.GetHouses());

            // unmortgaged property sells for original price value (£60)
            Assert.IsTrue(gangstersParadise.CanSellProperty());
            int sellingPrice = gangstersParadise.SellPropertyToBank();

            Assert.AreEqual(60, sellingPrice);
            // property is unowned after selling
            Assert.IsNull(gangstersParadise.GetOwner());
        }
Exemplo n.º 2
0
        public void InitaliseDevelopableLandWithCorrectData()
        {
            int[] rentTable = new int[6] {
                30, 60, 100, 150, 200, 320
            };
            int             price   = 200;
            Colour          group   = Colour.Blue;
            DevelopableLand reyLane = new DevelopableLand("Rey Lane", price, group, rentTable);

            // correct name
            Assert.AreEqual("Rey Lane", reyLane.GetPropertyName());
            // correct price
            Assert.AreEqual(200, reyLane.GetPrice());
            // correct group
            Assert.AreEqual(Colour.Blue, reyLane.GetColourGroup());
            // correct rent table
            var actualRentTable = reyLane.GetRentTable();

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(rentTable[i], actualRentTable[i]);
            }
            // initially unowned
            Assert.IsNull(reyLane.GetOwner());
            // initially unmortgaged
            Assert.IsFalse(reyLane.IsMortgaged());
            // initially undeveloped
            Assert.AreEqual(0, reyLane.GetHouses());
            // implements IProperty interface
            Assert.IsTrue(reyLane is IProperty);
        }
Exemplo n.º 3
0
        public void Player_DevelopProperty()
        {
            HumanPlayer     player        = new HumanPlayer("Bob", 0, Token.Boot);
            DevelopableLand crapperStreet = new DevelopableLand("Crapper Street", 100, Colour.Brown, new int[6] {
                20, 20, 40, 60, 80, 100
            });
            DevelopableLand gangsters = new DevelopableLand("Gangsters Paradise", 100, Colour.Brown, new int[6] {
                20, 20, 40, 60, 80, 100
            });

            // attempt to develop crapper street without buying property first throws error
            try
            {
                player.DevelopProperty(crapperStreet);
            }
            catch (Exception e)
            {
                Assert.AreEqual("Cannot develop a property that you don't own!", e.Message);
            }

            // bob buys property and buys 2 houses, development = 2
            player.BuyProperty(crapperStreet);
            int cash = player.PeekCash();

            player.DevelopProperty(crapperStreet);
            player.DevelopProperty(crapperStreet);
            Assert.AreEqual(cash - 100, player.PeekCash());
            Assert.AreEqual(2, crapperStreet.GetHouses());

            // bob sells developments
            player.UndevelopProperty(crapperStreet);
            player.UndevelopProperty(crapperStreet);
            Assert.AreEqual(cash, player.PeekCash());
            Assert.AreEqual(0, crapperStreet.GetHouses());

            // bob sells the property and attempts to sell developments
            player.SellProperty(crapperStreet);
            try
            {
                player.UndevelopProperty(crapperStreet);
            }
            catch (HumanPlayerException e)
            {
                Assert.AreEqual("Cannot undevelop a property that you don't own!", e.Message);
            }
        }
Exemplo n.º 4
0
        public void DevelopableLand_CalculateTotalValue()
        {
            int[] rentTable = new int[6] {
                30, 60, 100, 150, 200, 320
            };
            int             price   = 200;
            Colour          group   = Colour.Blue;
            DevelopableLand reyLane = new DevelopableLand("Rey Lane", price, group, rentTable);

            // total value = original price (unmortgaged, undeveloped)
            Assert.AreEqual(200, reyLane.CalculateTotalValue());
            // mortgage undeveloped property
            reyLane.Mortgage();
            Assert.IsTrue(reyLane.IsMortgaged());
            // total value = original price / 2
            Assert.AreEqual(100, reyLane.CalculateTotalValue());
            // unmortgaged property
            reyLane.Unmortgage();
            Assert.IsFalse(reyLane.IsMortgaged());
            // develop property with 3 houses
            for (int i = 0; i < 3; i++)
            {
                reyLane.Develop();
            }
            Assert.AreEqual(3, reyLane.GetHouses());
            // get correct house price
            int housePrice = reyLane.GetDevelopCost();

            Assert.AreEqual(50, housePrice);
            // total value = original price + (3 * houseprice)
            int correctTotal = 200 + (3 * 50);

            Assert.AreEqual(correctTotal, reyLane.CalculateTotalValue());

            // mortgage property
            reyLane.Mortgage();
            Assert.IsTrue(reyLane.IsMortgaged());

            //total value = (original price / 2) + (3 * houseprice)
            int correctTotal2 = (200 / 2) + (3 * housePrice);

            Assert.AreEqual(correctTotal2, reyLane.CalculateTotalValue());
        }