From 17c2adf6ce5ca91a6ab347bc0c0ee088958bd179 Mon Sep 17 00:00:00 2001 From: Christian Femers Date: Thu, 11 Jul 2019 21:56:11 +0200 Subject: [PATCH] Adopted tests to new BitVector and improved labeling --- .../mograsim/logic/ui/am2900/Am2901Test.java | 98 ++++++++++--------- .../logic/ui/am2900/TestableAm2901.java | 15 --- .../logic/ui/am2900/TestableAm2901Impl.java | 56 +++++------ 3 files changed, 80 insertions(+), 89 deletions(-) diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java index 21cb52f6..03790ec5 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/Am2901Test.java @@ -12,14 +12,17 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.provider.EnumSource; + import net.mograsim.logic.ui.am2900.TestableAm2901.Register; +@DisplayName("Am2901 Tests") @TestMethodOrder(OrderAnnotation.class) public class Am2901Test { @@ -87,9 +90,10 @@ public class Am2901Test am2901.assertRunSuccess(); } + @ParameterizedTest(name = "{0}") @Order(1) - @ParameterizedTest - @ArgumentsSource(TestableAm2901.RegisterProvider.class) + @DisplayName("Direct / high level access") + @EnumSource(Register.class) void testDirectAccess(Register r) { assertEquals("UUUU", am2901.getDirectly(r)); @@ -99,9 +103,10 @@ public class Am2901Test assertEquals("1011", am2901.getDirectly(r)); } + @ParameterizedTest(name = "{0}") @Order(2) - @ParameterizedTest - @ArgumentsSource(TestableAm2901.RegisterProvider.class) + @DisplayName("Setting each register to 0") + @EnumSource(Register.class) void testSetToZero(Register r) { assertEquals("UUUU", am2901.getDirectly(r)); @@ -116,8 +121,9 @@ public class Am2901Test assertEquals("1", am2901.getZero()); } - @Order(3) @Test + @Order(3) + @DisplayName("Setting all registers to 0") void testSetAllToZero() { setRegistersToZero(); @@ -138,8 +144,9 @@ public class Am2901Test })); } - @Order(4) @Test + @Order(4) + @DisplayName("ADD operation") void testADD() { am2901.setSrc(DA); @@ -159,18 +166,18 @@ public class Am2901Test int res32Bit_sgn = signed4ToSigned32(xy.x) + signed4ToSigned32(xy.y); int res4Bit_sgn = signed4ToSigned32(res32Bit_sgn); - String desc = xy.x + " + " + xy.y + " = " + res4Bit + ": "; - - assertEquals(to4bitBin(res4Bit & 0b1111), am2901.getY(), desc + "Y"); - assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), desc + "F=0"); - assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), desc + "F3"); - assertEquals(to1bitBin(res32Bit & 0b1_0000), am2901.getCarryOut(), desc + "Cn+4"); - assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), desc + "OVR"); + assertAll("Result of " + xy.x + " + " + xy.y + " = " + res32Bit, + () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"), + () -> assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), " F=0"), + () -> assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), " F3"), + () -> assertEquals(to1bitBin(res32Bit > 15), am2901.getCarryOut(), " Cn+4"), + () -> assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), " OVR")); })); } - @Order(4) @Test + @Order(4) + @DisplayName("AND operation") void testAND() { am2901.setSrc(DA); @@ -187,18 +194,19 @@ public class Am2901Test int res32Bit = xy.x & xy.y; - String desc = xy.x + " & " + xy.y + " = " + res32Bit + ": "; - - assertEquals(to4bitBin(res32Bit), am2901.getY(), desc + "Y"); - assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), desc + "F=0"); - assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), desc + "F3"); -// assertEquals(to1bitBin(res32Bit), am2901.getCarryOut(), desc + "Cn+4"); // TODO -// assertEquals(to1bitBin(res32Bit), am2901.getOverflow(), desc + "OVR"); // TODO + assertAll("Result of " + xy.x + " & " + xy.y + " = " + res32Bit, + () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"), + () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"), + () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3") +// () -> assertEquals(to1bitBin(res32Bit), am2901.getCarryOut(), " Cn+4"), // TODO +// () -> assertEquals(to1bitBin(res32Bit), am2901.getOverflow(), " OVR") // TODO + ); })); } - @Order(4) @Test + @Order(4) + @DisplayName("OR operation") void testOR() { am2901.setSrc(DA); @@ -215,18 +223,19 @@ public class Am2901Test int res32Bit = xy.x | xy.y; - String desc = xy.x + " | " + xy.y + " = " + res32Bit + ": "; - - assertEquals(to4bitBin(res32Bit), am2901.getY(), desc + "Y"); - assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), desc + "F=0"); - assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), desc + "F3"); -// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), desc + "Cn+4"); // TODO -// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), desc + "OVR"); // TODO + assertAll("Result of " + xy.x + " | " + xy.y + " = " + res32Bit, + () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"), + () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"), + () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3") +// () -> assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), " Cn+4"), // TODO +// () -> assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), " OVR") // TODO + ); })); } - @Order(4) @Test + @Order(4) + @DisplayName("XOR operation") void testXOR() { am2901.setSrc(DA); @@ -243,18 +252,16 @@ public class Am2901Test int res32Bit = xy.x ^ xy.y; - String desc = xy.x + " ^ " + xy.y + " = " + res32Bit + ": "; - - assertEquals(to4bitBin(res32Bit), am2901.getY(), desc + "Y"); - assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), desc + "F=0"); - assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), desc + "F3"); -// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getCarryOut(), desc + "Cn+4"); // TODO -// assertEquals(to1bitBin(res32Bit != 0b1111), am2901.getOverflow(), desc + "OVR"); // TODO + assertAll("Result of " + xy.x + " ^ " + xy.y + " = " + res32Bit, + () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"), + () -> assertEquals(to1bitBin(res32Bit == 0), am2901.getZero(), " F=0"), + () -> assertEquals(to1bitBin(res32Bit & 0b1000), am2901.getSign(), " F3")); })); } - @Order(4) @Test + @Order(4) + @DisplayName("SUB operation") void testSUB() { am2901.setSrc(DA); @@ -275,13 +282,12 @@ public class Am2901Test int res32Bit_sgn = signed4ToSigned32(xy.x) - signed4ToSigned32(xy.y); int res4Bit_sgn = signed4ToSigned32(res32Bit_sgn); - String desc = xy.x + " - " + xy.y + " = " + res4Bit + ": "; - - assertEquals(to4bitBin(res4Bit & 0b1111), am2901.getY(), desc + "Y"); - assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), desc + "F=0"); - assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), desc + "F3"); - assertEquals(to1bitBin(xy.x >= xy.y), am2901.getCarryOut(), desc + "Cn+4"); - assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), desc + "OVR"); + assertAll("Result of " + xy.x + " - " + xy.y + " = " + res32Bit, + () -> assertEquals(to4bitBin(res32Bit), am2901.getY(), " Y"), + () -> assertEquals(to1bitBin(res4Bit == 0), am2901.getZero(), " F=0"), + () -> assertEquals(to1bitBin(res4Bit & 0b1000), am2901.getSign(), " F3"), + () -> assertEquals(to1bitBin(xy.x >= xy.y), am2901.getCarryOut(), " Cn+4"), + () -> assertEquals(to1bitBin(res4Bit_sgn != res32Bit_sgn), am2901.getOverflow(), " OVR")); })); } diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java index fc4a80a5..ad0a0b87 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901.java @@ -5,10 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.stream.Stream; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; - public interface TestableAm2901 { void setup(); @@ -132,15 +128,4 @@ public interface TestableAm2901 return Arrays.stream(values()); } } - - public static class RegisterProvider implements ArgumentsProvider - { - - @Override - public Stream provideArguments(ExtensionContext context) throws Exception - { - return Register.stream().map(Arguments::of); - } - - } } diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java index 643eecbf..7bbc398c 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/ui/am2900/TestableAm2901Impl.java @@ -169,47 +169,47 @@ public class TestableAm2901Impl implements TestableAm2901 public void setDest(Am2901_Dest dest) { var bits = of(dest.ordinal(), 3); - I8.setToValueOf(bits.getBit(0)); - I7.setToValueOf(bits.getBit(1)); - I6.setToValueOf(bits.getBit(2)); + I8.setToValueOf(bits.getLSBit(2)); + I7.setToValueOf(bits.getLSBit(1)); + I6.setToValueOf(bits.getLSBit(0)); } @Override public void setFunc(Am2901_Func func) { var bits = of(func.ordinal(), 3); - I5.setToValueOf(bits.getBit(0)); - I4.setToValueOf(bits.getBit(1)); - I3.setToValueOf(bits.getBit(2)); + I5.setToValueOf(bits.getLSBit(2)); + I4.setToValueOf(bits.getLSBit(1)); + I3.setToValueOf(bits.getLSBit(0)); } @Override public void setSrc(Am2901_Src src) { var bits = of(src.ordinal(), 3); - I2.setToValueOf(bits.getBit(0)); - I1.setToValueOf(bits.getBit(1)); - I0.setToValueOf(bits.getBit(2)); + I2.setToValueOf(bits.getLSBit(2)); + I1.setToValueOf(bits.getLSBit(1)); + I0.setToValueOf(bits.getLSBit(0)); } @Override public void setReg_A(String val_4_bit) { - var bits = BitVector.parseMSBFirst(val_4_bit); - A3.setToValueOf(bits.getBit(3)); - A2.setToValueOf(bits.getBit(2)); - A1.setToValueOf(bits.getBit(1)); - A0.setToValueOf(bits.getBit(0)); + var bits = BitVector.parse(val_4_bit); + A3.setToValueOf(bits.getLSBit(3)); + A2.setToValueOf(bits.getLSBit(2)); + A1.setToValueOf(bits.getLSBit(1)); + A0.setToValueOf(bits.getLSBit(0)); } @Override public void setReg_B(String val_4_bit) { - var bits = BitVector.parseMSBFirst(val_4_bit); - B3.setToValueOf(bits.getBit(3)); - B2.setToValueOf(bits.getBit(2)); - B1.setToValueOf(bits.getBit(1)); - B0.setToValueOf(bits.getBit(0)); + var bits = BitVector.parse(val_4_bit); + B3.setToValueOf(bits.getLSBit(3)); + B2.setToValueOf(bits.getLSBit(2)); + B1.setToValueOf(bits.getLSBit(1)); + B0.setToValueOf(bits.getLSBit(0)); } @Override @@ -227,11 +227,11 @@ public class TestableAm2901Impl implements TestableAm2901 @Override public void setD(String val_4_bit) { - var bits = BitVector.parseMSBFirst(val_4_bit); - D4.setToValueOf(bits.getBit(3)); - D3.setToValueOf(bits.getBit(2)); - D2.setToValueOf(bits.getBit(1)); - D1.setToValueOf(bits.getBit(0)); + var bits = BitVector.parse(val_4_bit); + D4.setToValueOf(bits.getLSBit(3)); + D3.setToValueOf(bits.getLSBit(2)); + D2.setToValueOf(bits.getLSBit(1)); + D1.setToValueOf(bits.getLSBit(0)); } @Override @@ -331,7 +331,7 @@ public class TestableAm2901Impl implements TestableAm2901 var y2 = Y3.getDisplayedValue(); var y1 = Y2.getDisplayedValue(); var y0 = Y1.getDisplayedValue(); - return y0.concat(y1).concat(y2).concat(y3).toBitStringMSBFirst(); + return y3.concat(y2).concat(y1).concat(y0).toString(); } private void setField(String name, Object value) @@ -354,7 +354,7 @@ public class TestableAm2901Impl implements TestableAm2901 int val = value; for (int i = length - 1; i >= 0; i--) { - mutator.setBit(i, Bit.lastBitOf(val)); + mutator.setMSBit(i, Bit.lastBitOf(val)); val >>>= 1; } return mutator.toBitVector(); @@ -363,13 +363,13 @@ public class TestableAm2901Impl implements TestableAm2901 @Override public void setDirectly(Register r, String val_4_bit) { - am2901.setHighLevelState(regToStateID(r), BitVector.parseMSBFirst(val_4_bit)); + am2901.setHighLevelState(regToStateID(r), BitVector.parse(val_4_bit)); } @Override public String getDirectly(Register r) { - return ((BitVector) am2901.getHighLevelState(regToStateID(r))).toBitStringMSBFirst(); + return ((BitVector) am2901.getHighLevelState(regToStateID(r))).toString(); } private static String regToStateID(Register r) -- 2.17.1