Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void Rate_on_large_negative_balance()
[Task(2)]
public void Interest_on_negative_balance()
{
Assert.Equal(-321.3m, SavingsAccount.Interest(-10000.0m));
Assert.Equal(-321.3m, SavingsAccount.Interest(-10000.0m), precision: 4);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the precision by 1 here as there is just a single decimal point being checked?

If so, the other tests also need to be updated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a copy and paste error from Interest_on_large_balance that I forgot to update. That should have been a precision of 1.

For Interest_on_negative_balance, a precision of 1 would compare -321.3 to -321.3.

Expected: -321.3
Actual:   -321.3000059127807617187500000

For Interest_on_medium_balance, a precision of 3 would compare 81.050 vs 81.050.

Expected: 81.0498379
Actual:   81.04984047491550445556640625

For Interest_on_large_balance, a precision of 4 would compare 856.3698 vs 856.3698.

Expected: 856.3698
Actual:   856.3697670021057128906250000

So for that set, I think the precisions are reasonable.

}

[Fact]
Expand All @@ -111,14 +111,14 @@ public void Interest_on_small_balance()
[Task(2)]
public void Interest_on_medium_balance()
{
Assert.Equal(81.0498379m, SavingsAccount.Interest(4999.99m));
Assert.Equal(81.0498379m, SavingsAccount.Interest(4999.99m), precision: 3);
}

[Fact]
[Task(2)]
public void Interest_on_large_balance()
{
Assert.Equal(856.3698m, SavingsAccount.Interest(34600.80m));
Assert.Equal(856.3698m, SavingsAccount.Interest(34600.80m), precision: 4);
}

[Fact]
Expand All @@ -139,35 +139,39 @@ public void Annual_balance_update_for_small_positive_start_balance()
[Task(3)]
public void Annual_balance_update_for_average_positive_start_balance()
{
Assert.Equal(1016.210000m, SavingsAccount.AnnualBalanceUpdate(1_000.0m));
Assert.Equal(1016.210000m, SavingsAccount.AnnualBalanceUpdate(1_000.0m), precision: 5);
}

[Fact]
[Task(3)]
public void Annual_balance_update_for_large_positive_start_balance()
{
Assert.Equal(1016.210101621m, SavingsAccount.AnnualBalanceUpdate(1_000.0001m));
Assert.Equal(1016.210101621m, SavingsAccount.AnnualBalanceUpdate(1_000.0001m), precision: 5);
}

[Fact]
[Task(3)]
public void Annual_balance_update_for_huge_positive_start_balance()
{
Assert.Equal(920352587.26744292868451875m, SavingsAccount.AnnualBalanceUpdate(898124017.826243404425m));
const decimal balance = 898124017.826243404425m;
const decimal expected = 920352587.26744292868451875m;
const decimal tolerance = balance * 0.000000001m;

Assert.InRange(SavingsAccount.AnnualBalanceUpdate(balance), expected - tolerance, expected + tolerance);
}

[Fact]
[Task(3)]
public void Annual_balance_update_for_small_negative_start_balance()
{
Assert.Equal(-0.12695199m, SavingsAccount.AnnualBalanceUpdate(-0.123m));
Assert.Equal(-0.12695199m, SavingsAccount.AnnualBalanceUpdate(-0.123m), precision: 8);
}

[Fact]
[Task(3)]
public void Annual_balance_update_for_large_negative_start_balance()
{
Assert.Equal(-157878.97174203m, SavingsAccount.AnnualBalanceUpdate(-152964.231m));
Assert.Equal(-157878.97174203m, SavingsAccount.AnnualBalanceUpdate(-152964.231m), precision: 3);
}

[Fact]
Expand Down
Loading