Ejemplo n.º 1
0
 public void SetupTests()
 {
     sut = new BeeGame();
     var queensRule = new GameRule(0, 1, 100, 8);
     var workersRule = new GameRule(0, 5, 75, 10);
     var dronesRule = new GameRule(0, 8, 50, 12);
     settings = new GameSettings(queensRule, workersRule, dronesRule);
 }
Ejemplo n.º 2
0
        public ActionResult StartGame()
        {
            game = (BeeGame)Session["game"];

            settings = (GameSettings)Session["settings"];
            game.Start(settings);

            return View("Index", game);
        }
Ejemplo n.º 3
0
        public ActionResult HitBee()
        {
            game = (BeeGame)Session["game"];

            if (game.IsPlaying)
            {
                game.HitBee(game.Hive);
            }

            return View("Index", game);
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            game = new BeeGame();
            settings = new GameSettings(new GameRule(0, 1, 100, 8), new GameRule(0, 5, 75, 10), new GameRule(0, 8, 50, 12));

            game.Start(settings);

            Session["game"] = game;
            Session["settings"] = settings;

            return View(game);
        }
Ejemplo n.º 5
0
        public void Given_SpawnHive_Should_return_two_QueenBees_Invalid()
        {
            //  Arrange
            var sut = new BeeGame();
            var rule = new GameRule(0, 1, 0, 0);

            //  Act
            var result = sut.Start(new GameSettings(new GameRule(0, 2, 0, 0), rule, rule));

            var queen = result.Hive
                .Where(b => b.GetType().Equals(typeof(Queen)))
                .Select(b => b);

            //  Assert
            Assert.IsTrue(queen.Count() != 1);
        }
Ejemplo n.º 6
0
        public void Given_SpawnHive_Should_return_one_QueenBee_Valid()
        {
            //  Arrange
            var sut = new BeeGame();
            var rule = new GameRule(0, 1, 0, 0);

            //  Act
            var result = sut.Start(new GameSettings(rule, rule, rule));

            var queen = result.Hive
                .Where(b => b.GetType().Equals(typeof(Queen)))
                .Select(b => b);

            //  Assert
            Assert.AreEqual(1, queen.Count());
        }
Ejemplo n.º 7
0
        public void Given_SpawnHive_no_parameters_Should_return_one_QueenBee_null()
        {
            //  Arrange
            var sut = new BeeGame();
            var rule = new GameRule(0, 0, 0, 0);

            //  Act
            try
            {
                var result = sut.Start(new GameSettings(rule, rule, rule));
            }
            catch (Exception e)
            {
                //  Assert
                Assert.AreEqual("Queen Bees Quantity Can't be 0", e.Message);
                throw;
            }
        }
Ejemplo n.º 8
0
        public void GetLifeSpan_Drone_Should_Return_Invalid()
        {
            //  Arrange
            var sut = new BeeGame();
            var hive = new List<IBee>
            {
                new Queen(new Bee(10,0))
            };

            //  Act
            var result = sut.GetLifeSpan(typeof(Drone), hive);

            //  Assert
            Assert.AreNotEqual(10, result);
        }
Ejemplo n.º 9
0
        public void GetLifeSpan_Worker_Should_Return_Valid()
        {
            //  Arrange
            var sut = new BeeGame();
            var hive = new List<IBee>
            {
                new Worker(new Bee(10,0))
            };

            //  Act
            var result = sut.GetLifeSpan(typeof(Worker), hive);

            //  Assert
            Assert.AreEqual(10, result);
        }
Ejemplo n.º 10
0
        public void Called_HitBee_onHit_untill_zero_should_return_one_LifeSpan_zero()
        {
            //  Arrange
            var sut = new BeeGame().Start(settings);

            //  Act
            int hivePopulation = sut.Hive.Count();
            var bee = sut.Hive.FirstOrDefault(b => !b.GetType().Equals(typeof(Queen)));
            do
            {
                bee.Hit();

            } while (bee.LifeSpan > 0);

            sut.Hive = bee.CheckStatus(bee, sut.Hive);

            //  Assert
            Console.WriteLine(bee.GetType().Name);
            Assert.AreEqual(1, sut.Hive.Count(b => b.LifeSpan == 0));
        }
