diff --git a/X10D.Tests/src/Core/BooleanTests.cs b/X10D.Tests/src/Core/BooleanTests.cs index 7f01f63..1a5277c 100644 --- a/X10D.Tests/src/Core/BooleanTests.cs +++ b/X10D.Tests/src/Core/BooleanTests.cs @@ -1,33 +1,32 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for . +/// +[TestClass] +public class BooleanTests { /// - /// Tests for . + /// Tests . /// - [TestClass] - public class BooleanTests + [TestMethod] + public void GetBytes() { - /// - /// Tests . - /// - [TestMethod] - public void GetBytes() - { - const bool trueValue = true; - const bool falseValue = false; + const bool trueValue = true; + const bool falseValue = false; - var trueBytes = new byte[] { 0x01 }; - var falseBytes = new byte[] { 0x00 }; + var trueBytes = new byte[] { 0x01 }; + var falseBytes = new byte[] { 0x00 }; - byte[] trueResult = trueValue.GetBytes(); - byte[] falseResult = falseValue.GetBytes(); + byte[] trueResult = trueValue.GetBytes(); + byte[] falseResult = falseValue.GetBytes(); - Assert.AreEqual(1, trueResult.Length); - Assert.AreEqual(1, trueResult.Length); + Assert.AreEqual(1, trueResult.Length); + Assert.AreEqual(1, trueResult.Length); - CollectionAssert.AreEqual(trueBytes, trueResult); - CollectionAssert.AreEqual(falseBytes, falseResult); - } + CollectionAssert.AreEqual(trueBytes, trueResult); + CollectionAssert.AreEqual(falseBytes, falseResult); } -} +} \ No newline at end of file diff --git a/X10D.Tests/src/Core/ByteTests.cs b/X10D.Tests/src/Core/ByteTests.cs index 3852ecb..92b4cd3 100644 --- a/X10D.Tests/src/Core/ByteTests.cs +++ b/X10D.Tests/src/Core/ByteTests.cs @@ -1,62 +1,61 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for +/// +[TestClass] +public class ByteTests { /// - /// Tests for + /// Tests . /// - [TestClass] - public class ByteTests + [TestMethod] + public void GetBytes() { - /// - /// Tests . - /// - [TestMethod] - public void GetBytes() - { - const byte byteMinValue = byte.MinValue; - const byte byteMaxValue = byte.MaxValue; + const byte byteMinValue = byte.MinValue; + const byte byteMaxValue = byte.MaxValue; - var minValueBytes = new[] { byteMinValue }; - var maxValueBytes = new[] { byteMaxValue }; + var minValueBytes = new[] { byteMinValue }; + var maxValueBytes = new[] { byteMaxValue }; - var minValueResult = byteMinValue.GetBytes(); - var maxValueResult = byteMaxValue.GetBytes(); + var minValueResult = byteMinValue.GetBytes(); + var maxValueResult = byteMaxValue.GetBytes(); - CollectionAssert.AreEqual(minValueBytes, minValueResult); - CollectionAssert.AreEqual(maxValueBytes, maxValueResult); - } - - /// - /// Tests . - /// - [TestMethod] - public void IsEven() - { - const byte one = 1; - const byte two = 2; - - var oneEven = one.IsEven(); - var twoEven = two.IsEven(); - - Assert.IsFalse(oneEven); - Assert.IsTrue(twoEven); - } - - /// - /// Tests . - /// - [TestMethod] - public void IsOdd() - { - const byte one = 1; - const byte two = 2; - - var oneOdd = one.IsOdd(); - var twoOdd = two.IsOdd(); - - Assert.IsTrue(oneOdd); - Assert.IsFalse(twoOdd); - } + CollectionAssert.AreEqual(minValueBytes, minValueResult); + CollectionAssert.AreEqual(maxValueBytes, maxValueResult); } -} + + /// + /// Tests . + /// + [TestMethod] + public void IsEven() + { + const byte one = 1; + const byte two = 2; + + var oneEven = one.IsEven(); + var twoEven = two.IsEven(); + + Assert.IsFalse(oneEven); + Assert.IsTrue(twoEven); + } + + /// + /// Tests . + /// + [TestMethod] + public void IsOdd() + { + const byte one = 1; + const byte two = 2; + + var oneOdd = one.IsOdd(); + var twoOdd = two.IsOdd(); + + Assert.IsTrue(oneOdd); + Assert.IsFalse(twoOdd); + } +} \ No newline at end of file diff --git a/X10D.Tests/src/Core/CharTests.cs b/X10D.Tests/src/Core/CharTests.cs index c2a8360..45ef057 100644 --- a/X10D.Tests/src/Core/CharTests.cs +++ b/X10D.Tests/src/Core/CharTests.cs @@ -1,24 +1,23 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for . +/// +[TestClass] +public class CharTests { - /// - /// Tests for . - /// - [TestClass] - public class CharTests + [TestMethod] + public void Repeat() { - [TestMethod] - public void Repeat() - { - const char character = 'a'; - const int repeatCount = 10; + const char character = 'a'; + const int repeatCount = 10; - const string repeated = "aaaaaaaaaa"; - string result = character.Repeat(repeatCount); + const string repeated = "aaaaaaaaaa"; + string result = character.Repeat(repeatCount); - Assert.AreEqual(repeated, result); - Assert.ThrowsException(() => character.Repeat(-1)); - } + Assert.AreEqual(repeated, result); + Assert.ThrowsException(() => character.Repeat(-1)); } -} +} \ No newline at end of file diff --git a/X10D.Tests/src/Core/ComparableTests.cs b/X10D.Tests/src/Core/ComparableTests.cs index bd1ac7d..582ef40 100644 --- a/X10D.Tests/src/Core/ComparableTests.cs +++ b/X10D.Tests/src/Core/ComparableTests.cs @@ -1,131 +1,130 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for . +/// +[TestClass] +public class ComparableTests { /// - /// Tests for . + /// Tests /// - [TestClass] - public class ComparableTests + [TestMethod] + public void Between() { - /// - /// Tests - /// - [TestMethod] - public void Between() - { - const int lower = 5; - const int upper = 15; - const int value = 10; + const int lower = 5; + const int upper = 15; + const int value = 10; - Assert.IsTrue(value.Between(lower, upper), "value.Between(lower, upper)"); - Assert.IsFalse(lower.Between(value, upper), "lower.Between(value, upper)"); - Assert.IsFalse(upper.Between(lower, value), "upper.Between(lower, value)"); + Assert.IsTrue(value.Between(lower, upper), "value.Between(lower, upper)"); + Assert.IsFalse(lower.Between(value, upper), "lower.Between(value, upper)"); + Assert.IsFalse(upper.Between(lower, value), "upper.Between(lower, value)"); - Assert.IsTrue(upper.Between(lower, upper, InclusiveOptions.UpperInclusive), "upper.Between(lower, upper, Clusivity.UpperInclusive)"); - Assert.IsTrue(upper.Between(lower, upper, InclusiveOptions.Inclusive), "upper.Between(lower, upper, Clusivity.Inclusive)"); - Assert.IsFalse(upper.Between(lower, upper, InclusiveOptions.LowerInclusive), "upper.Between(lower, upper, Clusivity.LowerInclusive)"); + Assert.IsTrue(upper.Between(lower, upper, InclusiveOptions.UpperInclusive), "upper.Between(lower, upper, Clusivity.UpperInclusive)"); + Assert.IsTrue(upper.Between(lower, upper, InclusiveOptions.Inclusive), "upper.Between(lower, upper, Clusivity.Inclusive)"); + Assert.IsFalse(upper.Between(lower, upper, InclusiveOptions.LowerInclusive), "upper.Between(lower, upper, Clusivity.LowerInclusive)"); - Assert.IsTrue(lower.Between(lower, upper, InclusiveOptions.LowerInclusive), "lower.Between(lower, upper, Clusivity.LowerInclusive)"); - Assert.IsTrue(lower.Between(lower, upper, InclusiveOptions.Inclusive), "lower.Between(lower, upper, Clusivity.Inclusive)"); - Assert.IsFalse(lower.Between(lower, upper, InclusiveOptions.UpperInclusive), "lower.Between(lower, upper, Clusivity.UpperInclusive)"); - } - - /// - /// Tests - /// - [TestMethod] - public void Clamp() - { - const int lower = 5; - const int upper = 10; - const int value = 15; - - Assert.AreEqual(upper, value.Clamp(lower, upper)); - Assert.AreEqual(upper, lower.Clamp(upper, value)); - Assert.AreEqual(upper, upper.Clamp(lower, value)); - } - - /// - /// Tests - /// - [TestMethod] - public void GreaterThan() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(second.GreaterThan(first)); - Assert.IsFalse(first.GreaterThan(second)); - } - - /// - /// Tests - /// - [TestMethod] - public void GreaterThanOrEqualTo() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(second.GreaterThanOrEqualTo(first)); - Assert.IsTrue(second.GreaterThanOrEqualTo(second)); - Assert.IsTrue(first.GreaterThanOrEqualTo(first)); - Assert.IsFalse(first.GreaterThanOrEqualTo(second)); - } - - /// - /// Tests - /// - [TestMethod] - public void LessThan() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(first.LessThan(second)); - Assert.IsFalse(second.LessThan(first)); - } - - /// - /// Tests - /// - [TestMethod] - public void LessThanOrEqualTo() - { - const int first = 5; - const int second = 10; - - Assert.IsTrue(first.LessThanOrEqualTo(second)); - Assert.IsTrue(first.LessThanOrEqualTo(first)); - Assert.IsTrue(second.LessThanOrEqualTo(second)); - Assert.IsFalse(second.LessThanOrEqualTo(first)); - } - - /// - /// Tests - /// - [TestMethod] - public void Max() - { - const int first = 5; - const int second = 10; - - Assert.AreEqual(second, first.Max(second)); - Assert.AreEqual(second, second.Max(first)); - } - - /// - /// Tests - /// - [TestMethod] - public void Min() - { - const int first = 5; - const int second = 10; - - Assert.AreEqual(first, first.Min(second)); - Assert.AreEqual(first, second.Min(first)); - } + Assert.IsTrue(lower.Between(lower, upper, InclusiveOptions.LowerInclusive), "lower.Between(lower, upper, Clusivity.LowerInclusive)"); + Assert.IsTrue(lower.Between(lower, upper, InclusiveOptions.Inclusive), "lower.Between(lower, upper, Clusivity.Inclusive)"); + Assert.IsFalse(lower.Between(lower, upper, InclusiveOptions.UpperInclusive), "lower.Between(lower, upper, Clusivity.UpperInclusive)"); } -} + + /// + /// Tests + /// + [TestMethod] + public void Clamp() + { + const int lower = 5; + const int upper = 10; + const int value = 15; + + Assert.AreEqual(upper, value.Clamp(lower, upper)); + Assert.AreEqual(upper, lower.Clamp(upper, value)); + Assert.AreEqual(upper, upper.Clamp(lower, value)); + } + + /// + /// Tests + /// + [TestMethod] + public void GreaterThan() + { + const int first = 5; + const int second = 10; + + Assert.IsTrue(second.GreaterThan(first)); + Assert.IsFalse(first.GreaterThan(second)); + } + + /// + /// Tests + /// + [TestMethod] + public void GreaterThanOrEqualTo() + { + const int first = 5; + const int second = 10; + + Assert.IsTrue(second.GreaterThanOrEqualTo(first)); + Assert.IsTrue(second.GreaterThanOrEqualTo(second)); + Assert.IsTrue(first.GreaterThanOrEqualTo(first)); + Assert.IsFalse(first.GreaterThanOrEqualTo(second)); + } + + /// + /// Tests + /// + [TestMethod] + public void LessThan() + { + const int first = 5; + const int second = 10; + + Assert.IsTrue(first.LessThan(second)); + Assert.IsFalse(second.LessThan(first)); + } + + /// + /// Tests + /// + [TestMethod] + public void LessThanOrEqualTo() + { + const int first = 5; + const int second = 10; + + Assert.IsTrue(first.LessThanOrEqualTo(second)); + Assert.IsTrue(first.LessThanOrEqualTo(first)); + Assert.IsTrue(second.LessThanOrEqualTo(second)); + Assert.IsFalse(second.LessThanOrEqualTo(first)); + } + + /// + /// Tests + /// + [TestMethod] + public void Max() + { + const int first = 5; + const int second = 10; + + Assert.AreEqual(second, first.Max(second)); + Assert.AreEqual(second, second.Max(first)); + } + + /// + /// Tests + /// + [TestMethod] + public void Min() + { + const int first = 5; + const int second = 10; + + Assert.AreEqual(first, first.Min(second)); + Assert.AreEqual(first, second.Min(first)); + } +} \ No newline at end of file diff --git a/X10D.Tests/src/Core/DoubleTests.cs b/X10D.Tests/src/Core/DoubleTests.cs index 7190cfe..a815f42 100644 --- a/X10D.Tests/src/Core/DoubleTests.cs +++ b/X10D.Tests/src/Core/DoubleTests.cs @@ -1,106 +1,105 @@ using System.Diagnostics; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +/// +/// Tests for . +/// +[TestClass] +public class DoubleTests { - using System; - using Microsoft.VisualStudio.TestTools.UnitTesting; + /// + /// Test for + /// + [TestMethod] + public void LerpTo() + { + const double a = 0.0; + const double b = 1.0; + const double t = 0.5; + const double expected = 0.5; + + double actual = a.LerpFrom(b, t); + + Trace.WriteLine($"expected = {expected}"); + Trace.WriteLine($"{a}.LerpTo({b}, {t}) = {actual}"); + Assert.AreEqual(expected, actual, $"{a}.LerpTo({b}, {t})"); + } /// - /// Tests for . + /// Tests for . /// - [TestClass] - public class DoubleTests + [TestMethod] + public void DegreesToRadians() { - /// - /// Test for - /// - [TestMethod] - public void LerpTo() - { - const double a = 0.0; - const double b = 1.0; - const double t = 0.5; - const double expected = 0.5; + Assert.AreEqual(Math.PI, 180.0.DegreesToRadians()); + Assert.AreEqual(Math.PI * 1.5, 270.0.DegreesToRadians()); + Assert.AreEqual(0.0, 0.0.DegreesToRadians()); + Assert.AreEqual(0.017453292519943295, 1.0.DegreesToRadians()); + Assert.AreEqual(0.10471975511965978, 6.0.DegreesToRadians()); + Assert.AreEqual(0.20943951023931956, 12.0.DegreesToRadians()); + } - double actual = a.LerpFrom(b, t); + /// + /// Tests for . + /// + [TestMethod] + public void GetBytes() + { + CollectionAssert.AreEqual( + new byte[] {0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40}, + Math.PI.GetBytes()); + } - Trace.WriteLine($"expected = {expected}"); - Trace.WriteLine($"{a}.LerpTo({b}, {t}) = {actual}"); - Assert.AreEqual(expected, actual, $"{a}.LerpTo({b}, {t})"); - } + /// + /// Tests for . + /// + [TestMethod] + public void IsEven() + { + Assert.IsTrue(2.0.IsEven()); + Assert.IsFalse(1.0.IsEven()); + } - /// - /// Tests for . - /// - [TestMethod] - public void DegreesToRadians() - { - Assert.AreEqual(Math.PI, 180.0.DegreesToRadians()); - Assert.AreEqual(Math.PI * 1.5, 270.0.DegreesToRadians()); - Assert.AreEqual(0.0, 0.0.DegreesToRadians()); - Assert.AreEqual(0.017453292519943295, 1.0.DegreesToRadians()); - Assert.AreEqual(0.10471975511965978, 6.0.DegreesToRadians()); - Assert.AreEqual(0.20943951023931956, 12.0.DegreesToRadians()); - } + /// + /// Tests for . + /// + [TestMethod] + public void IsOdd() + { + Assert.IsFalse(2.0.IsOdd()); + Assert.IsTrue(1.0.IsOdd()); + } - /// - /// Tests for . - /// - [TestMethod] - public void GetBytes() - { - CollectionAssert.AreEqual( - new byte[] {0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40}, - Math.PI.GetBytes()); - } + /// + /// Tests for . + /// + [TestMethod] + public void RadiansToDegrees() + { + Assert.AreEqual(180.0, Math.PI.RadiansToDegrees()); + Assert.AreEqual(360.0, (2.0 * Math.PI).RadiansToDegrees()); + Assert.AreEqual(0.0, 0.0.RadiansToDegrees()); + Assert.AreEqual(1.0, 0.017453292519943295.RadiansToDegrees()); + Assert.AreEqual(6.000000000000001, 0.10471975511965978.RadiansToDegrees()); // rounding errors are fun + Assert.AreEqual(12.0, 0.20943951023931953.RadiansToDegrees()); + } - /// - /// Tests for . - /// - [TestMethod] - public void IsEven() - { - Assert.IsTrue(2.0.IsEven()); - Assert.IsFalse(1.0.IsEven()); - } + /// + /// Tests for and . + /// + [TestMethod] + public void Round() + { + Assert.AreEqual(4.0, 3.5.Round()); + Assert.AreEqual(7.0, 6.8.Round()); + Assert.AreEqual(7.0, 7.2.Round()); - /// - /// Tests for . - /// - [TestMethod] - public void IsOdd() - { - Assert.IsFalse(2.0.IsOdd()); - Assert.IsTrue(1.0.IsOdd()); - } - - /// - /// Tests for . - /// - [TestMethod] - public void RadiansToDegrees() - { - Assert.AreEqual(180.0, Math.PI.RadiansToDegrees()); - Assert.AreEqual(360.0, (2.0 * Math.PI).RadiansToDegrees()); - Assert.AreEqual(0.0, 0.0.RadiansToDegrees()); - Assert.AreEqual(1.0, 0.017453292519943295.RadiansToDegrees()); - Assert.AreEqual(6.000000000000001, 0.10471975511965978.RadiansToDegrees()); // rounding errors are fun - Assert.AreEqual(12.0, 0.20943951023931953.RadiansToDegrees()); - } - - /// - /// Tests for and . - /// - [TestMethod] - public void Round() - { - Assert.AreEqual(4.0, 3.5.Round()); - Assert.AreEqual(7.0, 6.8.Round()); - Assert.AreEqual(7.0, 7.2.Round()); - - Assert.AreEqual(5.0, 3.5.Round(5)); - Assert.AreEqual(5.0, 7.0.Round(5)); - Assert.AreEqual(10.0, 7.5.Round(5)); - } + Assert.AreEqual(5.0, 3.5.Round(5)); + Assert.AreEqual(5.0, 7.0.Round(5)); + Assert.AreEqual(10.0, 7.5.Round(5)); } } diff --git a/X10D.Tests/src/Core/IsPrimeTests.cs b/X10D.Tests/src/Core/IsPrimeTests.cs index cbba572..bb55450 100644 --- a/X10D.Tests/src/Core/IsPrimeTests.cs +++ b/X10D.Tests/src/Core/IsPrimeTests.cs @@ -3,117 +3,116 @@ using System.Reflection; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for . +/// +/// +/// Tests for this extension method are delegated to their own test class because of the non-trivial requirements for +/// loading testing prime numbers. +/// +/// +/// +/// +[TestClass] +public class IsPrimeTests { - /// - /// Tests for . - /// - /// - /// Tests for this extension method are delegated to their own test class because of the non-trivial requirements for - /// loading testing prime numbers. - /// - /// - /// - /// - [TestClass] - public class IsPrimeTests + private IReadOnlyList _primeNumbers = ArraySegment.Empty; + + [TestInitialize] + public void Initialize() { - private IReadOnlyList _primeNumbers = ArraySegment.Empty; + _primeNumbers = LoadPrimes(); + Assert.AreEqual(1000, _primeNumbers.Count); + } - [TestInitialize] - public void Initialize() + /// + /// Asserts the primality of the first 1000 known prime numbers. + /// + [TestMethod] + public void First1000Primes() + { + for (var index = 0; index < _primeNumbers.Count; index++) { - _primeNumbers = LoadPrimes(); - Assert.AreEqual(1000, _primeNumbers.Count); - } - - /// - /// Asserts the primality of the first 1000 known prime numbers. - /// - [TestMethod] - public void First1000Primes() - { - for (var index = 0; index < _primeNumbers.Count; index++) - { - int value = _primeNumbers[index]; - bool result = value.IsPrime(); - Assert.IsTrue(result, value.ToString("N0", CultureInfo.InvariantCulture)); - } - } - - /// - /// Asserts that all negative numbers are not prime. - /// - [TestMethod] - public void Negatives() - { - for (var value = short.MinValue; value < 0; value++) - { - bool result = value.IsPrime(); - Assert.IsFalse(result, value.ToString("N0", CultureInfo.InvariantCulture)); - } - } - - /// - /// Asserts that values 0 and 1 are not prime. - /// - [TestMethod] - public void LessThan2() - { - for (var value = 0; value < 2; value++) - { - bool result = value.IsPrime(); - Assert.IsFalse(result, value.ToString("N0", CultureInfo.InvariantCulture)); - } - } - - /// - /// Tests the primality of the numbers 0 - 7919. - /// - [TestMethod] - public void ZeroTo7919() - { - for (var value = 0; value < 7920; value++) - { - bool expected = _primeNumbers.Contains(value); - bool actual = value.IsPrime(); - - Assert.AreEqual(expected, actual, value.ToString("N0", CultureInfo.InvariantCulture)); - } - } - - /// - /// Tests the primality of the numbers 0 - . - /// - [TestMethod] - public void ZeroToByteMaxValue() - { - for (byte value = 0; value < byte.MaxValue; value++) - { - bool expected = _primeNumbers.Contains(value); - bool actual = value.IsPrime(); - - Assert.AreEqual(expected, actual, value.ToString("N0", CultureInfo.InvariantCulture)); - } - } - - private static IReadOnlyList LoadPrimes() - { - using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X10D.Tests.1000primes.txt"); - Assert.IsNotNull(stream); - - using var reader = new StreamReader(stream, Encoding.UTF8); - var primes = new List(); - - while (reader.ReadLine() is { } line) - { - if (int.TryParse(line, out int prime)) - { - primes.Add(prime); - } - } - - return primes.AsReadOnly(); + int value = _primeNumbers[index]; + bool result = value.IsPrime(); + Assert.IsTrue(result, value.ToString("N0", CultureInfo.InvariantCulture)); } } -} + + /// + /// Asserts that all negative numbers are not prime. + /// + [TestMethod] + public void Negatives() + { + for (var value = short.MinValue; value < 0; value++) + { + bool result = value.IsPrime(); + Assert.IsFalse(result, value.ToString("N0", CultureInfo.InvariantCulture)); + } + } + + /// + /// Asserts that values 0 and 1 are not prime. + /// + [TestMethod] + public void LessThan2() + { + for (var value = 0; value < 2; value++) + { + bool result = value.IsPrime(); + Assert.IsFalse(result, value.ToString("N0", CultureInfo.InvariantCulture)); + } + } + + /// + /// Tests the primality of the numbers 0 - 7919. + /// + [TestMethod] + public void ZeroTo7919() + { + for (var value = 0; value < 7920; value++) + { + bool expected = _primeNumbers.Contains(value); + bool actual = value.IsPrime(); + + Assert.AreEqual(expected, actual, value.ToString("N0", CultureInfo.InvariantCulture)); + } + } + + /// + /// Tests the primality of the numbers 0 - . + /// + [TestMethod] + public void ZeroToByteMaxValue() + { + for (byte value = 0; value < byte.MaxValue; value++) + { + bool expected = _primeNumbers.Contains(value); + bool actual = value.IsPrime(); + + Assert.AreEqual(expected, actual, value.ToString("N0", CultureInfo.InvariantCulture)); + } + } + + private static IReadOnlyList LoadPrimes() + { + using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X10D.Tests.1000primes.txt"); + Assert.IsNotNull(stream); + + using var reader = new StreamReader(stream, Encoding.UTF8); + var primes = new List(); + + while (reader.ReadLine() is { } line) + { + if (int.TryParse(line, out int prime)) + { + primes.Add(prime); + } + } + + return primes.AsReadOnly(); + } +} \ No newline at end of file diff --git a/X10D.Tests/src/Core/SByteTests.cs b/X10D.Tests/src/Core/SByteTests.cs index 57c83b0..23e681c 100644 --- a/X10D.Tests/src/Core/SByteTests.cs +++ b/X10D.Tests/src/Core/SByteTests.cs @@ -1,44 +1,43 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for +/// +[CLSCompliant(false)] +[TestClass] +public class SByteTests { /// - /// Tests for + /// Tests . /// - [CLSCompliant(false)] - [TestClass] - public class SByteTests + [TestMethod] + public void IsEven() { - /// - /// Tests . - /// - [TestMethod] - public void IsEven() - { - const sbyte one = 1; - const sbyte two = 2; + const sbyte one = 1; + const sbyte two = 2; - var oneEven = one.IsEven(); - var twoEven = two.IsEven(); + var oneEven = one.IsEven(); + var twoEven = two.IsEven(); - Assert.AreEqual(false, oneEven); - Assert.AreEqual(true, twoEven); - } - - /// - /// Tests . - /// - [TestMethod] - public void IsOdd() - { - const sbyte one = 1; - const sbyte two = 2; - - var oneOdd = one.IsOdd(); - var twoOdd = two.IsOdd(); - - Assert.AreEqual(true, oneOdd); - Assert.AreEqual(false, twoOdd); - } + Assert.AreEqual(false, oneEven); + Assert.AreEqual(true, twoEven); } -} + + /// + /// Tests . + /// + [TestMethod] + public void IsOdd() + { + const sbyte one = 1; + const sbyte two = 2; + + var oneOdd = one.IsOdd(); + var twoOdd = two.IsOdd(); + + Assert.AreEqual(true, oneOdd); + Assert.AreEqual(false, twoOdd); + } +} \ No newline at end of file diff --git a/X10D.Tests/src/Core/StringTests.cs b/X10D.Tests/src/Core/StringTests.cs index b940465..c0e76f8 100644 --- a/X10D.Tests/src/Core/StringTests.cs +++ b/X10D.Tests/src/Core/StringTests.cs @@ -1,236 +1,235 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace X10D.Tests.Core +namespace X10D.Tests.Core; + +/// +/// Tests for . +/// +[TestClass] +public class StringTests { /// - /// Tests for . + /// Tests . /// - [TestClass] - public class StringTests + [TestMethod] + public void AsNullIfEmpty() { - /// - /// Tests . - /// - [TestMethod] - public void AsNullIfEmpty() - { - const string sampleString = "Hello World"; - const string whitespaceString = " "; - const string emptyString = ""; - const string? nullString = null; + const string sampleString = "Hello World"; + const string whitespaceString = " "; + const string emptyString = ""; + const string? nullString = null; - string sampleResult = sampleString.AsNullIfEmpty(); - string whitespaceResult = whitespaceString.AsNullIfEmpty(); - string emptyResult = emptyString.AsNullIfEmpty(); - string? nullResult = nullString.AsNullIfEmpty(); + string sampleResult = sampleString.AsNullIfEmpty(); + string whitespaceResult = whitespaceString.AsNullIfEmpty(); + string emptyResult = emptyString.AsNullIfEmpty(); + string? nullResult = nullString.AsNullIfEmpty(); - Assert.AreEqual(sampleString, sampleResult); - Assert.AreEqual(whitespaceString, whitespaceResult); - Assert.AreEqual(nullString, emptyResult); - Assert.AreEqual(nullString, nullResult); - } - - /// - /// Tests . - /// - [TestMethod] - public void AsNullIfWhiteSpace() - { - const string sampleString = "Hello World"; - const string whitespaceString = " "; - const string emptyString = ""; - const string? nullString = null; - - string sampleResult = sampleString.AsNullIfWhiteSpace(); - string whitespaceResult = whitespaceString.AsNullIfWhiteSpace(); - string emptyResult = emptyString.AsNullIfWhiteSpace(); - string? nullResult = nullString.AsNullIfWhiteSpace(); - - Assert.AreEqual(sampleString, sampleResult); - Assert.AreEqual(nullString, whitespaceResult); - Assert.AreEqual(nullString, emptyResult); - Assert.AreEqual(nullString, nullResult); - } - - /// - /// Tests . - /// - [TestMethod] - public void Base64Decode() - { - const string input = "SGVsbG8gV29ybGQ="; - const string expected = "Hello World"; - - string result = input.Base64Decode(); - - Assert.AreEqual(expected, result); - } - - - /// - /// Tests . - /// - [TestMethod] - public void Base64Encode() - { - const string input = "Hello World"; - const string expected = "SGVsbG8gV29ybGQ="; - - string result = input.Base64Encode(); - - Assert.AreEqual(expected, result); - } - - /// - /// Tests . - /// - [TestMethod] - public void IsLower() - { - const string inputA = "Hello World"; - const string inputB = "hello world"; - const string? nullString = null; - - bool resultA = inputA.IsLower(); - bool resultB = inputB.IsLower(); - - Assert.ThrowsException(() => nullString!.IsLower()); - Assert.IsFalse(resultA); - Assert.IsTrue(resultB); - } - - [TestMethod] - public void IsPalindrome() - { - const string inputA = "Race car"; - const string inputB = "Racecar"; - const string inputC = "A man, a plan, a canal, panama"; - const string inputD = "Jackdaws love my big sphinx of quartz"; - const string inputE = "Y"; - const string inputF = "1"; - const string inputG = ""; - - Assert.IsTrue(inputA.IsPalindrome(), inputA); - Assert.IsTrue(inputB.IsPalindrome(), inputB); - Assert.IsTrue(inputC.IsPalindrome(), inputC); - Assert.IsFalse(inputD.IsPalindrome(), inputD); - Assert.IsTrue(inputE.IsPalindrome(), inputE); - Assert.IsTrue(inputF.IsPalindrome(), inputF); - Assert.IsFalse(inputG.IsPalindrome(), inputG); - } - - /// - /// Tests . - /// - [TestMethod] - public void IsUpper() - { - const string inputA = "Hello World"; - const string inputB = "HELLO WORLD"; - const string? nullString = null; - - bool resultA = inputA.IsUpper(); - bool resultB = inputB.IsUpper(); - - Assert.ThrowsException(() => nullString!.IsUpper()); - Assert.IsFalse(resultA); - Assert.IsTrue(resultB); - } - - /// - /// Tests . - /// - [TestMethod] - public void Shuffled() - { - const string input = "Hello World"; - const string expected = " oHlldrWoel"; - var random = new Random(1); - - string result = input.Shuffled(random); - - Assert.ThrowsException(() => ((string?)null)!.Shuffled()); - Assert.AreEqual(expected, result); - } - - /// - /// Tests . - /// - [TestMethod] - public void Randomize() - { - const string input = "Hello World"; - const string expected = "le rooldeoH"; - var random = new Random(1); - - string result = input.Randomize(input.Length, random); - - Assert.ThrowsException(() => ((string?)null)!.Randomize(1)); - Assert.ThrowsException(() => input.Randomize(-1)); - Assert.AreEqual(string.Empty, string.Empty.Randomize(0)); - Assert.AreEqual(expected, result); - } - - /// - /// Tests . - /// - [TestMethod] - public void Repeat() - { - const string input = "Hello World"; - const string expected = "Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World"; - const int repeatCount = 8; - - string result = input.Repeat(repeatCount); - - Assert.ThrowsException(() => ((string?)null)!.Repeat(repeatCount)); - Assert.ThrowsException(() => input.Repeat(-1)); - Assert.AreEqual(expected, result); - } - - /// - /// Tests . - /// - [TestMethod] - public void Reverse() - { - const string input = "Hello World"; - const string expected = "dlroW olleH"; - - string result = input.Reverse(); - - Assert.ThrowsException(() => ((string?)null)!.Reverse()); - Assert.AreEqual(string.Empty.Reverse(), string.Empty); - Assert.AreEqual(" ".Reverse(), " "); - Assert.AreEqual(expected, result); - } - - /// - /// Tests and - /// . - /// - [TestMethod] - public void WithAlternative() - { - const string inputA = "Hello World"; - const string inputB = " "; - const string inputC = ""; - const string? inputD = null; - const string alternative = "ALTERNATIVE"; - - string resultA = inputA.WithEmptyAlternative(alternative); - string resultB = inputB.WithEmptyAlternative(alternative); - string resultBWithWhitespace = inputB.WithWhiteSpaceAlternative(alternative); - string resultC = inputC.WithEmptyAlternative(alternative); - string resultD = inputD.WithEmptyAlternative(alternative); - - Assert.AreEqual(resultA, inputA); - Assert.AreEqual(resultB, inputB); - Assert.AreEqual(resultBWithWhitespace, alternative); - Assert.AreEqual(resultC, alternative); - Assert.AreEqual(resultD, alternative); - Assert.AreEqual(alternative, ((string?)null).WithEmptyAlternative(alternative)); - Assert.AreEqual(alternative, ((string?)null).WithWhiteSpaceAlternative(alternative)); - } + Assert.AreEqual(sampleString, sampleResult); + Assert.AreEqual(whitespaceString, whitespaceResult); + Assert.AreEqual(nullString, emptyResult); + Assert.AreEqual(nullString, nullResult); } -} + + /// + /// Tests . + /// + [TestMethod] + public void AsNullIfWhiteSpace() + { + const string sampleString = "Hello World"; + const string whitespaceString = " "; + const string emptyString = ""; + const string? nullString = null; + + string sampleResult = sampleString.AsNullIfWhiteSpace(); + string whitespaceResult = whitespaceString.AsNullIfWhiteSpace(); + string emptyResult = emptyString.AsNullIfWhiteSpace(); + string? nullResult = nullString.AsNullIfWhiteSpace(); + + Assert.AreEqual(sampleString, sampleResult); + Assert.AreEqual(nullString, whitespaceResult); + Assert.AreEqual(nullString, emptyResult); + Assert.AreEqual(nullString, nullResult); + } + + /// + /// Tests . + /// + [TestMethod] + public void Base64Decode() + { + const string input = "SGVsbG8gV29ybGQ="; + const string expected = "Hello World"; + + string result = input.Base64Decode(); + + Assert.AreEqual(expected, result); + } + + + /// + /// Tests . + /// + [TestMethod] + public void Base64Encode() + { + const string input = "Hello World"; + const string expected = "SGVsbG8gV29ybGQ="; + + string result = input.Base64Encode(); + + Assert.AreEqual(expected, result); + } + + /// + /// Tests . + /// + [TestMethod] + public void IsLower() + { + const string inputA = "Hello World"; + const string inputB = "hello world"; + const string? nullString = null; + + bool resultA = inputA.IsLower(); + bool resultB = inputB.IsLower(); + + Assert.ThrowsException(() => nullString!.IsLower()); + Assert.IsFalse(resultA); + Assert.IsTrue(resultB); + } + + [TestMethod] + public void IsPalindrome() + { + const string inputA = "Race car"; + const string inputB = "Racecar"; + const string inputC = "A man, a plan, a canal, panama"; + const string inputD = "Jackdaws love my big sphinx of quartz"; + const string inputE = "Y"; + const string inputF = "1"; + const string inputG = ""; + + Assert.IsTrue(inputA.IsPalindrome(), inputA); + Assert.IsTrue(inputB.IsPalindrome(), inputB); + Assert.IsTrue(inputC.IsPalindrome(), inputC); + Assert.IsFalse(inputD.IsPalindrome(), inputD); + Assert.IsTrue(inputE.IsPalindrome(), inputE); + Assert.IsTrue(inputF.IsPalindrome(), inputF); + Assert.IsFalse(inputG.IsPalindrome(), inputG); + } + + /// + /// Tests . + /// + [TestMethod] + public void IsUpper() + { + const string inputA = "Hello World"; + const string inputB = "HELLO WORLD"; + const string? nullString = null; + + bool resultA = inputA.IsUpper(); + bool resultB = inputB.IsUpper(); + + Assert.ThrowsException(() => nullString!.IsUpper()); + Assert.IsFalse(resultA); + Assert.IsTrue(resultB); + } + + /// + /// Tests . + /// + [TestMethod] + public void Shuffled() + { + const string input = "Hello World"; + const string expected = " oHlldrWoel"; + var random = new Random(1); + + string result = input.Shuffled(random); + + Assert.ThrowsException(() => ((string?)null)!.Shuffled()); + Assert.AreEqual(expected, result); + } + + /// + /// Tests . + /// + [TestMethod] + public void Randomize() + { + const string input = "Hello World"; + const string expected = "le rooldeoH"; + var random = new Random(1); + + string result = input.Randomize(input.Length, random); + + Assert.ThrowsException(() => ((string?)null)!.Randomize(1)); + Assert.ThrowsException(() => input.Randomize(-1)); + Assert.AreEqual(string.Empty, string.Empty.Randomize(0)); + Assert.AreEqual(expected, result); + } + + /// + /// Tests . + /// + [TestMethod] + public void Repeat() + { + const string input = "Hello World"; + const string expected = "Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World"; + const int repeatCount = 8; + + string result = input.Repeat(repeatCount); + + Assert.ThrowsException(() => ((string?)null)!.Repeat(repeatCount)); + Assert.ThrowsException(() => input.Repeat(-1)); + Assert.AreEqual(expected, result); + } + + /// + /// Tests . + /// + [TestMethod] + public void Reverse() + { + const string input = "Hello World"; + const string expected = "dlroW olleH"; + + string result = input.Reverse(); + + Assert.ThrowsException(() => ((string?)null)!.Reverse()); + Assert.AreEqual(string.Empty.Reverse(), string.Empty); + Assert.AreEqual(" ".Reverse(), " "); + Assert.AreEqual(expected, result); + } + + /// + /// Tests and + /// . + /// + [TestMethod] + public void WithAlternative() + { + const string inputA = "Hello World"; + const string inputB = " "; + const string inputC = ""; + const string? inputD = null; + const string alternative = "ALTERNATIVE"; + + string resultA = inputA.WithEmptyAlternative(alternative); + string resultB = inputB.WithEmptyAlternative(alternative); + string resultBWithWhitespace = inputB.WithWhiteSpaceAlternative(alternative); + string resultC = inputC.WithEmptyAlternative(alternative); + string resultD = inputD.WithEmptyAlternative(alternative); + + Assert.AreEqual(resultA, inputA); + Assert.AreEqual(resultB, inputB); + Assert.AreEqual(resultBWithWhitespace, alternative); + Assert.AreEqual(resultC, alternative); + Assert.AreEqual(resultD, alternative); + Assert.AreEqual(alternative, ((string?)null).WithEmptyAlternative(alternative)); + Assert.AreEqual(alternative, ((string?)null).WithWhiteSpaceAlternative(alternative)); + } +} \ No newline at end of file