Пример #1
0
        public static IEnumerable <object[]> LogicalXor_Test_Values()
        {
            foreach (var(left, right) in Values())
            {
                var expected = new FixedBytes(ByteArrayUtils.BitwiseXorBigEndian(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 });
            }
        }
Пример #2
0
 public void BitwiseXorBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left,
                                                                            byte[] right)
 {
     // Arrange
     // Act
     // Assert
     Assert.Throws <ArgumentNullException>(() => ByteArrayUtils.BitwiseXorBigEndian(left, right));
 }
Пример #3
0
        public void BitwiseXorBigEndian_Test(byte[] expected,
                                             byte[] left,
                                             byte[] right)
        {
            // Arrange
            var leftOriginal  = left.ToArray();
            var rightOriginal = right.ToArray();

            // Act
            var result = ByteArrayUtils.BitwiseXorBigEndian(left, right);

            // Assert
            Assert.Equal(expected, result);

            Assert.Equal(leftOriginal, left);   // input value not affected
            Assert.Equal(rightOriginal, right); // input value not affected
        }
Пример #4
0
        public static void BitwiseXorBigEndianExample()
        {
            // Setup
            var lhs = new byte[] { 0xC0, 0xDE };
            var rhs = new byte[] { 0xC0, 0xFF, 0xEE };

            // Act
            var result = ByteArrayUtils.BitwiseXorBigEndian(lhs, rhs);

            // Conclusion
            Console.WriteLine("BitwiseXorBigEndian 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);
        }