Ejemplo n.º 11
0
        public void Called_HitBee_Should_decrease_bee_lifespan()
        {
            //  Arrange
            var sut = new BeeGame().Start(settings);
            var startScore = sut.Hive.Select(b => b.LifeSpan).Sum();

            //  Act
            var teste = sut.HitBee(sut.Hive);
            var newScore = sut.Hive.Select(b => b.LifeSpan).Sum();

            //  Assert
            Assert.AreNotEqual(newScore, startScore);
        }
Ejemplo n.º 12
0
        public void Given_SpawnHive_valid_Should_NOT_Hit_random_bee()
        {
            //  Arrange
            var random = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
            var sut = new BeeGame().Start(settings);
            var container = new List<int>();
            var hive = new Hive();

            //  Act
            for (int i = 0; i < 25; i++)
            {
                var bee = sut.Hive[1];
                container.Add(sut.Hive.IndexOf(bee));
            }
            var result = container.Average();

            //  Assert
            Assert.AreEqual(container[0], result);
        }
Ejemplo n.º 13
0
        public void Given_SpawnHive_Should_return_bees_number_valid()
        {
            //  Arrange
            var sut = new BeeGame();

            //  Act
            var result = sut.Start(settings);

            var queens = result.Hive
                .Where(b => b.GetType().Equals(typeof(Queen)))
                .Select(b => b);

            var workers = result.Hive
                .Where(b => b.GetType().Equals(typeof(Worker)))
                .Select(b => b);

            var drones = result.Hive
                .Where(b => b.GetType().Equals(typeof(Drone)))
                .Select(b => b);

            //  Assert
            Assert.AreEqual(14, result.Hive.Count());
            Assert.AreEqual(1, queens.Count());
            Assert.AreEqual(5, workers.Count());
            Assert.AreEqual(8, drones.Count());
        }
Ejemplo n.º 14
0
        public void Given_SpawnHive_Should_return_one_DroneBees_Invalid()
        {
            //  Arrange
            var sut = new BeeGame();
            var rule = new GameRule(0, 1, 0, 0);

            //  Act
            var result = sut.Start(new GameSettings(rule, new GameRule(0, 2, 0, 0), rule));

            var drones = result.Hive
                .Where(b => b.GetType().Equals(typeof(Drone)))
                .Select(b => b);

            //  Assert
            Assert.IsTrue(drones.Count() != 5);
        }
Ejemplo n.º 15
0
        public void Given_SpawnHive_Should_return_eight_DroneBees_Valid()
        {
            //  Arrange
            var sut = new BeeGame();
            var rule = new GameRule(0, 1, 0, 0);

            //  Act
            var result = sut.Start(new GameSettings(rule, rule, new GameRule(0, 8, 0, 0)));

            var drones = result.Hive
                .Where(b => b.GetType().Equals(typeof(Drone)))
                .Select(b => b);

            //  Assert
            Assert.AreEqual(8, drones.Count());
        }
Ejemplo n.º 16
0
        public void Called_HitBee_onHit_untill_zero_should_remove_all_lifespan_from_hive()
        {
            //  Arrange
            var sut = new BeeGame().Start(settings);

            //  Act
            var bee = sut.Hive.FirstOrDefault(b => b.GetType().Equals(typeof(Queen)));
            do
            {
                bee.Hit();

            } while (bee.LifeSpan > 0);

            sut.Hive = bee.CheckStatus(bee, sut.Hive);

            //  Assert
            Console.WriteLine(bee.GetType().Name);
            Assert.AreEqual(0, sut.Hive.Sum(b => b.LifeSpan));
        }
Ejemplo n.º 17
0
        public void Given_SpawnHive_Should_return_five_WorkerBees_Valid()
        {
            //  Arrange
            var sut = new BeeGame();
            var rule = new GameRule(0, 1, 0, 0);

            //  Act
            var result = sut.Start(new GameSettings(rule, new GameRule(0, 5, 0, 0), rule));

            var workers = result.Hive
                .Where(b => b.GetType().Equals(typeof(Worker)))
                .Select(b => b);

            //  Assert
            Assert.AreEqual(5, workers.Count());
        }