def test_next(self): """ Test next_year to confirm that properties are advanced. """ initial_year = 2017 gross_income = 100 tax = Tax({initial_year: { 0: 0, 200: 0.5, 1000: 0.75 }}, inflation_adjust={ 2017: 1, 2018: 1, 2019: 1, 2020: 1 }, personal_deduction={2017: 0}) person = Person(initial_year, 'Name', 2000, raise_rate=2.0, retirement_date=self.retirement_date, gross_income=gross_income, tax_treatment=tax) self.assertEqual(person.gross_income, gross_income) self.assertEqual(person.net_income, Money(100)) self.assertEqual(person.this_year, initial_year) person.next_year() # 200% raise - gross income is now $300 self.assertEqual(person.gross_income, Money(300)) self.assertEqual(person.net_income, Money(250)) self.assertEqual(person.this_year, initial_year + 1)
def test_init_inputs(self): """ Test Person.__init__ with inputs arg. """ initial_year = 2017 gross_income = 500 inputs = { 'gross_income': { initial_year: 1000, initial_year + 2: 0 } } person = Person( initial_year, 'Name', 2000, retirement_date=2065, gross_income=gross_income, raise_rate=1, inputs=inputs) # We've gross income for the first and third years; the second # year should be set programmatically based on a 100% raise. self.assertEqual(person.gross_income, 1000) person.next_year() self.assertEqual(person.gross_income, 2000) person.next_year() self.assertEqual(person.gross_income, 0)
def test_decimal(self): """ Test compatibility with Decimal inputs. """ # Convert values to Decimal-based self.setUp_decimal() # The test itself is based on test_next initial_year = 2017 gross_income = 100 tax = Tax( {initial_year: { Decimal(0): Decimal(0), Decimal(200): Decimal(0.5), Decimal(1000): Decimal(0.75)}}, inflation_adjust={ 2017: Decimal(1), 2018: Decimal(1), 2019: Decimal(1), 2020: Decimal(1)}, personal_deduction={2017: Decimal(0)}) person = Person( initial_year, 'Name', 2000, raise_rate=Decimal(2.0), retirement_date=self.retirement_date, gross_income=gross_income, tax_treatment=tax) # In the first year: $100 gross income, $100 taxable income, # $100 net income. self.assertEqual(person.gross_income, gross_income) self.assertEqual(person.net_income, Decimal(100)) self.assertEqual(person.this_year, initial_year) self.assertEqual(person.taxable_income, Decimal(100)) person.next_year() # 200% raise # In the second year: $300 gross income, $300 taxable income, # $250 net income (as income over $200 is taxed at 50%) self.assertEqual(person.gross_income, Decimal(300)) self.assertEqual(person.net_income, Decimal(250)) self.assertEqual(person.this_year, initial_year + 1) self.assertEqual(person.taxable_income, Decimal(300))