-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathledger_test.py
173 lines (158 loc) · 5.94 KB
/
ledger_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/ledger/canonical-data.json
# File last updated on 2023-12-27
import unittest
from ledger import (
format_entries,
create_entry,
)
class LedgerTest(unittest.TestCase):
maxDiff = 5000
def test_empty_ledger(self):
currency = "USD"
locale = "en_US"
entries = []
expected = "\n".join(
[
"Date | Description | Change ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_one_entry(self):
currency = "USD"
locale = "en_US"
entries = [
create_entry("2015-01-01", "Buy present", -1000),
]
expected = "\n".join(
[
"Date | Description | Change ",
"01/01/2015 | Buy present | ($10.00)",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_credit_and_debit(self):
currency = "USD"
locale = "en_US"
entries = [
create_entry("2015-01-02", "Get present", 1000),
create_entry("2015-01-01", "Buy present", -1000),
]
expected = "\n".join(
[
"Date | Description | Change ",
"01/01/2015 | Buy present | ($10.00)",
"01/02/2015 | Get present | $10.00 ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_final_order_tie_breaker_is_change(self):
currency = "USD"
locale = "en_US"
entries = [
create_entry("2015-01-01", "Something", 0),
create_entry("2015-01-01", "Something", -1),
create_entry("2015-01-01", "Something", 1),
]
expected = "\n".join(
[
"Date | Description | Change ",
"01/01/2015 | Something | ($0.01)",
"01/01/2015 | Something | $0.00 ",
"01/01/2015 | Something | $0.01 ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_overlong_description_is_truncated(self):
currency = "USD"
locale = "en_US"
entries = [
create_entry("2015-01-01", "Freude schoner Gotterfunken", -123456),
]
expected = "\n".join(
[
"Date | Description | Change ",
"01/01/2015 | Freude schoner Gotterf... | ($1,234.56)",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_euros(self):
currency = "EUR"
locale = "en_US"
entries = [
create_entry("2015-01-01", "Buy present", -1000),
]
expected = "\n".join(
[
"Date | Description | Change ",
"01/01/2015 | Buy present | (€10.00)",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_dutch_locale(self):
currency = "USD"
locale = "nl_NL"
entries = [
create_entry("2015-03-12", "Buy present", 123456),
]
expected = "\n".join(
[
"Datum | Omschrijving | Verandering ",
"12-03-2015 | Buy present | $ 1.234,56 ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_dutch_locale_and_euros(self):
currency = "EUR"
locale = "nl_NL"
entries = [
create_entry("2015-03-12", "Buy present", 123456),
]
expected = "\n".join(
[
"Datum | Omschrijving | Verandering ",
"12-03-2015 | Buy present | € 1.234,56 ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_dutch_negative_number_with_3_digits_before_decimal_point(self):
currency = "USD"
locale = "nl_NL"
entries = [
create_entry("2015-03-12", "Buy present", -12345),
]
expected = "\n".join(
[
"Datum | Omschrijving | Verandering ",
"12-03-2015 | Buy present | $ -123,45 ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_american_negative_number_with_3_digits_before_decimal_point(self):
currency = "USD"
locale = "en_US"
entries = [
create_entry("2015-03-12", "Buy present", -12345),
]
expected = "\n".join(
[
"Date | Description | Change ",
"03/12/2015 | Buy present | ($123.45)",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)
def test_multiple_entries_on_same_date_ordered_by_description(self):
currency = "USD"
locale = "en_US"
entries = [
create_entry("2015-01-01", "Get present", 1000),
create_entry("2015-01-01", "Buy present", -1000),
]
expected = "\n".join(
[
"Date | Description | Change ",
"01/01/2015 | Buy present | ($10.00)",
"01/01/2015 | Get present | $10.00 ",
]
)
self.assertEqual(format_entries(currency, locale, entries), expected)