-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestClass.cs
97 lines (90 loc) · 3.14 KB
/
TestClass.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using NuGet.Frameworks;
namespace TDD_Kata
{
[TestFixture]
internal class TestClass
{
[Test]
public void TakesVoidReturnsZero()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(0, stringCalculator.Add(""));
}
[Test]
public void TakesOneReturnsThis()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(1, stringCalculator.Add("1"));
}
[Test]
public void TakesTwoReturnsSum()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(4, stringCalculator.Add("1,3"));
}
[Test]
public void TakesWithNewlineAndIgnoresIt()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(6, stringCalculator.Add("1\n2,3"));
}
[Test]
public void TakesDelimiterAndIgnoresIt()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(3, stringCalculator.Add("//;\n1;2"));
}
[Test]
public void TakesNegativeReturnsException()
{
StringCalculator stringCalculator = new();
ArgumentException ex = Assert.Throws<ArgumentException>(delegate { stringCalculator.Add("//;\n1;-2"); });
Assert.That(ex.Message, Is.EqualTo("negatives not allowed -2"));
}
[Test]
public void TakesNegativeReturnsExceptionWithPassedNegatives()
{
StringCalculator stringCalculator = new();
ArgumentException ex = Assert.Throws<ArgumentException>(delegate { stringCalculator.Add("//;\n1;-2///-54;,-25,15"); });
Assert.That(ex.Message, Is.EqualTo("negatives not allowed -2, -54, -25"));
}
[Test]
public void TakesSeveralCallsAndReturnsHowManyCalls()
{
StringCalculator stringCalculator = new();
stringCalculator.AddOccured += stringCalculator.AddCounter;
stringCalculator.Add("11,2");
stringCalculator.Add("11,2");
stringCalculator.Add("11,2");
Assert.AreEqual(3, stringCalculator.countAdds);
}
[Test]
public void TakesSeveralCallsAndReturnsHowManyCallsUsingEvent()
{
StringCalculator stringCalculator = new();
stringCalculator.AddOccured += stringCalculator.AddCounter;
stringCalculator.Add("11,2");
stringCalculator.Add("11,2");
stringCalculator.Add("11,2");
Assert.AreEqual(3, stringCalculator.countAdds);
}
[Test]
public void IgnoresMoreThan1000()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(1002, stringCalculator.Add("//;\n1;2, 2000, 999"));
}
[Test]
public void TakesDelimiterReturnsSum()
{
StringCalculator stringCalculator = new();
Assert.AreEqual(6, stringCalculator.Add("//[**][%%]\n1**2%%3"));
}
}
}