mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 14:02:19 +00:00
Added tests for all BitConverter Methods
This commit is contained in:
parent
fc224649f8
commit
c59bf1e4e3
1 changed files with 76 additions and 8 deletions
|
|
@ -11,6 +11,13 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
||||||
string result;
|
string result;
|
||||||
string expectedResult;
|
string expectedResult;
|
||||||
|
|
||||||
|
short aShort = 1;
|
||||||
|
byte[] shortBytes = BitConverter.GetBytes(aShort);
|
||||||
|
result = BitConverter.ToString(shortBytes);
|
||||||
|
expectedResult = "01-00";
|
||||||
|
|
||||||
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(shortBytes) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
int anInt = 1;
|
int anInt = 1;
|
||||||
|
|
||||||
byte[] intBytes = BitConverter.GetBytes(anInt);
|
byte[] intBytes = BitConverter.GetBytes(anInt);
|
||||||
|
|
@ -29,6 +36,22 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
||||||
|
|
||||||
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(longBytes) doesn't work: result " + result + " != " + expectedResult);
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(longBytes) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
|
ushort anUShort = 1;
|
||||||
|
byte[] ushortBytes = BitConverter.GetBytes(anUShort);
|
||||||
|
result = BitConverter.ToString(ushortBytes);
|
||||||
|
expectedResult = "01-00";
|
||||||
|
|
||||||
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(ushortBytes) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
|
uint anUInt = 1;
|
||||||
|
|
||||||
|
byte[] uintBytes = BitConverter.GetBytes(anUInt);
|
||||||
|
|
||||||
|
result = BitConverter.ToString(uintBytes, 0);
|
||||||
|
expectedResult = "01-00-00-00";
|
||||||
|
|
||||||
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(uintBytes) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
ulong anULong = 1;
|
ulong anULong = 1;
|
||||||
|
|
||||||
byte[] ulongBytes = BitConverter.GetBytes(anULong);
|
byte[] ulongBytes = BitConverter.GetBytes(anULong);
|
||||||
|
|
@ -48,6 +71,55 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
||||||
|
|
||||||
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(floatBytes) doesn't work: result " + result + " != " + expectedResult);
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(floatBytes) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
|
double aDouble = 1.0;
|
||||||
|
result = BitConverter.ToString(BitConverter.GetBytes(aDouble));
|
||||||
|
expectedResult = "00-00-00-00-00-00-F0-3F";
|
||||||
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(doubleBytes) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
|
bool aBool = true;
|
||||||
|
result = BitConverter.ToString(BitConverter.GetBytes(aBool));
|
||||||
|
expectedResult = "01";
|
||||||
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(bool) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
|
char aChar = 'X';
|
||||||
|
result = BitConverter.ToString(BitConverter.GetBytes(aChar));
|
||||||
|
expectedResult = "58-00";
|
||||||
|
Assert.IsTrue((result == expectedResult), "BitConverter.ToString(char) doesn't work: result " + result + " != " + expectedResult);
|
||||||
|
|
||||||
|
//Tests for GetBytes and ToXXX
|
||||||
|
aShort = 240;
|
||||||
|
Assert.IsTrue(BitConverter.ToInt16(BitConverter.GetBytes(aShort), 0) == aShort, "BitConverter works with Int16");
|
||||||
|
|
||||||
|
aShort = -240;
|
||||||
|
Assert.IsTrue(BitConverter.ToInt16(BitConverter.GetBytes(aShort), 0) == aShort, "BitConverter works with negativ Int16");
|
||||||
|
|
||||||
|
anInt = 1234;
|
||||||
|
Assert.IsTrue(BitConverter.ToInt32(BitConverter.GetBytes(anInt), 0) == anInt, "BitConverter works with Int32");
|
||||||
|
|
||||||
|
anInt = -1234;
|
||||||
|
Assert.IsTrue(BitConverter.ToInt32(BitConverter.GetBytes(anInt), 0) == anInt, "BitConverter works with negative Int32");
|
||||||
|
|
||||||
|
aLong = 123456789000;
|
||||||
|
Assert.IsTrue(BitConverter.ToInt64(BitConverter.GetBytes(aLong), 0) == aLong, "BitConvert works with Int64");
|
||||||
|
|
||||||
|
aLong = -123456789000;
|
||||||
|
Assert.IsTrue(BitConverter.ToInt64(BitConverter.GetBytes(aLong), 0) == aLong, "BitConvert works with negative Int64");
|
||||||
|
|
||||||
|
anUShort = 240;
|
||||||
|
Assert.IsTrue(BitConverter.ToUInt16(BitConverter.GetBytes(anUShort), 0) == anUShort, "BitConverter works with UInt16");
|
||||||
|
|
||||||
|
anUInt = 1233346;
|
||||||
|
Assert.IsTrue(BitConverter.ToUInt32(BitConverter.GetBytes(anUInt), 0) == anUInt, "BitConverter works with UInt32");
|
||||||
|
|
||||||
|
anULong = 123456789000;
|
||||||
|
Assert.IsTrue(BitConverter.ToUInt64(BitConverter.GetBytes(anULong), 0) == anULong, "BitConverter works with UInt64");
|
||||||
|
|
||||||
|
aBool = false;
|
||||||
|
Assert.IsTrue(BitConverter.ToBoolean(BitConverter.GetBytes(aBool), 0) == aBool, "BitConverter works with Bool");
|
||||||
|
|
||||||
|
aChar = 'C';
|
||||||
|
Assert.IsTrue(BitConverter.ToChar(BitConverter.GetBytes(aChar), 0) == aChar, "BitConverter works with Char");
|
||||||
|
|
||||||
double Result;
|
double Result;
|
||||||
byte[] doubleBytes = BitConverter.GetBytes(0d);
|
byte[] doubleBytes = BitConverter.GetBytes(0d);
|
||||||
Result = BitConverter.ToDouble(doubleBytes, 0);
|
Result = BitConverter.ToDouble(doubleBytes, 0);
|
||||||
|
|
@ -77,14 +149,10 @@ namespace Cosmos.Compiler.Tests.Bcl.System
|
||||||
Result = BitConverter.ToDouble(doubleBytes, 0);
|
Result = BitConverter.ToDouble(doubleBytes, 0);
|
||||||
Assert.IsTrue(Result == -1.2345, "BitConverter.ToDouble works with -1.2345");
|
Assert.IsTrue(Result == -1.2345, "BitConverter.ToDouble works with -1.2345");
|
||||||
|
|
||||||
double aDouble = 1.0;
|
//Conversion between doubles and long
|
||||||
|
Assert.IsTrue(BitConverter.Int64BitsToDouble(1) == 4.94065645841247E-324, "BitConverter long bits to double works");
|
||||||
|
Assert.IsTrue(BitConverter.DoubleToInt64Bits(4.94065645841247E-324) == 1, "BitConverter double to long bits works");
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue