Skip to content

Commit

Permalink
Add standard deduction to federal tax calculator.
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 committed Jul 15, 2024
1 parent d8a8d19 commit 4d8253e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/services/federal_tax_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ def call
attr_accessor :income

def calculate
bracket = FederalTaxBracket.where("bottom_range_cents <= ?", income.fractional).order(:bottom_range_cents).last
taxable_at_bracket_rate = Money.new(income - bracket.bottom_range)
bracket = FederalTaxBracket.where("bottom_range_cents <= ?", taxable_income.fractional).order(:bottom_range_cents).last
taxable_at_bracket_rate = Money.new(taxable_income - bracket.bottom_range)
rated = bracket.rate * taxable_at_bracket_rate
rated + bracket.cumulative
end

def taxable_income
# 2024 standard deduction = 13,850
@taxable_income ||= income - Money.new(13_850_00)
end
end
5 changes: 3 additions & 2 deletions spec/services/federal_tax_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

it "calculates federal tax" do
# salary_income = $50,000
# standard_deduction = $13,850
# tax_brackets = 10% on first $1,000, 15% from $1,001 to $100,000, 25% from $100,001 to $500,000

expect(service.format).to eq("$7,449.85")
expect((salary_income.rate - service).format).to eq("$42,550.15")
expect(service.format).to eq("$5,372.35")
expect((salary_income.rate - service).format).to eq("$44,627.65")
end
end

0 comments on commit 4d8253e

Please sign in to comment.