Ejemplo n.º 1
0
        public void CalculateBill()
        {
            Participant p1 = new Participant();

            p1.AddCharge(10.00);
            p1.AddCharge(20.00);

            Participant p2 = new Participant();

            p2.AddCharge(15.00);
            p2.AddCharge(15.01);
            p2.AddCharge(3.00);
            p2.AddCharge(3.01);

            Participant p3 = new Participant();

            p3.AddCharge(5.00);
            p3.AddCharge(9.00);
            p3.AddCharge(4.00);

            Expense e = new Expense();

            e.AddParticipant(p1);
            e.AddParticipant(p2);
            e.AddParticipant(p3);

            List <Expense> eList = new List <Expense> {
                e
            };

            ICalculator c = new ExpenseCalculator(eList);

            c.Calculate();

            Assert.AreEqual(Math.Round(eList[0].Participants[0].Balance, 2), -1.99);
            Assert.AreEqual(Math.Round(eList[0].Participants[1].Balance, 2), -8.01);
            Assert.AreEqual(Math.Round(eList[0].Participants[2].Balance, 2), 10.01);
        }
Ejemplo n.º 2
0
 private void ProcessCharge(Participant participant)
 {
     //Check if token is correct
     if (_lookaheadFirst.TokenType == TokenType.Amount)
     {
         //Get the charge amount
         double charge = double.Parse(_lookaheadFirst.Value);
         //Add charge to participant
         participant.AddCharge(charge);
         //Discart current token
         DiscardToken();
     }
     else if (_lookaheadFirst.TokenType == TokenType.Zero)
     {
         throw new InvalidEndOfFileException();
     }
     else
     {
         throw new InvalidTokenException(_line, _lookaheadFirst.Value, "Charge amount");
     }
 }