Add floating-point extensions for byte arrays and streams

This commit is contained in:
Matt Nadareski
2024-04-18 11:55:25 -04:00
parent 65bdcc563d
commit a93da97bbd
4 changed files with 164 additions and 16 deletions

View File

@@ -118,6 +118,24 @@ namespace SabreTools.IO.Test
Assert.Equal((uint)0x00010203, read);
}
[Fact]
public void ReadSingleTest()
{
int offset = 0;
float expected = BitConverter.Int32BitsToSingle(0x03020100);
float read = _bytes.ReadSingle(ref offset);
Assert.Equal(expected, read);
}
[Fact]
public void ReadSingleBigEndianTest()
{
int offset = 0;
float expected = BitConverter.Int32BitsToSingle(0x00010203);
float read = _bytes.ReadSingleBigEndian(ref offset);
Assert.Equal(expected, read);
}
[Fact]
public void ReadInt64Test()
{
@@ -150,6 +168,24 @@ namespace SabreTools.IO.Test
Assert.Equal((ulong)0x0001020304050607, read);
}
[Fact]
public void ReadDoubleTest()
{
int offset = 0;
double expected = BitConverter.Int64BitsToDouble(0x0706050403020100);
double read = _bytes.ReadDouble(ref offset);
Assert.Equal(expected, read);
}
[Fact]
public void ReadDoubleBigEndianTest()
{
int offset = 0;
double expected = BitConverter.Int64BitsToDouble(0x0001020304050607);
double read = _bytes.ReadDoubleBigEndian(ref offset);
Assert.Equal(expected, read);
}
[Fact]
public void ReadGuidTest()
{