Cosmos/Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
fanoI ad960c9a1a Continuation of Float work
- Fixed Single.ToString() on special cases (infinities, NaN and 0) and aumented the range of printable values
- Fixed Double.ToString(): it always printed "Double Overrange" for a bug in opcode ldarga
- Fixed opcode ldarga: the displacement of the argument variable was off of 4 bytes
- Fixed opcodes shr, shr_un and shl when the shift was more that 32 bytes, added to BCL relative tests
- Added BLC tests regarding BitConverter and unsafe code
- Moved the meat of the code of Single.ToString() and Double.ToString() to the class StringHelper together with the analogous methods for numer types
- Re-added _floatsignbit to CosmosAssembler.cs so the neg test should not fail anymore
- Removed all code relative to x87 that I had left under #if false
- Clean up
2016-08-22 16:31:22 +02: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);
}
}
}