예제 #1
0
        public void MultiplyNWithSum_GivenValidSumForThree_ReturnsCorrectProduct()
        {
            var calculator = new ExpenseCalculator(new[] { 1721, 979, 366, 299, 675, 1456 });

            var result = calculator.MultiplyNWithSum(2020, 3);

            Assert.AreEqual(241861950, result);
        }
예제 #2
0
        public void FindNWithSum_GivenInvalidSum_ReturnsNull()
        {
            var calculator = new ExpenseCalculator(new[] { 1721, 979, 366, 299, 675, 1456 });

            var result = calculator.FindNWithSum(2021);

            Assert.IsNull(result);
        }
예제 #3
0
        public void FindNWithSum_GivenValidSumForThree_ReturnsThreeWithSum()
        {
            var calculator = new ExpenseCalculator(new[] { 1721, 979, 366, 299, 675, 1456 });

            var result = calculator.FindNWithSum(2020, 3);

            Assert.AreEqual(new[] { 366, 675, 979 }, result);
        }
예제 #4
0
        private void LoadService(DateTime date)
        {
            var            listCruise = ListCruise;
            IList <Cruise> cruises;

            if (Cruise == null)
            {
                cruises = listCruise.ToList();
            }
            else
            {
                cruises = new List <Cruise>();
                cruises.Add(Cruise);
            }

            _date = date;
            if (Cruise != null)
            {
                Expense expense = Module.ExpenseGetByDate(Cruise, date);
                if (expense.Id <= 0)
                {
                    Module.SaveOrUpdate(expense);
                }

                ExpenseCalculator calculator = new ExpenseCalculator(Module, PartnershipManager);

                _customerCost = 0;
                _runningCost  = 0;
                Dictionary <CostType, double> cost = calculator.ExpenseCalculate(null, expense);
                foreach (KeyValuePair <CostType, double> pair in cost)
                {
                    if (pair.Key.IsSupplier && !pair.Key.IsDailyInput && !pair.Key.IsDaily && !pair.Key.IsMonthly &&
                        !pair.Key.IsYearly)
                    {
                        _customerCost += pair.Value;
                    }
                    else if (pair.Key.IsSupplier && !pair.Key.IsDailyInput && pair.Key.IsDaily)
                    {
                        _runningCost += pair.Value;
                    }
                }
            }

            if (DailyCost.Count > 0)
            {
                rptCruiseExpense.DataSource = cruises;
                rptCruiseExpense.DataBind();
            }
            else
            {
                plhDailyExpenses.Visible = false;
                rptCruiseExpense.Visible = false;
            }
        }
예제 #5
0
        public void ProcessFile()
        {
            IFileHelper expenseFileHelper = new ExpenseFileHelper(_fileName);

            //Process Input
            expenseFileHelper.ReadFile();
            expenseFileHelper.ValidateFile();

            //Calculate
            ICalculator calc = new ExpenseCalculator(expenseFileHelper.GetExpenses());

            calc.Calculate();

            //Process Output
            _fileOutput = expenseFileHelper.CreateOutput();
        }
예제 #6
0
 public HttpResponseMessage CalculateTrip([FromBody] TripList enteredTrip)
 {
     try
     {
         //Json.NET deserializes the given JSON into a list of trips but we only get one at a time
         var trip = enteredTrip.Trip.FirstOrDefault();
         var expenseCalculator = new ExpenseCalculator();
         var amountOwed        = string.Format("{0:f2}", expenseCalculator.GetAmountOwed(trip));
         return(Request.CreateResponse(HttpStatusCode.OK, amountOwed));
     }
     catch (Exception e)
     {
         var errorMessage  = enteredTrip == null ? "Invalid data given." : e.Message;
         var errorResponse = Request.CreateResponse(HttpStatusCode.BadRequest, errorMessage);
         return(errorResponse);
     }
 }
예제 #7
0
        static void Main(string[] args)
        {
            UserCredential    credential;
            ExpenseCalculator calculator = new ExpenseCalculator();

            using (var stream =
                       new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

                        // Create Gmail API service.
                        var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });


            var inboxlistRequest = service.Users.Messages.List("me");

            inboxlistRequest.LabelIds         = "INBOX";
            inboxlistRequest.IncludeSpamTrash = false;
            inboxlistRequest.Q = "after:2018/12/18";
            //get our emails
            var emailListResponse = inboxlistRequest.Execute();

            if (emailListResponse != null && emailListResponse.Messages != null)
            {
                //loop through each email and get what fields you want...
                IEnumerable <MailEntity> lstentity = calculator.GetTransactionDetails(emailListResponse, service);
            }
            Console.ReadLine();
        }
