Cosmos/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
José Pedro eff94b0f11 Improved code organization.
Added method tests.
Implemented Rethrow opcode.
2017-01-27 17:01:51 +00:00

60 lines
2 KiB
C#

using System;
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);
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);
}
}
}