From cc9d349b125e98ce39defa7c5180fb00c779779d Mon Sep 17 00:00:00 2001 From: fanoI Date: Wed, 30 Mar 2016 22:04:02 +0200 Subject: [PATCH 1/2] - Added Bitconverter tests (fails for Double) - Added to tests of Long and Ulong conversion between them --- .../Cosmos.Compiler.Tests.Bcl.csproj | 1 + Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs | 1 + .../System/BitConverterTest.cs | 53 +++++++++++++++++++ .../System/Int64Test.cs | 8 ++- .../System/UInt64Test.cs | 8 ++- 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/Cosmos.Compiler.Tests.Bcl.csproj b/Tests/Cosmos.Compiler.Tests.Bcl/Cosmos.Compiler.Tests.Bcl.csproj index 392913276..2cdfd269f 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/Cosmos.Compiler.Tests.Bcl.csproj +++ b/Tests/Cosmos.Compiler.Tests.Bcl/Cosmos.Compiler.Tests.Bcl.csproj @@ -80,6 +80,7 @@ + diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs b/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs index 7a774cd65..3545b6501 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs @@ -36,6 +36,7 @@ namespace Cosmos.Compiler.Tests.Bcl CharTest.Execute(); BooleanTest.Execute(); SingleTest.Execute(); + BitConverterTest.Execute(); DoubleTest.Execute(); DecimalTest.Execute(); System.Collections.Generic.ListTest.Execute(); diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs new file mode 100644 index 000000000..b158dd5e7 --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs @@ -0,0 +1,53 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Cosmos.TestRunner; + +namespace Cosmos.Compiler.Tests.Bcl.System +{ + class BitConverterTest + { + public static void Execute() + { + String result; + String expectedResult; + + int anInt = 1; + + byte[] intBytes = BitConverter.GetBytes(anInt); + + result = BitConverter.ToString(intBytes, 0); + expectedResult = "01-00-00-00"; + + Assert.IsTrue((result == expectedResult), "BitConverter.ToString(intBytes) doesn't work: result " + result + " != " + expectedResult); + + long aLong = 1; + + byte[] longBytes = BitConverter.GetBytes(aLong); + + result = BitConverter.ToString(longBytes, 0); + expectedResult = "01-00-00-00-00-00-00-00"; + + Assert.IsTrue((result == expectedResult), "BitConverter.ToString(longBytes) doesn't work: result " + result + " != " + expectedResult); + + ulong anULong = 1; + + byte[] ulongBytes = BitConverter.GetBytes(anULong); + + result = BitConverter.ToString(ulongBytes, 0); + expectedResult = "01-00-00-00-00-00-00-00"; + + Assert.IsTrue((result == expectedResult), "BitConverter.ToString(ulongBytes) doesn't work: result " + result + " != " + expectedResult); + + // This test fails bytes are screwed! + double aDouble = 1.0; + + byte[] doubleBytes = BitConverter.GetBytes(aDouble); + + result = BitConverter.ToString(doubleBytes, 0); + expectedResult = "00-00-00-00-00-00-F0-3F"; + + Assert.IsTrue((result == expectedResult), "BitConverter.ToString(doubleBytes) doesn't work: result " + result + " != " + expectedResult); + } + } +} diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs index e71c18728..0a9538e6c 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs @@ -37,7 +37,13 @@ namespace Cosmos.Compiler.Tests.Bcl.System // actually the Hash Code of a Int64 is the value interpolated with XOR to obtain an Int32... so not the same of 'value'! int expectedResultAsInt = (unchecked((int)((long)value)) ^ (int)(value >> 32)); - Assert.IsTrue((resultAsInt == expectedResultAsInt), "Int64.GetHashCode() doesn't work"); // XXX TODO when GetHashCode() works + Assert.IsTrue((resultAsInt == expectedResultAsInt), "Int64.GetHashCode() doesn't work"); + + // Let's try to convert a Long in a ULong + Int64 val2 = 42; + UInt64 val2AsULong = (ulong)val2; + + Assert.IsTrue((val2AsULong == 42), "Int64 to UInt64 conversion does not work"); #if false // Now let's try ToString() again but printed in hex (this test fails for now!) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs index 65040b55c..f793917fc 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs @@ -40,7 +40,13 @@ namespace Cosmos.Compiler.Tests.Bcl.System // actually the Hash Code of a Int64 is the value interpolated with XOR to obtain an Int32... so not the same of 'value'! int expectedResultAsInt = ((int)value) ^ (int)(value >> 32); - Assert.IsTrue((resultAsInt == expectedResultAsInt), "UInt64.GetHashCode() doesn't work"); // XXX TODO when GetHashCode() works + Assert.IsTrue((resultAsInt == expectedResultAsInt), "UInt64.GetHashCode() doesn't work"); + + // Let's try to convert an ULong in a Long + UInt64 val2 = 42; + Int64 val2AsLong = (long)val2; + + Assert.IsTrue((val2AsLong == 42), "UInt64 to Int64 conversion does not work"); #if false // Now let's try ToString() again but printed in hex (this test fails for now!) From 66a834bbce5932f8fcdd32dca5019fcbe68213c9 Mon Sep 17 00:00:00 2001 From: fanoI Date: Thu, 31 Mar 2016 01:21:24 +0200 Subject: [PATCH 2/2] Added Bitconveter test of floats (that have success!) --- .../System/BitConverterTest.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs b/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs index b158dd5e7..9ce3c4da9 100644 --- a/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs @@ -39,7 +39,17 @@ namespace Cosmos.Compiler.Tests.Bcl.System Assert.IsTrue((result == expectedResult), "BitConverter.ToString(ulongBytes) doesn't work: result " + result + " != " + expectedResult); - // This test fails bytes are screwed! + // These tests fails bytes are screwed! + + float aFloat = 1.0f; + + byte[] floatBytes = BitConverter.GetBytes(aFloat); + + result = BitConverter.ToString(floatBytes, 0); + expectedResult = "00-00-80-3F"; + + Assert.IsTrue((result == expectedResult), "BitConverter.ToString(floatBytes) doesn't work: result " + result + " != " + expectedResult); + double aDouble = 1.0; byte[] doubleBytes = BitConverter.GetBytes(aDouble); @@ -48,6 +58,8 @@ namespace Cosmos.Compiler.Tests.Bcl.System expectedResult = "00-00-00-00-00-00-F0-3F"; Assert.IsTrue((result == expectedResult), "BitConverter.ToString(doubleBytes) doesn't work: result " + result + " != " + expectedResult); + + } } }