Esempio n. 1
0
    def test_basic(self):
        d = Node(State.low, name="D")
        clk = Node(State.high, name="Clk")
        ff = DTypeFlipFlop([d, clk])
        ff.calculate()
        assert ff.outputs["Q"].state == State.low
        assert ff.outputs["QBar"].state == State.high

        d.state = State.high
        clk.state = State.high
        ff.calculate()
        assert ff.outputs["Q"].state == State.high
        assert ff.outputs["QBar"].state == State.low
Esempio n. 2
0
    def test_no_change_state_high_output(self):
        d = Node(State.high, name="D")
        clk = Node(State.high, name="Clk")
        ff = DTypeFlipFlop([d, clk])
        ff.calculate()
        assert ff.outputs["Q"].state == State.high
        assert ff.outputs["QBar"].state == State.low

        d.state = State.low
        clk.state = State.low
        ff.calculate()
        assert ff.outputs["Q"].state == State.high
        assert ff.outputs["QBar"].state == State.low

        d.state = State.high
        clk.state = State.low
        ff.calculate()
        assert ff.outputs["Q"].state == State.high
        assert ff.outputs["QBar"].state == State.low

        d.state = State.low
        clk.state = State.low
        ff.calculate()
        assert ff.outputs["Q"].state == State.high
        assert ff.outputs["QBar"].state == State.low
Esempio n. 3
0
    def test_last_state(self):
        """
        Tests that Set=low & Reset=Low provides the previous state
        """
        set_node = Node(State.low, name="Set")
        reset_node = Node(State.high, name="Reset")
        latch = SRNandLatch([set_node, reset_node])
        out_nodes = latch.calculate()
        assert out_nodes["Q"] == State.high
        assert out_nodes["QBar"] == State.low

        set_node.state = State.high
        reset_node.state = State.high
        out_nodes = latch.calculate()
        assert out_nodes["Q"] == State.high
        assert out_nodes["QBar"] == State.low

        set_node.state = State.high
        reset_node.state = State.low
        out_nodes = latch.calculate()
        assert out_nodes["Q"] == State.low
        assert out_nodes["QBar"] == State.high

        set_node.state = State.high
        reset_node.state = State.high
        out_nodes = latch.calculate()
        assert out_nodes["Q"] == State.low
        assert out_nodes["QBar"] == State.high