mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 05:52:11 +00:00
Merge pull request #348 from fanoI/master
- Added Bitconverter tests (fails for Double)
This commit is contained in:
commit
a57be9d675
5 changed files with 81 additions and 2 deletions
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ namespace Cosmos.Compiler.Tests.Bcl
|
|||
CharTest.Execute();
|
||||
BooleanTest.Execute();
|
||||
SingleTest.Execute();
|
||||
BitConverterTest.Execute();
|
||||
DoubleTest.Execute();
|
||||
DecimalTest.Execute();
|
||||
System.Collections.Generic.ListTest.Execute();
|
||||
|
|
|
|||
65
Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
Normal file
65
Tests/Cosmos.Compiler.Tests.Bcl/System/BitConverterTest.cs
Normal file
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,13 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
// 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!)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,13 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
|||
// 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!)
|
||||
|
|
|
|||
Loading…
Reference in a new issue