This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExerciseTwo.cs
68 lines (61 loc) · 2.03 KB
/
ExerciseTwo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Linq;
using NUnit.Framework;
namespace TDDSolo
{
public class ExerciseTwo
{
public class ShoppingCart
{
private static int Total(Tuple<int, int>[] shoppingCartItems)
{
var total = shoppingCartItems.Sum(item => item.Item2 * item.Item1);
if (total > 200)
{
return total - total / 10;
}
if (total > 100)
{
return total - total * 5 / 100;
}
return total;
}
[Test]
public void ZeroItemsResultsInZeroTotal()
{
AssertCost(0, new Tuple<int, int>[] { });
}
[TestCase(0, 0, 0)]
[TestCase(0, 1, 0)]
[TestCase(1, 1, 1)]
[TestCase(2, 1, 2)]
[TestCase(2, 1, 2)]
public void SingleItemPricedCorrectly(int price, int quantity, int expectedCost)
{
AssertCost(expectedCost, new[] { new Tuple<int, int>(price, quantity) });
}
[Test]
public void TwoSameItemsPricedCorrectly()
{
AssertCost(2, new[] { new Tuple<int, int>(1, 1), new Tuple<int, int>(1, 1) });
}
[Test]
public void TwoDifferentItemsPricedCorrectly()
{
AssertCost(3, new[] { new Tuple<int, int>(2, 1), new Tuple<int, int>(1, 1) });
}
[TestCase(100, 100)]
[TestCase(101, 96)]
[TestCase(201, 181)]
public void DiscountIsApplied(int price, int expectedTotal)
{
AssertCost(expectedTotal, new[] { new Tuple<int, int>(price, 1) });
}
private static void AssertCost(int expectedCost, Tuple<int, int>[] shoppingCartItems)
{
var total = Total(shoppingCartItems);
Assert.That(total, Is.EqualTo(expectedCost));
}
}
}
}