Skip to content

Commit ba80fa8

Browse files
author
n.bitounis
committed
Added a test to validate implementation against documented known values and removed static from test methods.
1 parent beaa3a6 commit ba80fa8

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

UnitTest/AlgorithmsTests/CatalanNumbersTest.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace UnitTest.AlgorithmsTests
88
public class CatalanNumbersTest
99
{
1010
[Fact]
11-
public static void DoTest()
11+
public void DoTest()
1212
{
1313
var list = CatalanNumbers.GetRange(0, 100);
1414
var list2 = new List<BigInteger>();
@@ -22,5 +22,48 @@ public static void DoTest()
2222
Assert.True(list[(int)i] == list2[(int)i], "Wrong calculation.");
2323
}
2424
}
25+
26+
// Values retrieved from https://oeis.org/A000108/list.
27+
[Theory]
28+
[InlineData(0, "1")]
29+
[InlineData(1, "1")]
30+
[InlineData(2, "2")]
31+
[InlineData(3, "5")]
32+
[InlineData(4, "14")]
33+
[InlineData(5, "42")]
34+
[InlineData(6, "132")]
35+
[InlineData(7, "429")]
36+
[InlineData(8, "1430")]
37+
[InlineData(9, "4862")]
38+
[InlineData(10, "16796")]
39+
[InlineData(11, "58786")]
40+
[InlineData(12, "208012")]
41+
[InlineData(13, "742900")]
42+
[InlineData(14, "2674440")]
43+
[InlineData(15, "9694845")]
44+
[InlineData(16, "35357670")]
45+
[InlineData(17, "129644790")]
46+
[InlineData(18, "477638700")]
47+
[InlineData(19, "1767263190")]
48+
[InlineData(20, "6564120420")]
49+
[InlineData(21, "24466267020")]
50+
[InlineData(22, "91482563640")]
51+
[InlineData(23, "343059613650")]
52+
[InlineData(24, "1289904147324")]
53+
[InlineData(25, "4861946401452")]
54+
[InlineData(26, "18367353072152")]
55+
[InlineData(27, "69533550916004")]
56+
[InlineData(28, "263747951750360")]
57+
[InlineData(29, "1002242216651368")]
58+
[InlineData(30, "3814986502092304")]
59+
public void ManuallyVerifyCatalanNumber(uint rank, string value)
60+
{
61+
// This conversion seems to be necessary because as of this
62+
// writing xunit doesn't behave well with BigInteger inline
63+
// data values.
64+
var bigint = BigInteger.Parse(value);
65+
66+
Assert.True(CatalanNumbers.GetNumber(rank) == bigint);
67+
}
2568
}
2669
}

0 commit comments

Comments
 (0)