Skip to content

Commit

Permalink
Merge pull request CosmosOS#348 from fanoI/master
Browse files Browse the repository at this point in the history
- Added Bitconverter tests (fails for Double)
  • Loading branch information
charlesbetros committed Apr 2, 2016
2 parents 653b7a8 + 66a834b commit a57be9d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ItemGroup>
<Compile Include="Kernel.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="System\BitConverterTest.cs" />
<Compile Include="System\BooleanTest.cs" />
<Compile Include="System\ByteTest.cs" />
<Compile Include="System\CharTest.cs" />
Expand Down
1 change: 1 addition & 0 deletions Tests/Cosmos.Compiler.Tests.Bcl/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected override void Run()
CharTest.Execute();
BooleanTest.Execute();
SingleTest.Execute();
BitConverterTest.Execute();
DoubleTest.Execute();
DecimalTest.Execute();
System.Collections.Generic.ListTest.Execute();
Expand Down
65 changes: 65 additions & 0 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
Original file line number Diff line number Diff line change
@@ -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);


}
}
}
8 changes: 7 additions & 1 deletion Tests/Cosmos.Compiler.Tests.Bcl/System/Int64Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public static void Execute()
// 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!)
Expand Down
8 changes: 7 additions & 1 deletion Tests/Cosmos.Compiler.Tests.Bcl/System/UInt64Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ public static void Execute()
// 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!)
Expand Down

0 comments on commit a57be9d

Please sign in to comment.