diff --git a/yTools.ConsoleTryout/Program.cs b/yTools.ConsoleTryout/Program.cs
index cf0bee1..4860d50 100644
--- a/yTools.ConsoleTryout/Program.cs
+++ b/yTools.ConsoleTryout/Program.cs
@@ -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));
}
}
}
\ No newline at end of file
diff --git a/yTools.Tests/BooleansTests.cs b/yTools.Tests/BooleansTests.cs
new file mode 100644
index 0000000..726d724
--- /dev/null
+++ b/yTools.Tests/BooleansTests.cs
@@ -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));
+ }
+}
\ No newline at end of file
diff --git a/yTools.Tests/DoublesTests.cs b/yTools.Tests/DoublesTests.cs
new file mode 100644
index 0000000..08c99e0
--- /dev/null
+++ b/yTools.Tests/DoublesTests.cs
@@ -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);
+ }
+}
\ No newline at end of file
diff --git a/yTools.Tests/IntegersTests.cs b/yTools.Tests/IntegersTests.cs
index a7702b8..1f28bbe 100644
--- a/yTools.Tests/IntegersTests.cs
+++ b/yTools.Tests/IntegersTests.cs
@@ -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]
@@ -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]
diff --git a/yTools.Tests/StringsTests.cs b/yTools.Tests/StringsTests.cs
index db6faf4..f9ce3fa 100644
--- a/yTools.Tests/StringsTests.cs
+++ b/yTools.Tests/StringsTests.cs
@@ -1,4 +1,5 @@
-using System;
+using System.Globalization;
+
namespace yTools.Tests
{
[TestClass]
@@ -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]
@@ -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);
}
}
}
\ No newline at end of file
diff --git a/yTools.Tests/VectorsTests.cs b/yTools.Tests/VectorsTests.cs
new file mode 100644
index 0000000..cff46da
--- /dev/null
+++ b/yTools.Tests/VectorsTests.cs
@@ -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);
+ }
+}
\ No newline at end of file
diff --git a/yTools/Booleans.cs b/yTools/Booleans.cs
index 0b9f6fb..14e7f15 100644
--- a/yTools/Booleans.cs
+++ b/yTools/Booleans.cs
@@ -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
{
///
/// The true boolean value.
///
- public const bool TRUE = true;
+ public const bool True = true;
///
/// The false boolean value.
///
- public const bool FALSE = false;
+ public const bool False = false;
///
/// Returns the opposite of the given boolean value.
diff --git a/yTools/Doubles.cs b/yTools/Doubles.cs
index 56e8c74..d8b2bdc 100644
--- a/yTools/Doubles.cs
+++ b/yTools/Doubles.cs
@@ -8,30 +8,30 @@ public static class Doubles
///
/// The maximum number for 32-bit decimals.
///
- public const float maxFloat = float.MaxValue;
+ public const float MaxFloat = float.MaxValue;
///
/// The maximum number for 64-bit decimals.
///
- public const double maxDouble = double.MaxValue;
+ public const double MaxDouble = double.MaxValue;
///
/// The maximum number for 128-bit decimals.
///
- public const decimal maxDecimal = decimal.MaxValue;
+ public const decimal MaxDecimal = decimal.MaxValue;
#endregion
#region MinValues
///
/// The minimum number for 32-bit decimals.
///
- public const float minFloat = float.MinValue;
+ public const float MinFloat = float.MinValue;
///
/// The minimum number for 64-bit decimals.
///
- public const double minDouble = double.MinValue;
+ public const double MinDouble = double.MinValue;
///
/// The minimum number for 128-bit decimals.
///
- public const decimal minDecimal = decimal.MinValue;
+ public const decimal MinDecimal = decimal.MinValue;
#endregion
///
diff --git a/yTools/Integers.cs b/yTools/Integers.cs
index a3bc992..818699c 100644
--- a/yTools/Integers.cs
+++ b/yTools/Integers.cs
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace yTools
{
@@ -12,39 +9,42 @@ public static class Integers
///
/// The maximum number for 16-bit intengers.
///
- public const short maxShort = short.MaxValue;
+ public const short MaxShort = short.MaxValue;
///
/// The maximum number for 32-bit intengers.
///
- public const int maxInt = int.MaxValue;
+ public const int MaxInt = int.MaxValue;
///
/// The maximum number for 64-bit intengers.
///
- public const long maxLong = long.MaxValue;
+ public const long MaxLong = long.MaxValue;
#endregion
#region MinValues
///
/// The minimum number for 16-bit intengers.
///
- public const short minShort = short.MinValue;
+ public const short MinShort = short.MinValue;
///
/// The minimum number for 32-bit intengers.
///
- public const int minInt = int.MinValue;
+ public const int MinInt = int.MinValue;
///
/// The minimum number for 64-bit intengers.
///
- public const long minLong = long.MinValue;
+ public const long MinLong = long.MinValue;
#endregion
///
/// The pi constant.
///
- public const double PI = Math.PI;
+ public const double Pi = Math.PI;
+
+ public static List PrimeNumbersProp => PrimeNumbers;
+ public static List NotPrimeNumbersProp => NotPrimeNumbers;
- static readonly List primeNumbers = new List();
- static readonly List notPrimeNumbers = new List();
+ private static readonly List PrimeNumbers = new List();
+ private static readonly List NotPrimeNumbers = new List();
///
/// Returns true if the given number is prime.
@@ -56,19 +56,19 @@ public static bool IsPrime(long number)
if (number == 2) return true;
if (number % 2 == 0) return false;
- if (primeNumbers.Contains(number)) return true;
- if (notPrimeNumbers.Contains(number)) return false;
+ if (PrimeNumbers.Contains(number)) return true;
+ if (NotPrimeNumbers.Contains(number)) return false;
var boundary = (int)Math.Floor(Math.Sqrt(number));
for (int i = 3; i <= boundary; i += 2)
if (number % i == 0)
{
- notPrimeNumbers.Add(number);
+ NotPrimeNumbers.Add(number);
return false;
}
- primeNumbers.Add(number);
+ PrimeNumbers.Add(number);
return true;
}
diff --git a/yTools/Strings.cs b/yTools/Strings.cs
index fb7d659..628ca4c 100644
--- a/yTools/Strings.cs
+++ b/yTools/Strings.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -93,6 +94,6 @@ public static string JoinChars(params char[] chars)
///
/// The value to convert. Its type must be a descendand of IConvertible.
/// A string representation of the given input. May be null.
- public static string? ToString(IConvertible value) => value.ToString();
+ public static string? ToString(IConvertible value) => value.ToString(CultureInfo.InvariantCulture);
}
}
diff --git a/yTools/Vectors.cs b/yTools/Vectors.cs
deleted file mode 100644
index 8eb3739..0000000
--- a/yTools/Vectors.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-namespace yTools
-{
- public static class Vectors
- {
- public struct Vector2
- {
- public double x, y;
-
- public Vector2(double x, double y)
- {
- this.x = x;
- this.y = y;
- }
-
- public override string ToString() => $"{x},{y}";
-
- public static explicit operator System.Numerics.Vector2(Vector2 vector2) => new System.Numerics.Vector2((float)vector2.x, (float)vector2.y);
-
- public static implicit operator Vector2(System.Numerics.Vector2 vector2) => new Vector2(vector2.X, vector2.Y);
- }
-
- public struct Vector3
- {
- public double x, y, z;
-
- public Vector3(double x, double y, double z)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
-
- public override string ToString() => $"{x},{y}";
-
- public static explicit operator System.Numerics.Vector3(Vector3 vector3) => new System.Numerics.Vector3((float)vector3.x, (float)vector3.y, (float)vector3.z);
-
- public static implicit operator Vector3(System.Numerics.Vector3 vector3) => new Vector3(vector3.X, vector3.Y, vector3.Z);
- }
- }
-}
diff --git a/yTools/Vectors/Vectors.cs b/yTools/Vectors/Vectors.cs
new file mode 100644
index 0000000..878b578
--- /dev/null
+++ b/yTools/Vectors/Vectors.cs
@@ -0,0 +1,43 @@
+namespace yTools.Vectors
+{
+ public struct Vector2
+ {
+ public double X { get; set; }
+ public double Y { get; set; }
+
+ public Vector2(double x, double y)
+ {
+ this.X = x;
+ this.Y = y;
+ }
+
+ public override string ToString() => $"{X},{Y}";
+
+ public static explicit operator System.Numerics.Vector2(Vector2 vector2) =>
+ new System.Numerics.Vector2((float)vector2.X, (float)vector2.Y);
+
+ public static implicit operator Vector2(System.Numerics.Vector2 vector2) => new Vector2(vector2.X, vector2.Y);
+ }
+
+ public struct Vector3
+ {
+ public double X { get; set; }
+ public double Y { get; set; }
+ public double Z { get; set; }
+
+ public Vector3(double x, double y, double z)
+ {
+ this.X = x;
+ this.Y = y;
+ this.Z = z;
+ }
+
+ public override string ToString() => $"{X},{Y},{Z}";
+
+ public static explicit operator System.Numerics.Vector3(Vector3 vector3) =>
+ new System.Numerics.Vector3((float)vector3.X, (float)vector3.Y, (float)vector3.Z);
+
+ public static implicit operator Vector3(System.Numerics.Vector3 vector3) =>
+ new Vector3(vector3.X, vector3.Y, vector3.Z);
+ }
+}
\ No newline at end of file