public void HaveScrewdriver() { var plumber = new Plumber(); Assert.Contains("螺丝刀", plumber.Tools); Assert.DoesNotContain("键盘", plumber.Tools); }
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); }
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); }
public void HaveNameValue() { var plumber = new Plumber { Name = "Brian" }; Assert.NotNull(plumber.Name); }
public void HaveAllTools() { var plumber = new Plumber(); var expectedTools = new[] { "螺丝刀", "扳子", "钳子" }; Assert.Equal(expectedTools, plumber.Tools); }
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); }
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)); }
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"); } }
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); }
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); }
public void HaveNoEmptyDefaultTools() { var plumber = new Plumber(); Assert.All(plumber.Tools, t => Assert.False(string.IsNullOrEmpty(t))); }
public void NotHaveNameByDefault() { var plumber = new Plumber(); Assert.Null(plumber.Name); }
public void HaveAtLeastOneScrewdriver() { var plumber = new Plumber(); Assert.Contains(plumber.Tools, t => t.Contains("螺丝刀")); }
public void NotHaveKeyboard() { var plumber = new Plumber(); Assert.DoesNotContain("键盘", plumber.Tools); }