from region import Region


def test_tick_nd_counts_single_target_delivery() -> None:
    region = Region("nd-single-delivery")
    hidden_layer_index = region.add_layer(1, 0, 0)
    region.bind_input_nd("nd", shape=[1], gain=1.0, epsilon_fire=0.01, layer_indices=[hidden_layer_index])

    metrics = region.tick_nd("nd", [1.0], [1])

    assert metrics.delivered_events == 1


def test_tick_nd_counts_multi_target_delivery() -> None:
    region = Region("nd-multi-delivery")
    first_target_index = region.add_layer(1, 0, 0)
    second_target_index = region.add_layer(1, 0, 0)
    region.bind_input_nd(
        "nd",
        shape=[1],
        gain=1.0,
        epsilon_fire=0.01,
        layer_indices=[first_target_index, second_target_index],
    )

    metrics = region.tick_nd("nd", [1.0], [1])

    assert metrics.delivered_events == 2


def test_tick_2d_counts_windowed_tract_delivery() -> None:
    region = Region("two-d-windowed-delivery")
    input_layer_index = region.add_input_layer_2d(1, 1, 1.0, 0.01)
    output_layer_index = region.add_output_layer_2d(1, 1, 0.0)
    region.connect_layers_windowed(
        input_layer_index,
        output_layer_index,
        kernel_h=1,
        kernel_w=1,
        stride_h=1,
        stride_w=1,
        padding="same",
    )
    region.bind_input("pixels", [input_layer_index])

    metrics = region.tick_2d("pixels", [[1.0]])

    assert metrics.delivered_events == 1
