Eureka/demo/fixture/test_tabsplit.py

28 lines
739 B
Python
Raw Normal View History

import unittest
from tabsplit import split_cents
class SplitCents(unittest.TestCase):
def test_even_split(self):
self.assertEqual(split_cents(90, 3), [30, 30, 30])
def test_remainder_goes_somewhere(self):
self.assertEqual(sum(split_cents(100, 3)), 100)
def test_zero_total(self):
self.assertEqual(split_cents(0, 4), [0, 0, 0, 0])
def test_single_payer_pays_everything(self):
self.assertEqual(split_cents(1234, 1), [1234])
def test_one_share_per_payer(self):
self.assertEqual(len(split_cents(100, 3)), 3)
def test_no_payers_is_an_error(self):
with self.assertRaises(ValueError):
split_cents(100, 0)
if __name__ == "__main__":
unittest.main()