示例#1
0
        public void FarmBuildingTest()
        {
            Farm    farm    = new Farm(5, 2);
            Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder));

            Assert.False(farm.AbleToFunction);
            Assert.Equal(2, farm.BuildingTime);
            Assert.Equal(0, farm.BuildProgress);
            Assert.Equal(0, farm.CurrentCapacity);
            Assert.Equal(5, farm.MaxCapacity);
            Assert.Equal(0, farm.CurrentConstructionUnitCount);
            Assert.Single(farm.UnitTypes);
            Assert.Single(farm.UnitTypes.Where(u => u == typeof(Farmer)));

            Assert.Empty(farm.DoWork());

            farm.DoBuildProcess();
            Assert.Equal(0, farm.BuildProgress);

            farm.AddConstructionUnit(builder);
            Assert.Equal(1, farm.CurrentConstructionUnitCount);
            farm.DoBuildProcess();
            Assert.Equal(1, farm.BuildProgress);
            Assert.False(farm.AbleToFunction);

            farm.DoBuildProcess();
            Assert.Equal(2, farm.BuildProgress);
            Assert.True(farm.AbleToFunction);
        }
示例#2
0
        public void FarmTest()
        {
            Farm    farm    = new Farm(1, 2);
            Builder builder = (Builder)UnitFactory.CreateUnit(typeof(Builder));
            Farmer  farmer  = (Farmer)UnitFactory.CreateUnit(typeof(Farmer));

            Assert.False(farm.AbleToFunction);
            Assert.Equal(2, farm.BuildingTime);
            Assert.Equal(0, farm.BuildProgress);
            Assert.Equal(0, farm.CurrentCapacity);
            Assert.Equal(1, farm.MaxCapacity);
            Assert.Equal(0, farm.CurrentConstructionUnitCount);
            Assert.Single(farm.UnitTypes);
            Assert.Single(farm.UnitTypes.Where(u => u == typeof(Farmer)));

            farm.DoBuildProcess();
            Assert.Equal(0, farm.BuildProgress);

            farm.AddConstructionUnit(builder);
            Assert.Equal(1, farm.CurrentConstructionUnitCount);
            farm.DoBuildProcess();
            Assert.Equal(1, farm.BuildProgress);
            Assert.False(farm.AbleToFunction);

            farm.DoBuildProcess();
            Assert.Equal(2, farm.BuildProgress);
            Assert.True(farm.AbleToFunction);

            farm.AssignUnit(farmer);
            Assert.Equal(1, farm.CurrentCapacity);
            var resources = farm.DoWork();

            Assert.NotNull(resources);
            Assert.Empty(resources);

            farm.AddInput(new ResourceAmount("cow", 3));
            resources = farm.DoWork();
            Assert.Equal(2, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "meat"));
            Assert.Single(resources.Where(r => r.Type == "meat" && r.Amount == 6)); //3 cow -> 2*3
            Assert.Single(resources.Where(r => r.Type == "milk"));
            Assert.Single(resources.Where(r => r.Type == "milk" && r.Amount == 6));

            resources = farm.DoWork();
            Assert.NotNull(resources);
            Assert.Empty(resources);

            farm.AddInput(new ResourceAmount("cow", 2));
            farm.RemoveInput(new ResourceAmount("cow", 2));
            Assert.NotNull(resources);
            Assert.Empty(resources);

            farm.AddInput(new ResourceAmount("cow", 2));
            farm.RemoveInput(new ResourceAmount("cow", 1));
            resources = farm.DoWork();
            Assert.Equal(2, resources.Count);
            Assert.Single(resources.Where(r => r.Type == "meat"));
            Assert.Single(resources.Where(r => r.Type == "meat" && r.Amount == 2));
            Assert.Single(resources.Where(r => r.Type == "milk"));
            Assert.Single(resources.Where(r => r.Type == "milk" && r.Amount == 2));
        }