58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using Xunit;
|
|
|
|
namespace Prices.Tests;
|
|
|
|
public sealed class PriceCalculatorTests
|
|
{
|
|
[Fact]
|
|
public void No_discount_keeps_the_price()
|
|
{
|
|
Assert.Equal(100m, PriceCalculator.ApplyDiscount(100m, 0m));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_full_discount_makes_it_free()
|
|
{
|
|
Assert.Equal(0m, PriceCalculator.ApplyDiscount(200m, 100m));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_quarter_off_200_is_150()
|
|
{
|
|
Assert.Equal(150m, PriceCalculator.ApplyDiscount(200m, 25m));
|
|
}
|
|
|
|
[Fact]
|
|
public void Half_off_80_is_40()
|
|
{
|
|
Assert.Equal(40m, PriceCalculator.ApplyDiscount(80m, 50m));
|
|
}
|
|
|
|
[Fact]
|
|
public void A_discount_above_100_percent_is_refused()
|
|
{
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => PriceCalculator.ApplyDiscount(100m, 101m));
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyDiscount_99_90_with_10_percent_rounds_to_89_90()
|
|
{
|
|
// 99.90 * (1 - 10/100) = 89.91 → rounded to nearest 0.05 = 89.90
|
|
Assert.Equal(89.90m, PriceCalculator.ApplyDiscount(99.90m, 10m));
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyDiscount_10_with_33_percent_rounds_correctly()
|
|
{
|
|
// 10 * (1 - 33/100) = 6.70 → 6.70 is already a multiple of 0.05
|
|
Assert.Equal(6.70m, PriceCalculator.ApplyDiscount(10m, 33m));
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyDiscount_5_55_with_10_percent_rounds_to_5_00()
|
|
{
|
|
// 5.55 * 0.9 = 4.995 → rounded to nearest 0.05 = 5.00
|
|
Assert.Equal(5.00m, PriceCalculator.ApplyDiscount(5.55m, 10m));
|
|
}
|
|
}
|