-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix order of bytes in decimal write bytes methods
- Loading branch information
1 parent
e5e27c0
commit 68197ef
Showing
4 changed files
with
75 additions
and
54 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
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,54 @@ | ||
using NUnit.Framework; | ||
using X10D.IO; | ||
|
||
namespace X10D.Tests.IO; | ||
|
||
[TestFixture] | ||
internal class DecimalTests | ||
{ | ||
[Test] | ||
public void GetBigEndianBytes_ShouldReturnBytes_InBigEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; | ||
|
||
byte[] bytes = value.GetBigEndianBytes(); | ||
|
||
CollectionAssert.AreEqual(expected, bytes); | ||
} | ||
|
||
[Test] | ||
public void GetLittleEndianBytes_ShouldReturnBytes_InLittleEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
|
||
byte[] bytes = value.GetLittleEndianBytes(); | ||
|
||
CollectionAssert.AreEqual(expected, bytes); | ||
} | ||
|
||
[Test] | ||
public void TryWriteBigEndianBytes_ShouldWriteBytes_InBigEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210]; | ||
|
||
Span<byte> bytes = stackalloc byte[16]; | ||
value.TryWriteBigEndianBytes(bytes); | ||
|
||
CollectionAssert.AreEqual(expected, bytes.ToArray()); | ||
} | ||
|
||
[Test] | ||
public void TryWriteLittleEndianBytes_ShouldWriteBytes_InLittleEndian() | ||
{ | ||
const decimal value = 1234m; | ||
byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
|
||
Span<byte> bytes = stackalloc byte[16]; | ||
value.TryWriteLittleEndianBytes(bytes); | ||
|
||
CollectionAssert.AreEqual(expected, bytes.ToArray()); | ||
} | ||
} |
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