Skip to content

Commit 4ef4860

Browse files
committed
added test for split amounts, started using nose
1 parent c51274a commit 4ef4860

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ python:
44
# command to install dependencies
55
install: "pip install -r setup/requirements.txt"
66
# command to run tests
7-
script: "cd test; python -m unittest ServerTest.ServerTest"
7+
script: "cd test; nosetests"

src/groupsplit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def main():
134134
rows = rows[1:]
135135
transactions = [{"date": datetime.strftime(datetime.strptime(r[date_col], "%m/%d/%y"), "%Y-%m-%dT%H:%M:%SZ"),
136136
"amount": -1 * Money(r[amount_col], local_currency),
137-
"desc": re.sub('\s+',' ', r[desc_col]})
137+
"desc": re.sub('\s+',' ', r[desc_col])}
138138
for r in rows if float(r[amount_col]) < 0]
139139
splits = []
140140
for t in transactions:

test/SplitTests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import unittest
2+
import sys
3+
from money import Money
4+
sys.path.append("../src")
5+
from groupsplit import split
6+
7+
class APIInterfaceTests(unittest.TestCase):
8+
def test_splits(self):
9+
cases = [
10+
{"amount": 1.00, "ppl": 2, "expect": (0.50, 0)},
11+
{"amount": 1.00, "ppl": 3, "expect": (0.33, 0.01)},
12+
{"amount": 12.97, "ppl": 5, "expect": (2.59, 0.02)},
13+
{"amount": 52000, "ppl": 3, "expect": (1733.33, 0.01)},
14+
]
15+
for case in cases:
16+
expect = ( Money(e, "CAD") for e in case['expect'])
17+
self.assertEqual(expect, split(Money(case['amount'], "CAD"), case['people']))

0 commit comments

Comments
 (0)