예제 #8
0
        public ActionResult Details(Guid instanceId)
        {
            using (var db = Context.Create())
            {
                var instance  = db.Instances.Find(instanceId);
                var users     = db.UserToInstanceMappings.AsNoTracking().Where(m => m.InstanceId == instanceId).Select(m => m.User).ToList();
                var abscenses = db.Abscenses.AsNoTracking().Where(a => a.InstanceId == instanceId).ToLookup(x => x.UserId);
                foreach (var u in users)
                {
                    u.Abscenses = (abscenses[u.Id] ?? Enumerable.Empty <Abscense>()).ToList();
                }
                var expenses   = db.Expenses.AsNoTracking().Where(e => e.InstanceId == instanceId).ToList();
                var categories = db.Categories.AsNoTracking().Where(e => e.InstanceId == instanceId).ToDictionary(c => c.Id);
                foreach (var e in expenses)
                {
                    e.Category = categories[e.CategoryId];
                }


                var joinUrl = Url.Action("Join", "Instance",
                                         routeValues: new { instanceId },
                                         protocol: Request.Url.Scheme);
                var userBalances = new ExpenseCalculator().CalculateBalances(instance,
                                                                             users,
                                                                             expenses,
                                                                             db.Transfers.AsNoTracking().Where(t => t.InstanceId == instanceId).ToList());


                return(View(new DetailsViewModel
                {
                    JoinUrl = joinUrl,
                    Instance = instance,
                    Users = users,
                    UserBalances = userBalances,
                    LastChanges = db.StoredEvents
                                  .AsNoTracking()
                                  .Where(e => e.InstanceId == instanceId)
                                  .OrderByDescending(e => e.TimeUtc)
                                  .Select(EventForList.Transform)
                                  .ToList()
                }));
            }
        }
