-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ByteTests.cs
134 lines (108 loc) · 3.64 KB
/
ByteTests.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Math;
namespace X10D.Tests.Math;
[TestClass]
public class ByteTests
{
[TestMethod]
public void DigitalRootShouldBeCorrect()
{
const byte value = 238;
Assert.AreEqual(4, value.DigitalRoot());
Assert.AreEqual(4, (-value).DigitalRoot());
}
[TestMethod]
public void FactorialShouldBeCorrect()
{
Assert.AreEqual(1L, ((byte)0).Factorial());
Assert.AreEqual(1L, ((byte)1).Factorial());
Assert.AreEqual(2L, ((byte)2).Factorial());
Assert.AreEqual(6L, ((byte)3).Factorial());
Assert.AreEqual(24L, ((byte)4).Factorial());
Assert.AreEqual(120L, ((byte)5).Factorial());
Assert.AreEqual(720L, ((byte)6).Factorial());
Assert.AreEqual(5040L, ((byte)7).Factorial());
Assert.AreEqual(40320L, ((byte)8).Factorial());
Assert.AreEqual(362880L, ((byte)9).Factorial());
Assert.AreEqual(3628800L, ((byte)10).Factorial());
}
[TestMethod]
public void GreatestCommonFactor_ShouldBe1_ForPrimeNumbers()
{
const byte first = 5;
const byte second = 7;
byte multiple = first.GreatestCommonFactor(second);
Assert.AreEqual(1, multiple);
}
[TestMethod]
public void GreatestCommonFactor_ShouldBe6_Given12And18()
{
const byte first = 12;
const byte second = 18;
byte multiple = first.GreatestCommonFactor(second);
Assert.AreEqual(6, multiple);
}
[TestMethod]
public void IsEvenShouldBeCorrect()
{
const byte one = 1;
const byte two = 2;
Assert.IsFalse(one.IsEven());
Assert.IsTrue(two.IsEven());
}
[TestMethod]
public void IsOddShouldBeCorrect()
{
const byte one = 1;
const byte two = 2;
Assert.IsTrue(one.IsOdd());
Assert.IsFalse(two.IsOdd());
}
[TestMethod]
public void LowestCommonMultiple_ShouldReturnCorrectValue_WhenCalledWithValidInput()
{
const byte value1 = 2;
const byte value2 = 3;
const byte expected = 6;
byte result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result);
}
[TestMethod]
public void LowestCommonMultiple_ShouldReturnZero_WhenCalledWithZero()
{
const byte value1 = 0;
const byte value2 = 10;
const byte expected = 0;
byte result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result);
}
[TestMethod]
public void LowestCommonMultiple_ShouldReturnGreaterValue_WhenCalledWithOne()
{
const byte value1 = 1;
const byte value2 = 10;
const byte expected = 10;
byte result1 = value1.LowestCommonMultiple(value2);
byte result2 = value2.LowestCommonMultiple(value1);
Assert.AreEqual(expected, result1);
Assert.AreEqual(expected, result2);
}
[TestMethod]
public void LowestCommonMultiple_ShouldReturnOtherValue_WhenCalledWithSameValue()
{
const byte value1 = 5;
const byte value2 = 5;
const byte expected = 5;
byte result = value1.LowestCommonMultiple(value2);
Assert.AreEqual(expected, result);
}
[TestMethod]
public void MultiplicativePersistence_ShouldBeCorrect_ForRecordHolders()
{
Assert.AreEqual(0, ((byte)0).MultiplicativePersistence());
Assert.AreEqual(1, ((byte)10).MultiplicativePersistence());
Assert.AreEqual(2, ((byte)25).MultiplicativePersistence());
Assert.AreEqual(3, ((byte)39).MultiplicativePersistence());
Assert.AreEqual(4, ((byte)77).MultiplicativePersistence());
}
}