Skip to content

Commit 3883d68

Browse files
create financial module (price plus tax)and tests
1 parent 5239e71 commit 3883d68

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Algorithms.Financial;
2+
using FluentAssertions;
3+
using NUnit.Framework;
4+
5+
namespace Algorithms.Tests.Financial
6+
{
7+
[TestFixture]
8+
9+
public class PricePlusTaxTest
10+
{
11+
[Test]
12+
public void Price_Plus_Tax_Test()
13+
{
14+
PricePlusTax.Calculate(125.50m, 0.05m).Should().Be(131.775m);
15+
PricePlusTax.Calculate(125.50f, 0.05f).Should().Be(131.775f);
16+
17+
PricePlusTax.Calculate(100.0m, 0.25m).Should().Be(125.0m);
18+
PricePlusTax.Calculate(100.0f, 0.25f).Should().Be(125.0f);
19+
20+
PricePlusTax.Calculate(0, 0.25).Should().Be(0);
21+
PricePlusTax.Calculate(0.0f, 0.25f).Should().Be(0.0f);
22+
PricePlusTax.Calculate(0.0m, 0.25m).Should().Be(0.0m);
23+
}
24+
}
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Numerics;
3+
4+
namespace Algorithms.Financial
5+
{
6+
public static class PricePlusTax
7+
{
8+
public static double Calculate(double price, double taxRate)
9+
=> price * (1 + taxRate);
10+
11+
public static decimal Calculate(decimal price, decimal taxRate)
12+
=> price * (1 + taxRate);
13+
14+
public static int Calculate(int price, int taxRate)
15+
=> price * (1 + taxRate);
16+
17+
public static float Calculate(float price, float taxRate)
18+
=> price * (1 + taxRate);
19+
}
20+
}

0 commit comments

Comments
 (0)