Skip to content

Commit

Permalink
Merge pull request #16 from Yesser-Studios/improvements
Browse files Browse the repository at this point in the history
Improve test coverage and used proper naming conventions
  • Loading branch information
yesseruser authored Feb 11, 2024
2 parents 58551ac + 183e81c commit b069ed9
Show file tree
Hide file tree
Showing 12 changed files with 351 additions and 77 deletions.
6 changes: 4 additions & 2 deletions yTools.ConsoleTryout/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace yTools.ConsoleTryout
using System.Globalization;

namespace yTools.ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(Doubles.maxDouble.ToString());
Console.WriteLine(Doubles.MaxDouble.ToString(CultureInfo.InvariantCulture));
}
}
}
13 changes: 13 additions & 0 deletions yTools.Tests/BooleansTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace yTools.Tests;

[TestClass]
public class BooleansTests
{
[TestMethod]
[DataRow(true)]
[DataRow(false)]
public void Invert(bool boolean)
{
Assert.AreEqual(!boolean, Booleans.Invert(boolean));
}
}
155 changes: 155 additions & 0 deletions yTools.Tests/DoublesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
namespace yTools.Tests;

[TestClass]
public class DoublesTests
{
[TestMethod]
[DataRow(5, 0)]
[DataRow(5.69, 47.9)]
[DataRow(57979.46, 4798.689, 78.967)]
public void Sum(params double[] nums)
{
var expected = nums.Sum();

var summed = Doubles.Sum(nums);

Assert.AreEqual(expected, summed);
}

[TestMethod]
[DataRow(5, 0)]
[DataRow(5.69, 47.9)]
[DataRow(57979.46, 4798.689, 78.967)]
public void Average(params double[] nums)
{
var expected = nums.Average();

var average = Doubles.Average(nums);

Assert.AreEqual(expected, average);
}

[TestMethod]
[DataRow(5, 0)]
[DataRow(5.69, 47.9)]
[DataRow(57979.46, 4798.689, 78.967)]
public void Max(params double[] nums)
{
var expected = nums.Max();

var max = Doubles.Max(nums);

Assert.AreEqual(expected, max);
}

[TestMethod]
[DataRow(5, 0)]
[DataRow(5.69, 47.9)]
[DataRow(57979.46, 4798.689, 78.967)]
public void Min(params double[] nums)
{
var expected = nums.Min();

var min = Doubles.Min(nums);

Assert.AreEqual(expected, min);
}

[TestMethod]
[DataRow(5, 4)]
[DataRow(5.69, 47.9)]
public void Power(double a, double b)
{
var expected = Math.Pow(a, b);

var actual = Doubles.Power(a, b);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(69)]
[DataRow(4.5)]
[DataRow(47.9)]
public void SquareRoot(double num)
{
var expected = Math.Sqrt(num);

var actual = Doubles.SquareRoot(num);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(69)]
[DataRow(4.5)]
[DataRow(47.9)]
public void CubeRoot(double num)
{
var expected = Math.Cbrt(num);

var actual = Doubles.CubeRoot(num);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(5, 4)]
[DataRow(5.69, 47.9)]
public void Add(double a, double b)
{
var expected = a + b;

var actual = Doubles.Add(a, b);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(5, 4)]
[DataRow(5.69, 47.9)]
public void Subtract(double a, double b)
{
var expected = a - b;

var actual = Doubles.Substract(a, b);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(5, 4)]
[DataRow(5.69, 47.9)]
public void Multiply(double a, double b)
{
var expected = a * b;

var actual = Doubles.Multiply(a, b);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(5, 4)]
[DataRow(5.69, 47.9)]
public void Divide(double a, double b)
{
var expected = a / b;

var actual = Doubles.Divide(a, b);

Assert.AreEqual(expected, actual);
}

[TestMethod]
[DataRow(5, 4)]
[DataRow(5.69, 47.9)]
public void Remainder(double a, double b)
{
var expected = a % b;

var actual = Doubles.Remainder(a, b);

Assert.AreEqual(expected, actual);
}
}
22 changes: 22 additions & 0 deletions yTools.Tests/IntegersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class IntegersTests
public void IsPrimeTrue(int number)
{
bool isPrime = Integers.IsPrime(number);
bool isPrimeNoSave = Integers.IsPrimeWithoutSaving(number);
Assert.IsTrue(isPrime);
Assert.IsTrue(isPrimeNoSave);
}

