from lateral_bus import LateralBus
from neuron_excitatory import ExcitatoryNeuron


def test_prune_synapses_requires_both_stale_and_weak():
    layer_bus = LateralBus()
    source_neuron = ExcitatoryNeuron("source", layer_bus)
    weak_stale_target = ExcitatoryNeuron("weak-stale", layer_bus)
    strong_stale_target = ExcitatoryNeuron("strong-stale", layer_bus)
    weak_recent_target = ExcitatoryNeuron("weak-recent", layer_bus)

    weak_stale_synapse = source_neuron.connect(weak_stale_target)
    strong_stale_synapse = source_neuron.connect(strong_stale_target)
    weak_recent_synapse = source_neuron.connect(weak_recent_target)

    weak_stale_synapse.set_strength_value(0.01)
    weak_stale_synapse.set_last_seen_tick(0)
    strong_stale_synapse.set_strength_value(0.50)
    strong_stale_synapse.set_last_seen_tick(0)
    weak_recent_synapse.set_strength_value(0.01)
    weak_recent_synapse.set_last_seen_tick(9)

    layer_bus.current_step = 10
    pruned_count = source_neuron.prune_synapses(stale_window=5, min_strength=0.10)

    assert pruned_count == 1
    remaining_targets = {outgoing_synapse.target.id for outgoing_synapse in source_neuron.get_outgoing()}
    assert remaining_targets == {"strong-stale", "weak-recent"}
