Move IO-related bool extensions to IO namespace (#7)

This commit is contained in:
Oliver Booth 2022-04-25 22:26:22 +01:00
parent e058ab75bc
commit 433d365a89
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
3 changed files with 34 additions and 33 deletions

View File

@ -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);
}
}

View 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));
}
}

View File

@ -1,4 +1,4 @@
namespace X10D;
namespace X10D.IO;
/// <summary>
/// Extension methods for <see cref="bool" />.