Ejemplo n.º 1
0
        public void HaveScrewdriver()
        {
            var plumber = new Plumber();

            Assert.Contains("螺丝刀", plumber.Tools);
            Assert.DoesNotContain("键盘", plumber.Tools);
        }
Ejemplo n.º 2
0
        public void HaveCorrectSalary()
        {
            var plumber  = new Plumber();
            var expected = Math.Round(plumber.TotalReward / plumber.Hours, 2);  //precision:2|4

            Assert.Equal(expected, plumber.Salary, precision: 3);
        }
Ejemplo n.º 3
0
        public void HaveCorrectSalary()
        {
            var plumber = new Plumber();

            Assert.NotEqual(66.666, plumber.Salary);
            Assert.NotEqual(66.666, plumber.Salary, precision: 3);
            Assert.Equal(66.667, plumber.Salary, precision: 3);
        }
Ejemplo n.º 4
0
        public void HaveNameValue()
        {
            var plumber = new Plumber
            {
                Name = "Brian"
            };

            Assert.NotNull(plumber.Name);
        }
Ejemplo n.º 5
0
        public void HaveAllTools()
        {
            var plumber       = new Plumber();
            var expectedTools = new[]
            {
                "螺丝刀",
                "扳子",
                "钳子"
            };

            Assert.Equal(expectedTools, plumber.Tools);
        }
Ejemplo n.º 6
0
        public override void Execute()
        {
            var apartment = new Residence
            {
                new Bathroom(),
                new Bedroom(),
                new Kitchen()
            };

            var apartmentMaid = new Maid();

            Assert.Equal(0, apartmentMaid.ServiceCost);

            apartment.Accept(apartmentMaid);
            Assert.Equal(Maid.BathroomPrice + Maid.BedroomPrice, apartmentMaid.ServiceCost);

            var apartmentPlumber = new Plumber();

            Assert.Equal(Plumber.BasePrice, apartmentPlumber.ServiceCost);

            apartment.Accept(apartmentPlumber);
            Assert.Equal(Plumber.BasePrice + Plumber.BathroomPrice + Plumber.KitchenPrice, apartmentPlumber.ServiceCost);


            var house = new Residence
            {
                new Bathroom(),
                new Bathroom(),

                new Bedroom(),
                new Bedroom(),
                new Bedroom(),

                new Kitchen(),
                new LivingRoom()
            };

            var houseMaid = new Maid();

            house.Accept(houseMaid);
            Assert.Equal(Maid.BathroomPrice * 2 + Maid.BedroomPrice * 3, houseMaid.ServiceCost);

            var housePlumber = new Plumber();

            house.Accept(housePlumber);
            Assert.Equal(Plumber.BasePrice + Plumber.BathroomPrice * 2 + Plumber.KitchenPrice, housePlumber.ServiceCost);
        }
Ejemplo n.º 7
0
        public void ShouldTestTemplateMethodPattern()
        {
            //Arrange
            Employee employee1 = new Mechanic();
            Employee employee2 = new Plumber();

            IWorker mechanicWorker;
            IWorker plumberWorker;

            //Act
            mechanicWorker = employee1.Work();
            plumberWorker  = employee2.Work();

            //Assert
            Assert.AreEqual(mechanicWorker.GetType(), typeof(MechanicWorker));
            Assert.AreEqual(plumberWorker.GetType(), typeof(PlumberWorker));
        }