[TestMethod]
Expand All @@ -32,7 +34,27 @@ public void IsPrimeTrue(int number)
public void IsPrimeFalse(int number)
{
bool isPrime = Integers.IsPrime(number);
bool isPrimeNoSave = Integers.IsPrimeWithoutSaving(number);
Assert.IsFalse(isPrime);
Assert.IsFalse(isPrimeNoSave);
}

[TestMethod]
[DataRow(11)]
public void IsPrimeTrueCache(int number)
{
bool isPrime = Integers.IsPrime(number);
Assert.IsTrue(isPrime);
Assert.IsTrue(Integers.PrimeNumbersProp.Contains(number));
}

[TestMethod]
[DataRow(9)]
public void IsPrimeFalseCache(int number)
{
bool isPrime = Integers.IsPrime(number);
Assert.IsFalse(isPrime);
Assert.IsTrue(Integers.NotPrimeNumbersProp.Contains(number));
}

[TestMethod]
Expand Down
61 changes: 58 additions & 3 deletions yTools.Tests/StringsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace yTools.Tests
{
[TestClass]
Expand All @@ -12,7 +13,7 @@ public class StringsTests
public void ConvertToString(double value)
{
string? converted = Strings.ToString(value);
Assert.AreEqual(converted, value.ToString());
Assert.AreEqual(converted, value.ToString(CultureInfo.InvariantCulture));
}

[TestMethod]
Expand All @@ -23,12 +24,66 @@ public void ConvertToString(double value)
public void JoinStrings(params string[] strings)
{
string joined = Strings.JoinStrings(strings);

string correct = "";
foreach (var str in strings)
{
correct += str;
}
Assert.AreEqual(joined, correct);

Assert.AreEqual(correct, joined);
}

[TestMethod]
[DataRow('h', 'e', 'l', 'l', 'o')]
[DataRow('h', 'r', 'u')]
[DataRow('i', 'd', 'k')]
public void JoinChars(params char[] chars)
{
string joined = Strings.JoinChars(chars);

string correct = "";
foreach (var c in chars)
{
correct += c;
}

Assert.AreEqual(correct, joined);
}

[TestMethod]
[DataRow("YO", "yo")]
[DataRow("hello", "hello")]
[DataRow("iDk", "idk")]
[DataRow("69", "69")]
[DataRow(".,'!", ".,'!")]
[DataRow("Mhm.", "mhm.")]
public void Lower(string str, string expected)
{
Assert.AreEqual(expected, Strings.Lower(str));
}

[TestMethod]
[DataRow("YO", "YO")]
[DataRow("hello", "HELLO")]
[DataRow("iDk", "IDK")]
[DataRow("69", "69")]
[DataRow(".,'!", ".,'!")]
[DataRow("Mhm.", "MHM.")]
public void Upper(string str, string expected)
{
Assert.AreEqual(expected, Strings.Upper(str));
}

[TestMethod]
[DataRow("Hello")]
public void IsNullOrWhitespace(string str)
{
var expected = string.IsNullOrWhiteSpace(str);

var actual = Strings.IsNullOrWhitespace(str);

Assert.AreEqual(expected, actual);
}
}
}
29 changes: 29 additions & 0 deletions yTools.Tests/VectorsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using yTools.Vectors;

namespace yTools.Tests;

[TestClass]
public class VectorsTests
{
[TestMethod]
public void Vector2ToString()
{
Vector2 vector = new(49.5, 50);

var expected = $"{vector.X},{vector.Y}";
var actual = vector.ToString();

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Vector3ToString()
{
Vector3 vector = new(49, 50.1, 51);

var expected = $"{vector.X},{vector.Y},{vector.Z}";
var actual = vector.ToString();

Assert.AreEqual(expected, actual);
}
}
12 changes: 3 additions & 9 deletions yTools/Booleans.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yTools
namespace yTools
{
public static class Booleans
{
/// <summary>
/// The true boolean value.
/// </summary>
public const bool TRUE = true;
public const bool True = true;

/// <summary>
/// The false boolean value.
/// </summary>
public const bool FALSE = false;
public const bool False = false;

/// <summary>
/// Returns the opposite of the given boolean value.
Expand Down
Loading

0 comments on commit b069ed9

Please sign in to comment.