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..9ce3c4da9 --- /dev/null +++ b/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs @@ -0,0 +1,65 @@ +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); + + // 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); + + 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!)