예제 #9
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);
        }
        public void LocateTest(int expected, int matchesToFind)
        {
            // Arrange
            var expenseReport = @"
                1721
                979
                366
                299
                675
                1456";

            var expenses = expenseReport
                           .Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
                           .Select(int.Parse);

            var expenseCalculator = new ExpenseCalculator();

            // Act
            var multiply = expenseCalculator.Magic(expenses, matchesToFind);

            // Assert
            Assert.That(multiply, Is.EqualTo(expected));
        }
        public static void Export(IList list, int count, IList expenseList, DateTime _date, string bookingFormat, HttpResponse Response, string templatePath, SailsTrip trip, SailsAdminBasePage page)
        {
            SailsModule module = page.Module;
            // Bắt đầu thao tác export

            ExcelFile excelFile = new ExcelFile();

            excelFile.LoadXls(templatePath);

            // Số lệnh điều tua = số lượng group
            int numberOfGroup = -1;

            foreach (Booking booking in list)
            {
                if (booking.Group > numberOfGroup)
                {
                    numberOfGroup = booking.Group;
                }
            }

            foreach (ExpenseService service in expenseList)
            {
                if (service.Group > numberOfGroup)
                {
                    numberOfGroup = service.Group;
                }
            }

            if (numberOfGroup <= 0)
            {
                numberOfGroup = 1; // Tối thiểu là 1 group
            }

            #region -- sheet 0: Lệnh điều tour --
            for (int ii = 0; ii <= numberOfGroup; ii++)
            {
                // Mở sheet 0
                ExcelWorksheet originSheet = excelFile.Worksheets[0];

                int numberOfBooking = 0;
                foreach (Booking booking in list)
                {
                    if (booking.Group == ii)
                    {
                        numberOfBooking++;
                    }
                }

                if (numberOfBooking == 0 && ii == 0)
                {
                    continue;
                }

                ExcelWorksheet sheet = excelFile.Worksheets.AddCopy("LenhDieuTour" + ii, originSheet);

                #region -- Thông tin chung --

                if (expenseList != null)
                {
                    // Các thông tin chèn thêm
                    foreach (ExpenseService service in expenseList)
                    {
                        if (service.Group != ii)
                        {
                            continue;
                        }

                        switch (service.Type.Id)
                        {
                        case SailsModule.GUIDE_COST:
                            if (service.Type.IsCustomType || service.Supplier == null)
                            {
                                if (string.IsNullOrEmpty(service.Name) && service.Supplier != null)
                                {
                                    sheet.Cells["C3"].Value = service.Supplier.Name;
                                }
                                else
                                {
                                    sheet.Cells["C3"].Value = service.Name;
                                }
                                if (string.IsNullOrEmpty(service.Name) && service.Supplier != null)
                                {
                                    sheet.Cells["F3"].Value = service.Supplier.Phone;
                                }
                                else
                                {
                                    sheet.Cells["F3"].Value = service.Phone;
                                }
                            }
                            else
                            {
                                sheet.Cells["C3"].Value = service.Supplier.Name;
                                sheet.Cells["f3"].Value = service.Supplier.Phone;
                            }
                            break;

                        case SailsModule.TRANSPORT:
                            if (service.Type.IsCustomType || service.Supplier == null)
                            {
                                if (string.IsNullOrEmpty(service.Name) && service.Supplier != null)
                                {
                                    sheet.Cells["C4"].Value = service.Supplier.Name;
                                }
                                else
                                {
                                    sheet.Cells["C4"].Value = service.Name;
                                }
                                if (string.IsNullOrEmpty(service.Name) && service.Supplier != null)
                                {
                                    sheet.Cells["F4"].Value = service.Supplier.Phone;
                                }
                                else
                                {
                                    sheet.Cells["F4"].Value = service.Phone;
                                }
                            }
                            else
                            {
                                sheet.Cells["C4"].Value = service.Supplier.Name;
                                sheet.Cells["f4"].Value = service.Supplier.Phone;
                            }
                            break;

                        case SailsModule.HOTEL:
                            if (service.Supplier != null)
                            {
                                sheet.Cells["C7"].Value = service.Supplier.Name;
                            }
                            else
                            {
                                sheet.Cells["C7"].Value = service.Name;
                            }
                            break;
                        }
                    }
                }

                sheet.Cells["D1"].Value = _date;

                // Tính tổng pax
                int adult = 0;
                int child = 0;
                int baby  = 0;

                int pAdult = 0;
                int pChild = 0;
                int pBaby  = 0;

                foreach (Booking booking in list)
                {
                    if (booking.StartDate == _date && booking.Group == ii)
                    {
                        adult += booking.Adult;
                        child += booking.Child;
                        baby  += booking.Baby;
                    }
                    else if (booking.Group == ii)
                    {
                        pAdult += booking.Adult;
                        pChild += booking.Child;
                        pBaby  += booking.Baby;
                    }
                }

                int pax = adult + child + pAdult + pChild;

                sheet.Cells["C5"].Value  = page.UserIdentity.FullName;
                sheet.Cells["C6"].Value  = pax;
                sheet.Cells["C12"].Value = adult;
                sheet.Cells["D12"].Value = child;
                sheet.Cells["E12"].Value = baby;

                sheet.Cells["C18"].Value = pAdult;
                sheet.Cells["D18"].Value = pChild;
                sheet.Cells["E18"].Value = pBaby;

                #endregion

                #region -- Sao chép các dòng --

                // Sao chép dòng đầu theo số lượng booking
                // Dòng đầu tiên là dòng 11
                const int firstrow = 10;

                // Đếm số book trong ngày
                int curr = 0;
                foreach (Booking booking in list)
                {
                    if (booking.StartDate == _date && booking.Group == ii)
                    {
                        curr += 1;
                    }
                }

                sheet.Rows[16].InsertCopy(count - curr - 1, sheet.Rows[firstrow]);
                if (curr > 0)
                {
                    sheet.Rows[firstrow].InsertCopy(curr - 1, sheet.Rows[firstrow]);
                }
                int firstProw = 16 + curr;

                #endregion

                #region -- Thông tin từng booking --

                // Ghi vào file excel theo từng dòng
                int crow  = firstrow;
                int cProw = firstProw - 1;
                foreach (Booking booking in list)
                {
                    if (booking.Group != ii)
                    {
                        continue;
                    }
                    sheet.Cells["D2"].Value = string.Format("{0}{1:ddMMyy}-{2:00}", booking.Trip.TripCode, booking.StartDate, booking.Group);
                    int current;
                    int index;
                    if (booking.StartDate != _date)
                    {
                        // Dòng previous hiện tại
                        current = cProw;
                        // Index = cột previous hiện tại - previous đầu tiên
                        index = cProw - firstProw + 2;
                        cProw++;
                    }
                    else
                    {
                        current = crow;
                        index   = crow - firstrow + 1;
                        crow++;
                    }
                    sheet.Cells[current, 0].Value = index; // Cột index
                    string name = booking.CustomerName.Replace("<br/>", "\n");
                    if (name.Length > 0)
                    {
                        name = name.Remove(name.Length - 1);
                    }
                    sheet.Cells[current, 1].Value = name;                   // Cột name
                    sheet.Cells[current, 2].Value = booking.Adult;          // Cột adult
                    sheet.Cells[current, 3].Value = booking.Child;          // Cột child
                    sheet.Cells[current, 4].Value = booking.Baby;           // Cột baby
                    sheet.Cells[current, 5].Value = booking.Trip.TripCode;  // Cột trip code
                    sheet.Cells[current, 6].Value = booking.PickupAddress;  // Cột pickup address
                    sheet.Cells[current, 7].Value = booking.SpecialRequest; // Cột special request

                    sheet.Cells[current, 9].Style.Borders.SetBorders(MultipleBorders.Outside, System.Drawing.Color.Black, LineStyle.Thin);

                    if (booking.Agency != null)
                    {
                        sheet.Cells[current, 8].Value = booking.Agency.Name; // Cột agency

                        if (!string.IsNullOrEmpty(booking.AgencyCode))
                        {
                            sheet.Cells[current, 9].Value = booking.AgencyCode;
                            // Chỉ hiển thị nếu có agency (cột TA COde)
                        }
                        else
                        {
                            if (booking.CustomBookingId > 0)
                            {
                                sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.CustomBookingId);
                            }
                            else
                            {
                                sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.Id);
                            }
                        }
                    }
                    else
                    {
                        sheet.Cells[current, 8].Value = SailsModule.NOAGENCY; // Hiển thị oriental nếu ko có agency

                        if (booking.CustomBookingId > 0)
                        {
                            sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.CustomBookingId);
                        }
                        else
                        {
                            sheet.Cells[current, 9].Value = string.Format(bookingFormat, booking.Id);
                        }
                    }

                    if (booking.PickupTime != null)
                    {
                        sheet.Cells[current, 10].Value = booking.PickupTime.Value.ToString("HH:mm");
                    }

                    if (booking.SeeoffTime != null)
                    {
                        sheet.Cells[current, 11].Value = booking.SeeoffTime.Value.ToString("HH:mm");
                    }

                    if (trip.Name.ToLower() != "airport transfer")
                    {
                        sheet.Columns[11].Delete();
                    }

                    if (trip.Name.ToLower() != "airport transfer")
                    {
                        sheet.Columns[10].Delete();
                    }
                }


                #endregion

                // Mở sheet 1
                originSheet = excelFile.Worksheets[1];
                ExcelWorksheet budget = excelFile.Worksheets.AddCopy("Budget" + ii, originSheet);

                budget.Cells["C3"].Value = sheet.Cells["C3"].Value;
                budget.Cells["C4"].Value = sheet.Cells["C4"].Value;
                budget.Cells["A1"].Value = sheet.Cells["D1"].Value;
                budget.Cells["C5"].Value = page.UserIdentity.FullName;
                budget.Cells["C6"].Value = sheet.Cells["C6"].Value;

                budget.Cells["A1"].Value = string.Format("{0}{1:ddMMyyyy}", trip.TripCode, _date);

                // Các chi phí xuất ra bao gồm chi phí theo ngày và chi phí theo khách
                ExpenseCalculator calculator = new ExpenseCalculator(module, true);
                SailExpense       expense    = module.ExpenseGetByDate(trip, _date);
                IList             expenses   = module.ExpenseServiceGet(trip, _date, _date, null, null, null, null, false, null, 0, "");


                CostingTable cost      = calculator.GetCurrentTable(_date, trip, TripOption.Option1);
                IList        costTypes = new ArrayList();
                foreach (KeyValuePair <CostType, double> entry in module.CostTypeGetAutoDailyBase())
                {
                    costTypes.Add(entry.Key);
                }
                Dictionary <CostType, Costing> unitPrices = cost.GetCostMap(costTypes);


                const int first = 8;
                curr = first;

                foreach (ExpenseService entry in expenses)
                {
                    if (entry.Group != ii)
                    {
                        continue;
                    }

                    if (entry.Type.IsPayNow)
                    {
                        if (entry.Type.IsDailyInput)// Nếu là chi phí nhập tay
                        {
                            if (entry.Cost == 0)
                            {
                                continue;
                            }
                            budget.Rows[curr].InsertCopy(1, budget.Rows[curr]);
                            budget.Cells[curr, 0].Value = curr - first + 1;
                            budget.Cells[curr, 1].Value = _date;
                            if (entry.Type.Name.ToLower().Contains("others"))
                            {
                                budget.Cells[curr, 2].Value = entry.Name;
                            }
                            else
                            {
                                budget.Cells[curr, 2].Value = entry.Type.Name;
                            }
                            budget.Cells[curr, 3].Value = entry.Cost; // chi phí dành cho cả đoàn
                            budget.Cells[curr, 4].Value = entry.Cost;
                            curr++;
                        }
                        else if (!entry.Type.IsMonthly && !entry.Type.IsYearly)
                        {
                            double value = unitPrices[entry.Type].Adult * adult;

                            if (value > 0)
                            {
                                budget.Rows[curr].InsertCopy(1, budget.Rows[curr]);
                                budget.Cells[curr, 0].Value = curr - first + 1;
                                budget.Cells[curr, 1].Value = _date;
                                budget.Cells[curr, 2].Value = entry.Type.Name + " (adult)";
                                budget.Cells[curr, 3].Value = unitPrices[entry.Type].Adult; // giá adult
                                budget.Cells[curr, 4].Value = value;
                                curr++;
                            }

                            value = unitPrices[entry.Type].Child * child;

                            if (value > 0)
                            {
                                budget.Rows[curr].InsertCopy(1, budget.Rows[curr]);
                                budget.Cells[curr, 0].Value = curr - first + 1;
                                budget.Cells[curr, 1].Value = _date;
                                budget.Cells[curr, 2].Value = entry.Type.Name + " (child)";
                                budget.Cells[curr, 3].Value = unitPrices[entry.Type].Child; // giá adult
                                budget.Cells[curr, 4].Value = value;
                                curr++;
                            }

                            value = unitPrices[entry.Type].Baby * baby;

                            if (value > 0)
                            {
                                budget.Rows[curr].InsertCopy(1, budget.Rows[curr]);
                                budget.Cells[curr, 0].Value = curr - first + 1;
                                budget.Cells[curr, 1].Value = _date;
                                budget.Cells[curr, 2].Value = entry.Type.Name + " (baby)";
                                budget.Cells[curr, 3].Value = unitPrices[entry.Type].Baby; // giá adult
                                budget.Cells[curr, 4].Value = value;
                                curr++;
                            }
                        }
                    }
                }
            }

            #endregion

            #region -- sheet 1:
            //if (excelFile.Worksheets.Count == 1)
            //{
            //    goto end;
            //}
            //ExcelWorksheet budget = excelFile.Worksheets[1];
            #endregion

end:
            #region -- Trả dữ liệu về cho người dùng --

            Response.Clear();
            Response.Buffer      = true;
            Response.ContentType = "application/vnd.ms-excel";
            Response.AppendHeader("content-disposition",
                                  "attachment; filename=" + string.Format("Lenhdieutour{0:dd_MMM}.xls", _date));

            MemoryStream m = new MemoryStream();

            excelFile.SaveXls(m);

            Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();

            m.Close();
            Response.End();

            #endregion
        }
예제 #12
0
 public void Setup()
 {
     expenseCalculator = new ExpenseCalculator();
 }
예제 #13
0
        public void TestOneFreeLoader()
        {
            ExpenseCalculator calculator = new ExpenseCalculator();

            // One Free Loader
            // $300.60 Total Expenses
            Person Jimmy = new Person("Jimmy", new List <double>()
            {
                100, 120.60, 50, 30
            });

            // $0 Total Expenses
            Person Bob = new Person("Bob");

            // $300.60 Total Expenses
            Person Sarah = new Person("Sarah", new List <double>()
            {
                300.60
            });

            ObservableCollection <Person> people_ = new ObservableCollection <Person>()
            {
                Jimmy,
                Bob,
                Sarah
            };

            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(100.2, Jimmy.TotalOwed);
            Assert.AreEqual(-200.4, Bob.TotalOwed);
            Assert.AreEqual(100.2, Sarah.TotalOwed);
            Assert.AreEqual("Bob owes Jimmy $100.2\nBob owes Sarah $100.2\n", calculator.PrescribePayments(people_));

            // Test that order doesn't matter
            people_ = new ObservableCollection <Person>()
            {
                Bob,
                Jimmy,
                Sarah
            };
            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(100.2, Jimmy.TotalOwed);
            Assert.AreEqual(-200.4, Bob.TotalOwed);
            Assert.AreEqual(100.2, Sarah.TotalOwed);
            Assert.AreEqual("Bob owes Jimmy $100.2\nBob owes Sarah $100.2\n", calculator.PrescribePayments(people_));


            // Test that order doesn't matter
            people_ = new ObservableCollection <Person>()
            {
                Sarah,
                Jimmy,
                Bob
            };
            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(100.2, Jimmy.TotalOwed);
            Assert.AreEqual(-200.4, Bob.TotalOwed);
            Assert.AreEqual(100.2, Sarah.TotalOwed);
            Assert.AreEqual("Bob owes Sarah $100.2\nBob owes Jimmy $100.2\n", calculator.PrescribePayments(people_));
        }
