public void CreateConstantAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Constant, 1));
            AlgoFactory.AddFactory(AlgoType.Constant);
            var algo = AlgoFactory.CreateAlgo(AlgoType.Constant, 1);

            Assert.True(algo is ConstantAlgo);
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(1, algo.GetNext());
        }
        public void CreateMultipleAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Multiple, 1, 2));
            AlgoFactory.AddFactory(AlgoType.Multiple);
            var algo = AlgoFactory.CreateAlgo(AlgoType.Multiple, 1, 2);

            Assert.True(algo is MultipleAlgo);
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(2, algo.GetNext());
            Assert.Equal(4, algo.GetNext());
        }
        public void CreateIncrementAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Increment, 1, 5));
            AlgoFactory.AddFactory(AlgoType.Increment);
            var algo = AlgoFactory.CreateAlgo(AlgoType.Increment, 1, 5);

            Assert.True(algo is IncrementAlgo);
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(6, algo.GetNext());
            Assert.Equal(11, algo.GetNext());
        }
        public void CreateExpAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Exp, 3));
            AlgoFactory.AddFactory(AlgoType.Exp);
            var algo = AlgoFactory.CreateAlgo(AlgoType.Exp, 3);

            Assert.True(algo is ExpAlgo);
            Assert.Equal(3, algo.GetNext());
            Assert.Equal(9, algo.GetNext());
            Assert.Equal(27, algo.GetNext());
        }
        public void CreateFibonacciAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Fibonacci));
            AlgoFactory.AddFactory(AlgoType.Fibonacci);
            var algo = AlgoFactory.CreateAlgo(AlgoType.Fibonacci);

            Assert.True(algo is FibonacciAlgo);
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(2, algo.GetNext());
            Assert.Equal(3, algo.GetNext());
        }
        public void CreateMoreMultipleAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Multiple, 1, 2));
            AlgoFactory.AddFactory(AlgoType.Multiple);
            var algo  = AlgoFactory.CreateAlgo(AlgoType.Multiple, 1, 2);
            var algo2 = AlgoFactory.CreateAlgo(AlgoType.Multiple, 2, 1.5);

            Assert.True(algo is MultipleAlgo);
            Assert.True(algo2 is MultipleAlgo);
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(2, algo.GetNext());
            Assert.Equal(4, algo.GetNext());
            Assert.Equal(2, algo2.GetNext());
            Assert.Equal(3, algo2.GetNext());
            Assert.Equal(5, algo2.GetNext()); //4,5
            Assert.Equal(7, algo2.GetNext()); //6,75
        }
        public void CreateMoreIncrementAlgoTest()
        {
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Increment, 1, 3));
            AlgoFactory.AddFactory(AlgoType.Increment);
            var algo  = AlgoFactory.CreateAlgo(AlgoType.Increment, 1, 3);
            var algo2 = AlgoFactory.CreateAlgo(AlgoType.Increment, 2, 4);

            Assert.True(algo is IncrementAlgo);
            Assert.True(algo2 is IncrementAlgo);
            Assert.Equal(1, algo.GetNext());
            Assert.Equal(4, algo.GetNext());
            Assert.Equal(7, algo.GetNext());
            Assert.Equal(10, algo.GetNext());
            Assert.Equal(2, algo2.GetNext());
            Assert.Equal(6, algo2.GetNext());
            Assert.Equal(10, algo2.GetNext());
        }
Exemple #8
0
        public PlayerTests()
        {
            ConfigurationManager.SetJson(Utility.CONFIGFILE_JSON);

            AlgoFactory.CleanFactories();
            AlgoFactory.AddFactory(AlgoType.Constant);
            AlgoFactory.AddFactory(AlgoType.Exp);
            AlgoFactory.AddFactory(AlgoType.Fibonacci);
            AlgoFactory.AddFactory(AlgoType.Increment);
            AlgoFactory.AddFactory(AlgoType.Multiple);

            UnitFactory.CleanFactories();
            GathererUnitRegister gathererVisitor = new GathererUnitRegister();

            UnitFactory.AddFactory(gathererVisitor);
            BuilderUnitRegister builderVisitor = new BuilderUnitRegister();

            UnitFactory.AddFactory(builderVisitor);
            FarmerUnitRegister farmerVisitor = new FarmerUnitRegister();

            UnitFactory.AddFactory(farmerVisitor);
            ResearcherUnitRegister researcherVisitor = new ResearcherUnitRegister();

            UnitFactory.AddFactory(researcherVisitor);

            BuildingFactory.CleanFactories();

            ForestCampBuildingRegister forestCampVisitor = new ForestCampBuildingRegister();

            BuildingFactory.AddFactory(forestCampVisitor);
            MiningVillageBuildingRegister miningVillageVisitor = new MiningVillageBuildingRegister();

            BuildingFactory.AddFactory(miningVillageVisitor);
            FarmBuildingRegister farmVisitor = new FarmBuildingRegister();

            BuildingFactory.AddFactory(farmVisitor);
            LabBuildingRegister labVisitor = new LabBuildingRegister();

            BuildingFactory.AddFactory(labVisitor);

            Market.ResetMarket();
            Player.GetInstance().ResetPlayer();
        }
        public void CreateFailTest()
        {
            AlgoFactory.AddFactory(AlgoType.Constant);
            AlgoFactory.AddFactory(AlgoType.Increment);
            AlgoFactory.AddFactory(AlgoType.Multiple);
            AlgoFactory.AddFactory(AlgoType.Exp);
            AlgoFactory.AddFactory(AlgoType.Fibonacci);

            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Constant, 3, 1));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Constant));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Increment, 1));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Increment));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Multiple, 8));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Multiple));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Exp, 1, 7));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Exp));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Fibonacci, 10, 1));
            Assert.Throws <Exception>(() => AlgoFactory.CreateAlgo(AlgoType.Fibonacci, 7));
        }