def test_shared_debt(self): """If a thing was bought for several people, they should all pay for it """ exchange_rates = {"CZK": 1} df = bills("""Jan,Ticket,1400,CZK,Matěj Petr""") r = settle(["Jan", "Petr", "Matěj"], exchange_rates, df) self.assertEqual(r, {("Petr", "Jan", 700), ("Matěj", "Jan", 700)}) df = bills("""Jan,Ticket,1500,CZK,Matěj Petr Martin""") r = settle(["Jan", "Petr", "Matěj", "Martin"], exchange_rates, df) self.assertEqual(r, { ("Petr", "Jan", 500), ("Matěj", "Jan", 500), ("Martin", "Jan", 500), }) df = bills("""Jan,Ticket,1500,CZK,AllBut Jan""") r = settle(["Jan", "Petr", "Matěj", "Martin"], exchange_rates, df) self.assertEqual(r, { ("Petr", "Jan", 500), ("Matěj", "Jan", 500), ("Martin", "Jan", 500), })
def test_allbut_shortcut(self): """Test if using AllBut instead of rest of names gives the same result. """ exchange_rates = {"CZK": 1} people = ["Jan", "Matěj", "Petr", "Martin"] df1 = bills("""Jan,Ticket,1200,CZK,Matěj Petr Martin""") df2 = bills("""Jan,Ticket,1200,CZK,AllBut Jan""") r1 = settle(people, exchange_rates, df1) r2 = settle(people, exchange_rates, df2) self.assertEqual(r1, r2)
def test_all_shortcut(self): """Test if using All instead of all the names gives the same result """ exchange_rates = {"CZK": 1} people = ["Jan", "Matěj", "Petr", "Martin"] df1 = bills("""Petr,Accomodation,395,CZK,Jan Matěj Petr Martin""") df2 = bills("""Petr,Accomodation,395,CZK,All""") r1 = settle(people, exchange_rates, df1) r2 = settle(people, exchange_rates, df2) self.assertEqual(r1, r2)
def test_one_debt(self): """Lender should get his money back.""" exchange_rates = {"CZK": 1} df = bills("John,Icecream,15,CZK,David") r = settle(["John", "David"], exchange_rates, df) self.assertEqual(r, {("David", "John", 15)})
def test_mutual_debts(self): """If a owes b and b owes a the same amount, no payments are needed.""" exchange_rates = {"CZK": 1} df = bills("""John,Icecream,20,CZK,David David,Kofola,20,CZK,John""") r = settle(["John", "David"], exchange_rates, df) self.assertEqual(r, set())
def test_circular_debts(self): """In case of circular debts of the same value, no payments are needed. """ exchange_rates = {"CZK": 1} df = bills("""John,Item,10,CZK,David David,Item,10,CZK,Martin Martin,Item,10,CZK,John""") r = settle(["John", "David", "Martin"], exchange_rates, df) self.assertEqual(r, set())
def test_circular_debts_one_bigger(self): """Only the amount owed above level of circular debts should be paid. """ exchange_rates = {"CZK": 1} df = bills("""John,Item,10,CZK,David David,Item,10,CZK,Martin Martin,Item,10,CZK,Adam Adam,Item,11,CZK,John""") r = settle(["John", "David", "Martin", "Adam"], exchange_rates, df) self.assertEqual(r, {("John", "Adam", 1)})
def test_more_currencies(self): """Test if bills in different currencies are counted right.""" exchange_rates = {"CZK": 1, "EUR": 30, "USD": 20} df = bills("""John,Lunch,100,CZK,David David,Dinner,2,EUR,John Adam,Breakfast,1,USD,John""") r = settle(["John", "David", "Adam"], exchange_rates, df) self.assertEqual(will_get("John", r), 20) self.assertEqual(will_get("David", r), -40) self.assertEqual(will_get("Adam", r), 20)