Fixed tax calculator

This commit is contained in:
Kumi 2017-11-12 22:18:35 +01:00
parent e68fc13254
commit 64965f1ae8
2 changed files with 19 additions and 11 deletions

View file

@ -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 level in sorted(self.rates.items()):
if level[0] < income:
rate = level[1]
else:
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
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)

View file

@ -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"