Ejemplo n.º 8
0
        static void CheckSlices(double[] depths, Plumber <double> plumber)
        {
            var enumerable = plumber.GetDepthSlices();

            using (var enumerator = enumerable.GetEnumerator())
            {
                var prevStart = int.MaxValue;
                var prevLimit = int.MinValue;

                for (var depth = plumber.MaxDepth; 0 <= depth; depth--)
                {
                    var depthStart = 0;
                    while (depths[depthStart] < depth)
                    {
                        depthStart++;
                    }

                    var depthLimit = depths.Length;
                    while (depths[depthLimit - 1] < depth)
                    {
                        depthLimit--;
                    }

                    var slice = plumber.GetDepthSlice(depth);
                    Assert.AreEqual(depthStart, slice.Start);
                    Assert.AreEqual(depthLimit, slice.Limit);

                    if (depthStart != prevStart || depthLimit != prevLimit)
                    {
                        Assert.IsTrue(enumerator.MoveNext(), "Another slice is available");
                        Assert.AreEqual(depthStart, enumerator.Current.Start, "Start of enumerated slices matches");
                        Assert.AreEqual(depthLimit, enumerator.Current.Limit, "Limit of enumerated slices matches");

                        prevStart = depthStart;
                        prevLimit = depthLimit;
                    }
                }

                Assert.IsFalse(enumerator.MoveNext(), "Reached end of slices");
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            IWorker carpenter = new Carpenter();
            IWorker plumber   = new Plumber();

            carpenter.DoWork();
            plumber.DoWork();



            //List<Employee> employees = new List<Employee>();
            //employees.Add(new PermanentEmployee(1, "Ahmed"));
            //employees.Add(new TempEmployee(2, "Mohamed"));
            ////employees.Add(new ContractEmployee(3, "Salah"));

            //foreach (var emp in employees)
            //{
            //    Console.WriteLine("Name: {0}, Bouns: {1}, Min: {2} ",
            //        emp.ToString(),
            //        emp.CalculateBonus(100000).ToString(),
            //        emp.GetMinimumSalary().ToString());
            //}


            //Console.WriteLine("============================================");

            //List<IEmployee> emps = new List<IEmployee>();
            //emps.Add(new PermanentEmployee(1, "Ahmed"));
            //emps.Add(new TempEmployee(2, "Mohamed"));
            //emps.Add(new ContractEmployee(3, "Salah"));

            //foreach (var emp in emps)
            //{
            //    Console.WriteLine("Name: {0}, Min: {1} ",
            //        emp.ToString(),
            //        emp.GetMinimumSalary().ToString());
            //}

            Console.ReadKey(true);
        }
Ejemplo n.º 10
0
        static Plumber <double> CreatePlumber(double[] depths)
        {
            var limit = depths.Length;

            Assert.IsTrue(0 < limit, "Must be at least one value");

            // Start assing first position is maximum depth.
            var depth    = depths[0];
            var position = 1;

            // Work down to edge of supposed bottom.
            while (position < limit && depth < depths[position])
            {
                depth = depths[position];

                position++;
            }

            var maxPosition = position - 1;

            // Work way back up.
            while (position < limit)
            {
                Assert.IsTrue(depths[position] < depth);
                depth = depths[position];

                position++;
            }

            Assert.AreEqual(limit, position);

            var plumber = Plumber <double> .Create(1, (r, i) => (int)depths[i], (r, i) => maxPosition < i? -1 : maxPosition == i? 0 : 0, limit);

            Assert.AreEqual((int)depths[maxPosition], plumber.MaxDepth);

            return(plumber);
        }
Ejemplo n.º 11
0
        public void HaveNoEmptyDefaultTools()
        {
            var plumber = new Plumber();

            Assert.All(plumber.Tools, t => Assert.False(string.IsNullOrEmpty(t)));
        }
Ejemplo n.º 12
0
        public void NotHaveNameByDefault()
        {
            var plumber = new Plumber();

            Assert.Null(plumber.Name);
        }
Ejemplo n.º 13
0
        public void HaveAtLeastOneScrewdriver()
        {
            var plumber = new Plumber();

            Assert.Contains(plumber.Tools, t => t.Contains("螺丝刀"));
        }
Ejemplo n.º 14
0
        public void NotHaveKeyboard()
        {
            var plumber = new Plumber();

            Assert.DoesNotContain("键盘", plumber.Tools);
        }