public void AddMember_TwoMembers_AddOneMember_ShouldReturn_3() { Trip instance = new Trip(); instance.AddMember(new Member()); instance.AddMember(new Member()); instance.AddMember(new Member()); Assert.AreEqual(3, instance.Members.Count); }
public static void Main(string[] args) { if (args == null || args.Length == 0) { Console.WriteLine("Please specify a filename."); return; } string inputFile = args[0]; string outputFile = inputFile + ".out"; try { StreamReader sr = new StreamReader(inputFile); // Get the first line as the number of members int memberCount = GetIntegerLine(sr); // Initilize TripGroup class TripGroup tripGroup = new TripGroup(); do { Trip trip = new Trip(); tripGroup.AddTrip(trip); // Loop to add members for (int index = 0; index < memberCount; index++) { Member member = new Member(); trip.AddMember(member); // Get the number of expenses for current member int expenseCount = GetIntegerLine(sr); // Loop to add expenses for (int expenseIndex = 0; expenseIndex < expenseCount; expenseIndex++) { decimal amount = GetDecimalLine(sr); member.AddCharge(amount); } } // Get the number of members for next trip memberCount = GetIntegerLine(sr); }while (memberCount != 0); //Close the read file sr.Close(); // Start to output billing data StreamWriter streamWriter = new StreamWriter(outputFile); // Triger calculation tripGroup.Calculate(); // Call Output method to output data tripGroup.Output(streamWriter); streamWriter.Close(); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public void CaculateAmountDue_ShouldReturnCorrectAmountDue() { Trip instance = new Trip(); Member member1 = new Member() { Charges = new List <decimal> { 2.0m, 4.0m } }; Member member2 = new Member() { Charges = new List <decimal> { 10.0m, 2.0m, 3.2m } }; instance.AddMember(member1); instance.AddMember(member2); instance.CaculateAmountDue(); Assert.AreEqual(4.6m, member1.AmountDue); Assert.AreEqual(-4.6m, member2.AmountDue); }
public void CaculateAmountDue_WithTwoMembersSpendTheSameAmount_ShouldReturnAmountDue_0() { Trip instance = new Trip(); Member member1 = new Member() { Charges = new List <decimal> { 2.0m, 4.0m } }; Member member2 = new Member() { Charges = new List <decimal> { 1.0m, 2.0m, 3.0m } }; instance.AddMember(member1); instance.AddMember(member2); instance.CaculateAmountDue(); Assert.AreEqual(0, member1.AmountDue); Assert.AreEqual(0, member2.AmountDue); }