コード例 #1
0
        public void Test1_Farmer_4pts(string s)
        {
            Villager v;

            if (s == "farmer")
            {
                v = new Farmer();
            }
            else
            {
                v = new Slacker();
            }

            Assert.NotNull(v);
            int actual       = v.Farm();
            int hungerActual = v.Hunger;

            if (s == "farmer")
            {
                Assert.Equal(2, actual);
                Assert.Equal(1, hungerActual);
            }
            else
            {
                Assert.Equal(0, actual);
                Assert.Equal(3, hungerActual);
            }
        }
コード例 #2
0
        public void Test3_TownHasRightVillagers_1pt()
        {
            Town            t     = new Town();
            List <Villager> vills = t.Villagers;

            int actual   = vills[0].Farm();
            int expected = 2;

            //This is a farmer
            Assert.Equal(expected, actual);
            Farmer  farmer = new Farmer();
            Slacker slacker = new Slacker();
            int     farmTotal = 0, slackTotal = 0;


            for (int i = 0; i < vills.Count; i++)
            {
                //These are slackers
                Villager v = vills[i];
                if (v.GetType() == farmer.GetType())
                {
                    farmTotal++;
                }
                else
                {
                    slackTotal++;
                }
            }

            int expectedFarmers  = 1;
            int expectedSlackers = 3;

            Assert.Equal(expectedFarmers, farmTotal);
            Assert.Equal(expectedSlackers, slackTotal);
        }
コード例 #3
0
        // Constructor
        public Town(Farmer farmer, Slacker slacker1, Slacker slacker2, Slacker slacker3)
        {
            Villagers = new List <Villager>();

            Villagers.Add(farmer);
            Villagers.Add(slacker1);
            Villagers.Add(slacker2);
            Villagers.Add(slacker3);
        }