def test_wire_moves_signal_to_source_position(): wire = Wire(Vector(0, 0), Vector(2, 0)) signal = wire.tick(Signal(True, Vector(2, 0))) assert signal.current assert signal.position == Vector(0, 0)
def test_rotate_turns_button_90_degrees_clockwise(): button = Button(Vector(1, 1), Vector(1, 0)) assert button.output.position == Vector(2, 1) button.rotate() assert button.output.position == Vector(2, 1) button.tick() assert button.output.position == Vector(1, 2)
def test_signal_is_only_add_once(): grid = Grid(10, 10) grid.add_signal(Signal(True, Vector(2, 3))) assert len(grid.signals) == 1 grid.add_signal(Signal(True, Vector(2, 3))) assert len(grid.signals) == 1
def test_wire_returns_original_signal_if_signal_position_is_not_on_source_or_target( ): wire = Wire(Vector(0, 0), Vector(2, 0)) signal = wire.tick(Signal(True, Vector(1, 0))) assert signal.current assert signal.position == Vector(1, 0)
def test_press_activates_output_signal_after_update(): button = Button(Vector(1, 1), Vector(1, 0)) button.press() assert not button.output button.tick() assert button.output
def test_two_signals_are_equal_when_their_currents_are_equal(): assert Signal(True, Vector(0, 0)) == Signal(True, Vector(9, 5)) assert Signal(False, Vector(0, 0)) == Signal(False, Vector(9, 5)) assert Signal(True, Vector(0, 0)) != Signal(False, Vector(9, 5))
def test_signal_can_be_toggled_on_and_off(): signal = Signal(False, Vector(0, 0)) signal.toggle() assert signal == Signal(True, Vector(0, 0)) signal.toggle() assert signal == Signal(False, Vector(0, 0))
def test_signals_can_be_switched_on_and_off(): signal = Signal(False, Vector(0, 0)) signal.on() assert signal == Signal(True, Vector(0, 0)) signal.off() assert signal == Signal(False, Vector(0, 0))
def test_rotates_by_90_degress_steps_anticlockwise_for_negative_values(): assert Vector(1, 0).rotate(-1) == Vector(0, -1)
def test_rotates_by_90_degree_steps_clockwise_for_positive_values(): assert Vector(1, 0).rotate(0) == Vector(1, 0) assert Vector(1, 0).rotate(1) == Vector(0, 1) assert Vector(1, 0).rotate(2) == Vector(-1, 0) assert Vector(1, 0).rotate(3) == Vector(0, -1) assert Vector(1, 0).rotate(4) == Vector(1, 0)
def test_subtracting_two_vectors_subtracts_right_xy_values_from_left_xy_values(): assert Vector(1, 1) - Vector(1, 0) == Vector(0, 1) assert Vector(1, 1) - Vector(0, 1) == Vector(1, 0)
def test_adding_two_vectors_adds_their_x_and_y_coordinates(): assert Vector(1, 0) + Vector(0, 1) == Vector(1, 1)
def test_two_vectors_are_equal_if_x_and_y_coordinates_are_equal(): assert Vector(1, 0) == Vector(1, 0) assert Vector(1, 0) != Vector(0, 1) assert Vector(1, 0) != Vector(1, 1) assert Vector(1, 0) != Vector(0, 0)
def test_add_signal_adds_a_signal_to_the_grid(): grid = Grid(10, 10) grid.add_signal(Signal(True, Vector(2, 3))) assert Signal(True, Vector(2, 3)) in grid.signals
def test_button_is_not_pressed_by_default(): button = Button(Vector(1, 1), Vector(1, 0)) assert not button.output button.tick() assert not button.output
def test_vector_has_length(self): assert math.isclose(Vector(1, 1).length, math.sqrt(2))
def test_vector_is_created_with_x_y_coordinates(): vector = Vector(0, 1) assert vector.x == 0 assert vector.y == 1
def test_wire_has_two_coordinates(): wire = Wire(Vector(0, 0), Vector(2, 0)) assert wire.target == Vector(2, 0) assert wire.source == Vector(0, 0)
def test_power_source__activates__adjacent_grid_coordinate(): power_source = PowerSource(Vector(1, 1), down) assert power_source.tick() == Signal(True, Vector(1, 2))