예제 #14
0
        public void TestNoDebts()
        {
            ExpenseCalculator calculator = new ExpenseCalculator();

            // One Free Loader
            // $300 Total Expenses
            Person Jimmy = new Person("Jimmy", new List <double>()
            {
                100, 120, 50, 30
            });

            // $300 Total Expenses
            Person Bob = new Person("Bob", new List <double>()
            {
                300
            });

            // $300 Total Expenses
            Person Sarah = new Person("Sarah", new List <double>()
            {
                300
            });

            ObservableCollection <Person> people_ = new ObservableCollection <Person>()
            {
                Jimmy,
                Bob,
                Sarah
            };

            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(0, Jimmy.TotalOwed);
            Assert.AreEqual(0, Bob.TotalOwed);
            Assert.AreEqual(0, Sarah.TotalOwed);
            Assert.AreEqual("", calculator.PrescribePayments(people_));

            // $0 Total Expenses
            Person j = new Person("j", new List <double>()
            {
                0
            });

            // $0 Total Expenses
            Person b = new Person("b", new List <double>()
            {
                0
            });

            // $0 Total Expenses
            Person s = new Person("s", new List <double>()
            {
                0
            });

            people_ = new ObservableCollection <Person>()
            {
                j,
                b,
                s
            };
            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(0, j.TotalOwed);
            Assert.AreEqual(0, b.TotalOwed);
            Assert.AreEqual(0, s.TotalOwed);
            Assert.AreEqual("", calculator.PrescribePayments(people_));
        }
