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
{
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));
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));
assertEquals("1", am2901.getZero());
}
- @Order(3)
@Test
+ @Order(3)
+ @DisplayName("Setting all registers to 0")
void testSetAllToZero()
{
setRegistersToZero();
}));
}
- @Order(4)
@Test
+ @Order(4)
+ @DisplayName("ADD operation")
void testADD()
{
am2901.setSrc(DA);
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);
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);
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);
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);
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"));
}));
}
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
@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
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)
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();
@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)