Skip to content

Commit

Permalink
Moved float tests to single tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quajak committed Dec 31, 2017
1 parent c2b83a6 commit 2049d9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 48 deletions.
1 change: 0 additions & 1 deletion Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ protected override void Run()
BooleanTest.Execute();
SingleTest.Execute();
DoubleTest.Execute();
FloatTest.Execute();
MathTest.Execute();
//DecimalTest.Execute();
BitConverterTest.Execute();
Expand Down
43 changes: 0 additions & 43 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/FloatTest.cs

This file was deleted.

37 changes: 33 additions & 4 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/SingleTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Cosmos.Compiler.Tests.Bcl.Helper;
using Cosmos.TestRunner;

namespace Cosmos.Compiler.Tests.Bcl.System
{
class SingleTest
internal class SingleTest
{
/* The single== equality operator is so imprecise to not be really ever useful we should be happy if the two values are "similar" */

private static bool SinglesAreEqual(Single left, Single right)
{
// Define the tolerance for variation in their values
Single difference = (Single) Math.Abs(left * .00001);
Single difference = (Single)Math.Abs(left * .00001);

if (Math.Abs(left - right) <= difference)
return true;
Expand Down Expand Up @@ -62,7 +64,7 @@ public static void Execute()
expectedResult = "-42.42";

Assert.IsTrue((result == expectedResult), "Single.ToString of negative number doesn't work");

/* A big value (to be correct toString should convert it in scientific notation) */
value = 9223372036854775808f;

Expand All @@ -73,7 +75,7 @@ public static void Execute()

/* OK now a normal value */
value = 42.42F; // It exists Single.MaxValue but it is a too big value an can be represented only on Scientific notation but then how to confront with a String?

result = value.ToString();
expectedResult = "42.42";

Expand Down Expand Up @@ -206,6 +208,33 @@ public static void Execute()
value = 42.0f;
valueNegated = -value;
Assert.IsTrue((SinglesAreEqual(valueNegated, -42.0f)), "(float) negation of positive float doesn't work");

#region Parsing

value = float.Parse("0.4");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, 0.4), "simple parsing of float works");

value = float.Parse("+0.3");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, 0.3), "parsing of float with positive sign works!");

value = float.Parse("-0.4");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, -0.4), "parsing of negative float works!");

value = float.Parse(" 0.7 ");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, 0.7), "float parsing ignores leading and trailing whitespaces");

value = float.Parse("0.4E1");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, 4), "float parsing takes in account E");

value = float.Parse("0.4E-1");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, 0.04), "float parsing works with negative E");

Assert.IsFalse(float.TryParse("asd4", out value), "float TryParse returns false when it fails");

Assert.IsTrue(float.TryParse("2.3", out value), " float TryParse returns true when it works");
Assert.IsTrue(EqualityHelper.DoublesAreEqual(value, 2.3), "float TryParse returns correct result when it works");

#endregion Parsing
}
}
}

0 comments on commit 2049d9c

Please sign in to comment.