Cosmos/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
fanoI 58c556f085 - Initial work as for https://github.com/CosmosOS/Cosmos/issues/359
- Added Console.Clear() to Guess Demo (the boot text remained on screen)
- Added to BCL test BitConverterTest (all failing), test for single / double arithmetic operations
- Added to TestRunner BCLTest
2016-05-21 18:55:39 +02:00

67 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);
}
}
}