mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:25:43 +00:00
Move IO-related bool extensions to IO namespace (#7)
This commit is contained in:
parent
e058ab75bc
commit
433d365a89
@ -1,32 +0,0 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace X10D.Tests.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="BooleanExtensions" />.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class BooleanTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests <see cref="BooleanExtensions.GetBytes" />.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GetBytes()
|
||||
{
|
||||
const bool trueValue = true;
|
||||
const bool falseValue = false;
|
||||
|
||||
var trueBytes = new byte[] { 0x01 };
|
||||
var falseBytes = new byte[] { 0x00 };
|
||||
|
||||
byte[] trueResult = trueValue.GetBytes();
|
||||
byte[] falseResult = falseValue.GetBytes();
|
||||
|
||||
Assert.AreEqual(1, trueResult.Length);
|
||||
Assert.AreEqual(1, trueResult.Length);
|
||||
|
||||
CollectionAssert.AreEqual(trueBytes, trueResult);
|
||||
CollectionAssert.AreEqual(falseBytes, falseResult);
|
||||
}
|
||||
}
|
33
X10D.Tests/src/IO/BooleanTests.cs
Normal file
33
X10D.Tests/src/IO/BooleanTests.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.IO;
|
||||
|
||||
namespace X10D.Tests.IO;
|
||||
|
||||
[TestClass]
|
||||
public class BooleanTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void GetBytes_ReturnsArrayContaining1()
|
||||
{
|
||||
const bool value = true;
|
||||
CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TryWriteBytes_ReturnsTrue_FillsSpanContaining1_GivenLargeEnoughSpan()
|
||||
{
|
||||
const bool value = true;
|
||||
Span<byte> buffer = stackalloc byte[1];
|
||||
Assert.IsTrue(value.TryWriteBytes(buffer));
|
||||
CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TryWriteBytes_ReturnsFalse_GivenSmallSpan()
|
||||
{
|
||||
const bool value = true;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.IsFalse(value.TryWriteBytes(buffer));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace X10D;
|
||||
namespace X10D.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="bool" />.
|
||||
|
Loading…
Reference in New Issue
Block a user