Cosmos/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
2016-09-11 07:53:45 -05:00

66 lines
2.2 KiB
C#

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 works, what is the difference with double? That is saved as an Int32 in oly a register?
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);
//// This tests 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);
}
}
}