Class MockRegister


  • public class MockRegister
    extends Object
    Represents a "ghost" register: a register component replaced with Pin components for easier testing. Useful for testing the combinational logic in a sequential circuit by getting/setting the Pins contained in it.

    Idea: Suppose we want to test a circuit that looks like this

                    ______
           .-------|D    Q|------.
           |       |      |      |
           |       |_/\___|      |
           |                     |
           '--[ combinational ]--'
              [    logic      ]
     

    but we want to test that combinational logic — who cares about the register? So rewire the circuit to look like this instead, where d is an output pin, and q is an input pin:

           .-------(d)  [q]------.
           |                     |
           |                     |
           |                     |
           '--[ combinational ]--'
              [    logic      ]
     

    This way, we can test that combinational logic on its own by setting the value of q and then checking the value of d. In fact, a MockRegister contains a new input/output pin for every Register Port so you can test the student connected all register ports correctly.

    See Also:
    Subcircuit.mockOnlyRegister(int)
    • Method Detail

      • getQ

        public InputPin getQ()
        Returns the Pin which replaced the out port of the register. This is the only input Pin in MockRegister since you should InputPin.set(int) this to the value you want the "ghost" register to contain in the test.
        Returns:
        the InputPin for the Q register port
      • getD

        public OutputPin getD()
        Returns the Pin which replaced the in port of the register. This is an output Pin because the student's code will set it to something.
        Returns:
        the OutputPin for the D register port
      • getEn

        public OutputPin getEn()
        Returns the Pin which replaced the write enable port of the register. This is an output Pin because the student's code will set it to something.
        Returns:
        the OutputPin for the write enable register port
      • getClk

        public OutputPin getClk()
        Returns the Pin which replaced the clock port of the register. This is an output Pin because the student's code will set it to something.
        Returns:
        the OutputPin for the clock register port
      • getRst

        public OutputPin getRst()
        Returns the Pin which replaced the reset port of the register. This is an output Pin because the student's code will set it to something.
        Returns:
        the OutputPin for the reset register port
      • getSubcircuit

        public Subcircuit getSubcircuit()
        Returns the Subcircuit where the Pins which make up this MockRegister live.
        Returns:
        the subcircuit where this mock register lives