-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hack for fp-determinism across Unity and .NET 8
- Loading branch information
Showing
5 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
using ByteSerialization.IO; | ||
using Xunit; | ||
|
||
namespace ByteSerialization.Tests.Unit.IO | ||
{ | ||
public class EndianBinaryReaderTest | ||
{ | ||
[Fact] | ||
public void Test_ReadSingle_BE() => | ||
AssertReadResult(13.5407705f, "4158 a6ff", Endianness.BigEndian, r => r.ReadSingle()); | ||
|
||
private void AssertReadResult<T>(T expectedValue, string hexStringToRead, Endianness endianness, Func<EndianBinaryReader, T> readFunc) | ||
{ | ||
using var ms = new MemoryStream(HexStringConverter.ToByteArray(hexStringToRead)); | ||
using var reader = new EndianBinaryReader(ms, endianness); | ||
T actualValue = readFunc.Invoke(reader); | ||
Assert.Equal(expectedValue, actualValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
using ByteSerialization.IO; | ||
using Xunit; | ||
|
||
namespace ByteSerialization.Tests.Unit.IO | ||
{ | ||
public class EndianBinaryWriterTest | ||
{ | ||
[Fact] | ||
public void Test_WriteSingle_BE() => | ||
AssertWriteResult("4158 a6ff", 13.5407705f, Endianness.BigEndian, (r, x) => r.Write(x)); | ||
|
||
private void AssertWriteResult<T>(string expectedHexString, T valueToWrite, Endianness endianness, Action<EndianBinaryWriter, T> writeFunc) | ||
{ | ||
using var ms = new MemoryStream(); | ||
using var writer = new EndianBinaryWriter(ms, endianness); | ||
writeFunc.Invoke(writer, valueToWrite); | ||
byte[] actualBytes = ms.ToArray(); | ||
byte[] expectedBytes = HexStringConverter.ToByteArray(expectedHexString); | ||
Assert.True(Enumerable.SequenceEqual(expectedBytes, actualBytes)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters