public static void TestOperatorAndDiffSizes(int t1, int s1, int t2, int s2, string expected, string testOp) { // Arrange var testObj1 = new DataStructures.BitArray.BitArray(s1); var testObj2 = new DataStructures.BitArray.BitArray(s2); // Act testObj1.Compile(t1); testObj2.Compile(t2); DataStructures.BitArray.BitArray result = null; if (testOp.Equals("AND")) { result = testObj1 & testObj2; } else if (testOp.Equals("OR")) { result = testObj1 | testObj2; } else { result = testObj1 ^ testObj2; } // Assert Assert.AreEqual(expected, result.ToString()); }
public static void TestCompileInteger(int number, string expected) { // Arrange var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(number); // Assert Assert.AreEqual(expected, testObj.ToString()); }
public static void CurrentThrowsException() { // Arragne var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(16); // Assert _ = Assert.Throws <InvalidOperationException>(() => _ = testObj.Current); }
public static void TestToInt64(int number, int expected) { // Arrange var testObj = new DataStructures.BitArray.BitArray(6); // Act testObj.Compile(number); // Assert Assert.AreEqual(expected, testObj.ToInt64()); }
public static void TestNumberOfZeroBits(int number, int expected) { // Arrange var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(number); // Assert Assert.AreEqual(expected, testObj.NumberOfZeroBits()); }
public static void TestCompileToString(string sequence, string expectedSequence) { // Arrange var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(sequence); // Assert Assert.AreEqual(expectedSequence, testObj.ToString()); }
public static void TestParity() { // Arrange var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(26); // Assert Assert.IsFalse(testObj.EvenParity()); Assert.IsTrue(testObj.OddParity()); }
public static void TestOperatorShiftRight(int number, string expected) { // Arrange var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(number); testObj >>= 2; // Assert Assert.AreEqual(expected, testObj.ToString()); }
public static void TestIndexer() { // Arrange var testObj = new DataStructures.BitArray.BitArray(5); // Act testObj.Compile(24); // Assert Assert.IsTrue(testObj[0]); Assert.IsTrue(testObj[1]); Assert.IsFalse(testObj[3]); }
public static void TestCompileIntegerThrowsException(int number, string expectedErrorMsg, int arrayLength) { // Arrange var testObj = new DataStructures.BitArray.BitArray(arrayLength); // Act void Act() => testObj.Compile(number); // Assert var ex = Assert.Throws <Exception>(Act); Assert.AreEqual(expectedErrorMsg, ex.Message); }
public static void TestHasCode() { // Arrange const int num = 5; var testObj = new DataStructures.BitArray.BitArray(3); // Act testObj.Compile(num); var result = testObj.GetHashCode(); // Assert Assert.NotNull(result); Assert.AreEqual(5, result); }
public static void TestCompileLongThrowsException(int number, int arrLen) { // Arrange var testObj = new DataStructures.BitArray.BitArray(arrLen); // Act void Act() => testObj.Compile((long)number); // Assert var ex = Assert.Throws <Exception>(Act); Assert.AreEqual(number < 0 ? "Compile: only positive numbers > 0" : "Compile: not apt length!", ex.Message); }
public static void TestOperatorXor(int testNum, int testNum2, int expected) { // Arrange var testObj1 = new DataStructures.BitArray.BitArray(5); var testObj2 = new DataStructures.BitArray.BitArray(5); // Act testObj1.Compile(testNum); testObj2.Compile(testNum2); var result = testObj1 ^ testObj2; // Assert Assert.AreEqual(expected, result.ToInt32()); }
public static void TestOperatorOr(int tObj1, int tObj2, string expected) { // Arrange var testObj1 = new DataStructures.BitArray.BitArray(5); var testObj2 = new DataStructures.BitArray.BitArray(5); // Act testObj1.Compile(tObj1); testObj2.Compile(tObj2); var result = testObj1 | testObj2; // Assert Assert.AreEqual(expected, result.ToString()); }
public static void TestCompileToStringThorwsException(string sequence, int arrLen) { // Arrange var testObj = new DataStructures.BitArray.BitArray(arrLen); // Act void Act() => testObj.Compile(sequence); // Assert var ex = Assert.Throws <Exception>(Act); if (sequence.Length > arrLen || sequence.Length < arrLen) { Assert.AreEqual("Compile: not equal length!", ex.Message); } }