Seed: price calculator with discount tests
Mini project for agentd live testing: three of the five tests fail on main. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
21
src/Prices/PriceCalculator.cs
Normal file
21
src/Prices/PriceCalculator.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace Prices;
|
||||
|
||||
/// <summary>Turns a list price into what the customer actually pays.</summary>
|
||||
public static class PriceCalculator
|
||||
{
|
||||
/// <summary>Applies a percentage discount to a price, e.g. 25 for a quarter off.</summary>
|
||||
public static decimal ApplyDiscount(decimal price, decimal discountPercent)
|
||||
{
|
||||
if (price < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(price), "A price cannot be negative.");
|
||||
}
|
||||
|
||||
if (discountPercent is < 0 or > 100)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(discountPercent), "A discount is between 0 and 100 percent.");
|
||||
}
|
||||
|
||||
return price - discountPercent;
|
||||
}
|
||||
}
|
||||
9
src/Prices/Prices.csproj
Normal file
9
src/Prices/Prices.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user