예제 #15
0
        public void TestOneSidedDebt()
        {
            ExpenseCalculator calculator = new ExpenseCalculator();

            // Base Cases
            // 2 people, test onesided debt
            // $300 Total Expenses
            Person Jimmy = new Person("Jimmy", new List <double>()
            {
                100, 120, 50, 30
            });
            // $0 Total Expenses
            Person Bob = new Person("Bob");

            ObservableCollection <Person> people_ = new ObservableCollection <Person>()
            {
                Jimmy,
                Bob
            };

            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(150, Jimmy.TotalOwed);
            Assert.AreEqual(-150, Bob.TotalOwed);
            Assert.AreEqual("Bob owes Jimmy $150\n", calculator.PrescribePayments(people_));

            // 3 people, one sided debt
            // $0 Total Expenses
            Person Sarah = new Person("Sarah");

            people_ = new ObservableCollection <Person>()
            {
                Jimmy,
                Bob,
                Sarah
            };
            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(200, Jimmy.TotalOwed);
            Assert.AreEqual(-100, Bob.TotalOwed);
            Assert.AreEqual(-100, Sarah.TotalOwed);
            Assert.AreEqual("Bob owes Jimmy $100\nSarah owes Jimmy $100\n", calculator.PrescribePayments(people_));

            // Test that order doesn't matter
            people_ = new ObservableCollection <Person>()
            {
                Bob,
                Jimmy,
                Sarah
            };
            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(200, Jimmy.TotalOwed);
            Assert.AreEqual(-100, Bob.TotalOwed);
            Assert.AreEqual(-100, Sarah.TotalOwed);
            Assert.AreEqual("Bob owes Jimmy $100\nSarah owes Jimmy $100\n", calculator.PrescribePayments(people_));


            // Test that order doesn't matter
            people_ = new ObservableCollection <Person>()
            {
                Bob,
                Sarah,
                Jimmy
            };
            calculator.CalculateAllDebts(people_);

            Assert.AreEqual(200, Jimmy.TotalOwed);
            Assert.AreEqual(-100, Bob.TotalOwed);
            Assert.AreEqual(-100, Sarah.TotalOwed);
            Assert.AreEqual("Bob owes Jimmy $100\nSarah owes Jimmy $100\n", calculator.PrescribePayments(people_));
        }