From 4118b4792d0a1e855a9ee239fee4ac3d9971e531 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 25 Nov 2026 20:36:56 +0100 Subject: [PATCH] Percepts: Touch updates the slot's Kind; a freed slot is zeroed fully; tests for both and for the anonymous-emitter hole Co-Authored-By: Claude Sonnet 5.5 --- src/Lodur.Core/Perception.cs | 5 +++++ tests/Lodur.Core.Tests/PerceptTests.cs | 30 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Lodur.Core/Perception.cs b/src/Lodur.Core/Perception.cs index a3a4bf3..61db099 100644 --- a/src/Lodur.Core/Perception.cs +++ b/src/Lodur.Core/Perception.cs @@ -388,6 +388,10 @@ namespace Lodur if (_pId[s] != 0 && !_pSensed[s] && _pSince[s] > _memorySeconds) { _pId[s] = 0; + _pKind[s] = 0; + _pX[s] = 0f; _pY[s] = 0f; _pZ[s] = 0f; + _pSalience[s] = 0.0; + _pSince[s] = 0.0; } } @@ -484,6 +488,7 @@ namespace Lodur _pSalience[slot] = salience; } + _pKind[slot] = e.Kind; _pSensed[slot] = true; _pSince[slot] = 0.0; } diff --git a/tests/Lodur.Core.Tests/PerceptTests.cs b/tests/Lodur.Core.Tests/PerceptTests.cs index ca9b85f..b58ca30 100644 --- a/tests/Lodur.Core.Tests/PerceptTests.cs +++ b/tests/Lodur.Core.Tests/PerceptTests.cs @@ -39,6 +39,36 @@ public sealed class PerceptTests return n; } + [Fact] + public void A_remembered_id_sensed_with_a_new_kind_takes_the_new_kind() + { + var p = Make(); + Sense(p, new[] { At(1, kind: 7) }); + Sense(p, new[] { At(1, kind: 9) }); + Assert.Equal(9u, p.Percept(SlotOf(p, 1)).Kind); + } + + [Fact] + public void A_free_slot_is_all_zero_after_forgetting_and_an_anonymous_emitter_cannot_write_into_it() + { + var p = Make(capacity: 2, memory: 0.05); + Sense(p, new[] { At(1, x: 0.5f) }); + for (var i = 0; i < 20; i++) Sense(p, Array.Empty()); + Assert.Equal(0, Occupied(p)); + for (var i = 0; i < 3; i++) Sense(p, new[] { At(0, x: 0.5f) }); + for (var s = 0; s < p.PerceptCount; s++) + { + var c = p.Percept(s); + Assert.Equal(0UL, c.Id); + Assert.Equal(0u, c.Kind); + Assert.Equal(0f, c.X); + Assert.Equal(0f, c.Y); + Assert.Equal(0f, c.Z); + Assert.Equal(0.0, c.Salience); + Assert.Equal(0.0, c.SecondsSinceSensed); + } + } + [Fact] public void An_anonymous_emitter_loads_the_nerve_and_makes_no_percept() {