-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnitTests.cs
More file actions
69 lines (59 loc) · 1.71 KB
/
UnitTests.cs
File metadata and controls
69 lines (59 loc) · 1.71 KB
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
using System;
using System.Collections.Generic;
using NUnit.Framework;
[assembly: IndexesStartAtOne]
namespace IndexesStartAt.Tests
{
public static class UnitTests
{
private static readonly int[] Values = { 4, 8, 15, 16, 23, 42 };
[Test]
public static void ShouldIndexWithConstants()
{
Assert.AreEqual(Values[1], 4);
}
[Test]
public static void ShouldThrowWhenTakingZerothArgument()
{
Assert.Throws<IndexOutOfRangeException>(() =>
{
int _ = Values[0];
});
}
[Test]
public static void ShouldIndexWithVariables()
{
for (int i = 1; i <= Values.Length; i++)
{
Assert.DoesNotThrow(() =>
{
int _ = Values[i];
});
}
}
[Test]
public static void ShouldIndexMatrices()
{
int[,] m =
{
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
Assert.AreEqual(m[1, 1], 1);
Assert.AreEqual(m[3, 3], 9);
}
[Test]
public static void ShouldNotChangeNonIntegers()
{
string GetKey() => "Test2";
var test = new Dictionary<string, string>
{
{ "Test1", "It works." },
{ "Test2", "It works with non-literals as well." }
};
Assert.AreEqual(test["Test1"], "It works.");
Assert.AreEqual(test[GetKey()], "It works with non-literals as well.");
}
}
}