Commit 64965f1a authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Fixed tax calculator

parent e68fc132
......@@ -25,19 +25,27 @@ class TaxRates:
def add_rate(self, above, rate):
self.rates[int(above)] = int(rate)
def get_rate(self, income):
rate = 0
def get_taxes(self, income):
taxes = 0
ratelist = list(self.rates.items())
for rate in range(len(ratelist)):
running = None
try:
if income > ratelist[rate + 1][0]:
running = ratelist[rate + 1][0] - ratelist[rate][0]
except:
pass
for level in sorted(self.rates.items()):
if level[0] < income:
rate = level[1]
else:
running = running or (income - ratelist[rate][0])
if running < 0:
break
return rate
taxes += running / 100 * ratelist[rate][1]
def get_taxes(self, income):
return income / 100 * self.get_rate(income)
return taxes
def get_taxes(income):
return TaxRates().get_taxes(income)
......
......@@ -2,6 +2,6 @@ from einkommenssteuer import get_taxes
def test_get_taxes():
assert get_taxes(5000) == 0
assert get_taxes(1000000) == 500000
assert get_taxes(31500) == 31500 * 42 / 100
assert get_taxes(40000) == 10080
assert get_taxes(564000) == 269880
assert "nobody needs 10 fucking tests for this"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment