Skip to content

Commit

Permalink
test: add 100% coverage for DigitalRoot
Browse files Browse the repository at this point in the history
remove partial coverage by checking for 9
  • Loading branch information
oliverbooth committed Jun 12, 2024
1 parent db96c9e commit 7f92772
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 12 deletions.
18 changes: 17 additions & 1 deletion X10D.Tests/src/Math/ByteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,29 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const byte value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const byte value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const byte value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void FactorialShouldBeCorrect()
{
Expand Down
18 changes: 17 additions & 1 deletion X10D.Tests/src/Math/Int16Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const short value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const short value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const short value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void FactorialShouldBeCorrect()
{
Expand Down
18 changes: 17 additions & 1 deletion X10D.Tests/src/Math/Int32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const int value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const int value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const int value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void FactorialShouldBeCorrect()
{
Expand Down
18 changes: 17 additions & 1 deletion X10D.Tests/src/Math/Int64Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const long value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const long value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const long value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void FactorialShouldBeCorrect()
{
Expand Down
18 changes: 17 additions & 1 deletion X10D.Tests/src/Math/SByteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ public void CountDigits_ShouldReturn3_Given127()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given127()
{
const sbyte value = 127; // sbyte.MaxValue. can't use 238 like the other tests
Assert.That(value.DigitalRoot(), Is.EqualTo(1));
Assert.That((-value).DigitalRoot(), Is.EqualTo(1));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const sbyte value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const sbyte value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void FactorialShouldBeCorrect()
{
Expand Down
18 changes: 17 additions & 1 deletion X10D.Tests/src/Math/UInt16Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,29 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const ushort value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const ushort value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const ushort value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void FactorialShouldBeCorrect()
{
Expand Down
22 changes: 19 additions & 3 deletions X10D.Tests/src/Math/UInt32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,27 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const uint value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4U));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4U));
Assert.That(value.DigitalRoot(), Is.EqualTo(4));
Assert.That((-value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const uint value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const uint value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
Expand Down
22 changes: 19 additions & 3 deletions X10D.Tests/src/Math/UInt64Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,31 @@ public void CountDigits_ShouldReturn3_Given199()
}

[Test]
public void DigitalRootShouldBeCorrect()
public void DigitalRoot_ShouldReturn4_Given238()
{
const ulong value = 238;
Assert.That(value.DigitalRoot(), Is.EqualTo(4U));
Assert.That(value.DigitalRoot(), Is.EqualTo(4));

// -ulong operator not defined because it might exceed long.MinValue,
// so instead, cast to long and then negate.
// HAX.
Assert.That((-(long)value).DigitalRoot(), Is.EqualTo(4U));
Assert.That((-(long)value).DigitalRoot(), Is.EqualTo(4));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given9()
{
const ulong value = 9;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-(long)value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
public void DigitalRoot_ShouldReturn9_Given18()
{
const ulong value = 18;
Assert.That(value.DigitalRoot(), Is.EqualTo(9));
Assert.That((-(long)value).DigitalRoot(), Is.EqualTo(9));
}

[Test]
Expand Down

0 comments on commit 7f92772

Please sign in to comment.