diff options
| -rw-r--r-- | geldschieberbot.py | 7 | ||||
| -rw-r--r-- | tanken.py | 13 | ||||
| -rwxr-xr-x | test.py | 5 |
3 files changed, 17 insertions, 8 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py index 3ad9960..93766fe 100644 --- a/geldschieberbot.py +++ b/geldschieberbot.py @@ -269,6 +269,7 @@ def summary(sender, args, msg): # pylint: disable=unused-argument cmds["sum"] = summary cmds["summary"] = summary + def full_summary(sender, args, msg): # pylint: disable=unused-argument if len(args) == 1: return create_total_summary(), None @@ -516,7 +517,7 @@ def cars(sender, args, msg): del available_cars[car] remove_from_balance(car) return f'removed "{car}" from the available cars', None - + # pay bill if args[1] in ["pay"]: if len(args) < 4: @@ -584,7 +585,7 @@ def cars(sender, args, msg): changes[sender_name].append(change) return output, None - + return None, f'unknown car subcommand "{args[1]}".' @@ -847,6 +848,7 @@ def cancel(sender, args, msg): cmds["cancel"] = cancel + def thanks(sender, args, msg): sender_name = num2name.get(sender, sender) msg = f'You are welcome. It is a pleasure to work with you, {sender_name}.' @@ -856,6 +858,7 @@ def thanks(sender, args, msg): return msg, None + cmds["thanks"] = thanks @@ -1,5 +1,6 @@ #!/bin/env python3 + # cost should be given in cents def tanken(drives, cost, service_charge=0): passengers = {} @@ -19,17 +20,19 @@ def tanken(drives, cost, service_charge=0): # collect distances per passenger for p in d[1:]: if p not in passengers: - passengers[p] = {"distance": d[0], - "cost": 0, - "service_charge": 0} + passengers[p] = { + "distance": d[0], + "cost": 0, + "service_charge": 0 + } else: passengers[p]["distance"] += d[0] - + # calculate cost per kilometer if distance <= 0: return None, "Driven distance must be greater than 0!" - c = cost/distance + c = cost / distance for d in drives: # calculate cost per drive split among passengers @@ -1120,6 +1120,7 @@ fiat: \tBalance: -3.00""" self.assertEqual(res.stdout, msg) + class TestThanks(unittest.TestCase): def test_thanks(self): res = run_bot(self, num[alice], "!thanks") @@ -1131,7 +1132,9 @@ class TestThanks(unittest.TestCase): res = run_bot(self, num[alice], "!thanks pussy") self.assertEqual( res.stdout, - f"You are welcome. It is a pleasure to work with you, {alice}.\nBut don't call me pussy.") + f"You are welcome. It is a pleasure to work with you, {alice}.\nBut don't call me pussy." + ) + if __name__ == '__main__': unittest.main() |
