def test_step_three_blocks(self): block1 = source() block2 = source() block3 = operator_of(conjunction, block1, block2) simulation = Simulation([block3, block2, block1]) simulation.run() self.assertEqual(1, block3.outputs[0].value)
def test_step_four_blocks(self): source1 = source() source2 = source() conj = operator_of(conjunction, source1, source2) neg = operator_of(negation, conj) simulation = Simulation([neg, conj, source2, source1]) simulation.run() self.assertEqual(0, neg.outputs[0].value)
def test_block(first_input, second_input, block_factory) -> int: first_source_block = source(value=first_input) second_source_block = source(value=second_input) block = block_factory() first_source_block.outputs[0].connect_with(block.inputs[0]) second_source_block.outputs[0].connect_with(block.inputs[1]) first_source_block.push() second_source_block.push() block.push() return block.outputs[0].value
def test_negation(self): source_block = source(0) not_block = negation() source_block.outputs[0].connect_with(not_block.inputs[0]) source_block.push() not_block.push() self.assertEqual(1, not_block.outputs[0].value)
def test_connector_pushes_to_next(self): source_block = source() second_block = Block(0, 0, input_connectors_n=1, output_connectors_n=0) source_block.outputs[0].connect_with(second_block.inputs[0]) source_block.push() for c2 in second_block.inputs: self.assertEqual(1, c2.value)
def test_step_pushes(self): block = source() simulation = Simulation([block]) simulation.run() self.assertEqual(1, block.outputs[0].value)
def test_source_block_pushes_signal(self): source_block = source() source_block.push() self.assertEqual(1, source_block.outputs[0].value)
def test_inside_connector_output(self): block = source() right_middle = Point(Block.WIDTH, Block.HEIGHT / 2) conn = block.inside_connector(right_middle) self.assertTrue(conn.contains(right_middle))
def sources(*args): return tuple(source(v) for v in args)