import math

from region import Region


def test_temporal_focus_creates_many_slots():
    region = Region("tfocus")
    target_layer_index = region.add_layer(1, 0, 0)
    region.bind_input("in", [target_layer_index])

    # feed values from 1.0 to 2.0 (inclusive) in small steps
    steps = 50
    for loop_index in range(steps + 1):
        input_value = 1.0 + (loop_index / steps)
        region.tick("in", input_value)

    # check total slots on first neuron
    source_neuron = region.layers[target_layer_index].get_neurons()[0]
    total_slots = len(source_neuron.slots)
    assert total_slots >= 10, f"expected >=10 slots, got {total_slots}"


def test_temporal_focus_exposes_scalar_anchor_state():
    region = Region("tfocus_anchor")
    target_layer_index = region.add_layer(1, 0, 0)
    region.bind_input("in", [target_layer_index])

    region.tick("in", 0.5)
    region.tick("in", 0.8)

    input_edge_index = region.input_edges["in"]
    source_neuron = region.layers[input_edge_index].get_neurons()[0]
    assert source_neuron.last_slot_anchor_state is not None
    assert source_neuron.last_slot_anchor_state.scalar_value == 0.5
    assert source_neuron.last_slot_focus_selection is not None
    assert source_neuron.last_slot_focus_selection.candidate.scalar_value == 0.8
