public static IEnumerable <object[]> LogicalAnd_Test_Values() { foreach (var(left, right) in Values()) { var expected = new FixedBytes(ByteArrayUtils.BitwiseAndBigEndian(left, right)); yield return(new object[] { expected, new FixedBytes(left), new FixedBytes(right) }); } yield return(new object[] { null, null, new FixedBytes(new byte[] { 0xFF }) }); yield return(new object[] { null, new FixedBytes(new byte[] { 0xFF }), null }); yield return(new object[] { null, null, null }); IEnumerable <(byte[] left, byte[] right)> Values() { yield return(new byte[] { 0xFF }, Array.Empty <byte>()); yield return(new byte[] { 0x00 }, new byte[] { 0x00 }); yield return(new byte[] { 0xF0 }, new byte[] { 0x0F }); yield return(new byte[] { 0x42 }, new byte[] { 0xBD }); yield return(new byte[] { 0xFF }, new byte[] { 0xBD }); yield return(new byte[] { 0xFF, 0xFF }, new byte[] { 0xBD }); } }
public void BitwiseAndBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left, byte[] right) { // Arrange // Act // Assert Assert.Throws <ArgumentNullException>(() => ByteArrayUtils.BitwiseAndBigEndian(left, right)); }
public void BitwiseAndBigEndian_Test(byte[] expected, byte[] left, byte[] right) { // Arrange var leftOriginal = left.ToArray(); var rightOriginal = right.ToArray(); // Act var result = ByteArrayUtils.BitwiseAndBigEndian(left, right); // Assert Assert.Equal(expected, result); Assert.Equal(leftOriginal, left); // input value not affected Assert.Equal(rightOriginal, right); // input value not affected }
public static void BitwiseAndBigEndianExample() { // Setup var lhs = new byte[] { 0xC0, 0xDE }; var rhs = new byte[] { 0xC0, 0xFF, 0xEE }; // Act var result = ByteArrayUtils.BitwiseAndBigEndian(lhs, rhs); // Conclusion Console.WriteLine("BitwiseAndBigEndian Example"); Console.WriteLine($"lhs:\t{lhs.ToString("H")}"); Console.WriteLine($"rhs:\t{rhs.ToString("H")}"); Console.WriteLine($"result:\t{result.ToString("H")}"); Console.WriteLine(string.Empty); Console.WriteLine($"lhs:\t{lhs.ToString("b")}"); Console.WriteLine($"rhs:\t{rhs.ToString("b")}"); Console.WriteLine($"result:\t{result.ToString("b")}"); Console.WriteLine(string.Empty); }