From 527108dcdb16bec1b6ba7ba19d36dfd022d10250 Mon Sep 17 00:00:00 2001 From: Jasper Date: Sat, 30 Dec 2017 12:22:26 +0100 Subject: [PATCH] Added tests for Math.Exp and Math.Pow --- .../System/MathTest.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/MathTest.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/MathTest.cs index eb02c05d5..0c1bc4a76 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/MathTest.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/MathTest.cs @@ -6,7 +6,7 @@ using Cosmos.Compiler.Tests.Bcl.Helper; namespace Cosmos.Compiler.Tests.Bcl.System { - class MathTest + internal class MathTest { public static void Execute() { @@ -35,6 +35,41 @@ namespace Cosmos.Compiler.Tests.Bcl.System // Test with positive infinity result = Math.Sqrt(double.PositiveInfinity); Assert.IsTrue(double.IsPositiveInfinity(result), "Sqrt of PositiveInfinity must return PositiveInfinity"); + + #region Math.Exp + + //Test with integer + result = Math.Exp(2); + Assert.IsTrue((result == 7.38905609893065), "e^2 is equal to 7.38905609893065"); + + //Test with double exponent + result = Math.Exp(1.5); + Assert.IsTrue(EqualityHelper.DoublesAreEqual(result, 4.48168907033806), "e^1.5 returns correct result"); + + #endregion Math.Exp + + #region Math.Pow + + //Test with integer power + result = Math.Pow(2, 2); + Assert.IsTrue(EqualityHelper.DoublesAreEqual(result, 4), "2^2 gives accurate result"); + + //Test with decimal power + result = Math.Pow(9, 0.5); + Assert.IsTrue(EqualityHelper.DoublesAreEqual(result, Math.Sqrt(9)), "9^0.5 gives same answer as sqrt(9)"); + + //Test with negative base + result = Math.Pow(-2, 2); + Assert.IsTrue(EqualityHelper.DoublesAreEqual(result, 4), "Math.Pow gives correct result when raising negative number to even power"); + + result = Math.Pow(-2, 3); + Assert.IsTrue(EqualityHelper.DoublesAreEqual(result, -8), "Math.Pow gives correct result when raising negative number to odd power"); + + //Test with negative power + result = Math.Pow(2, -1); + Assert.IsTrue(EqualityHelper.DoublesAreEqual(result, 0.5), "Pow gives correct results when handling negative powers"); + + #endregion Math.Pow } } }