From 6662aefd184ae3df0ca1f87913b766dd39a39387 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 16 Sep 2025 17:57:13 -0300 Subject: [PATCH 01/21] support multiple ideas first test --- .../idea/HabitExecutionerCodelet.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 8d7b0046..a33baf11 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -12,6 +12,8 @@ import br.unicamp.cst.core.entities.Codelet; import br.unicamp.cst.core.entities.Memory; +import br.unicamp.cst.core.entities.MemoryContainer; + import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,12 +43,12 @@ public void accessMemoryObjects() { } } } - if (root.isLeaf()) { - Logger.getAnonymousLogger().log(Level.INFO, "I was not able to find any valid Idea at inputs"); - } - if (h == null) { - Logger.getAnonymousLogger().log(Level.INFO, "I found no habit to execute"); - } + // if (root.isLeaf() && this.inputs.size() > 1) { + // Logger.getAnonymousLogger().log(Level.INFO, "I was not able to find any valid Idea at inputs"); + // } + // if (h == null) { + // Logger.getAnonymousLogger().log(Level.INFO, "I found no habit to execute"); + // } } @Override @@ -58,8 +60,18 @@ public void calculateActivation() { public void proc() { if (h != null) { Idea ois = h.exec(root); - for (Memory m : outputs) - m.setI(ois); + if (ois != null) { + for (Idea sub_ois : ois.getL()) { + for (Memory m : outputs) { + if (m instanceof MemoryContainer) { + MemoryContainer mc = (MemoryContainer) m; + if (sub_ois.getName().equals(mc.getName())) { + mc.setI(ois, -1.0d, mc.getName()); + } + } + } + } + } } } -} +} \ No newline at end of file From 467f97134c6111403bafc51ceaf8f465f09ebc9e Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 23 Sep 2025 18:29:45 -0300 Subject: [PATCH 02/21] partial bug fix --- .../cst/representation/idea/HabitExecutionerCodelet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index a33baf11..5a294a43 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -29,7 +29,7 @@ public class HabitExecutionerCodelet extends Codelet { @Override public void accessMemoryObjects() { - root = new Idea("root"); + root = new Idea("root", ""); for (Memory m : this.inputs) { Object o = m.getI(); if (o instanceof Idea) { @@ -66,7 +66,7 @@ public void proc() { if (m instanceof MemoryContainer) { MemoryContainer mc = (MemoryContainer) m; if (sub_ois.getName().equals(mc.getName())) { - mc.setI(ois, -1.0d, mc.getName()); + mc.setI(sub_ois, -1.0d, mc.getName()); } } } From bd5575bd56e53ebfe07f3d92091fc7a299a031e6 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 25 Sep 2025 16:50:26 -0300 Subject: [PATCH 03/21] partial fix --- .../idea/HabitExecutionerCodelet.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 5a294a43..09a13cdf 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -23,15 +23,23 @@ * @author rgudwin */ public class HabitExecutionerCodelet extends Codelet { - + private volatile double inputActivation = 0.0d; + MemoryContainer mc; Habit h; Idea root; + + public HabitExecutionerCodelet(String name) { + this.name = name; + } @Override public void accessMemoryObjects() { root = new Idea("root", ""); for (Memory m : this.inputs) { - Object o = m.getI(); + if (m instanceof MemoryContainer) { + mc = (MemoryContainer) m; + } + Object o = mc.getI(); if (o instanceof Idea) { Idea id = (Idea)o; Object value = id.getValue(); @@ -43,12 +51,12 @@ public void accessMemoryObjects() { } } } - // if (root.isLeaf() && this.inputs.size() > 1) { - // Logger.getAnonymousLogger().log(Level.INFO, "I was not able to find any valid Idea at inputs"); - // } - // if (h == null) { - // Logger.getAnonymousLogger().log(Level.INFO, "I found no habit to execute"); - // } + if (root.isLeaf() && this.inputs.size() > 1) { + Logger.getAnonymousLogger().log(Level.INFO, "I was not able to find any valid Idea at inputs"); + } + if (h == null) { + Logger.getAnonymousLogger().log(Level.INFO, "I found no habit to execute"); + } } @Override @@ -66,7 +74,11 @@ public void proc() { if (m instanceof MemoryContainer) { MemoryContainer mc = (MemoryContainer) m; if (sub_ois.getName().equals(mc.getName())) { - mc.setI(sub_ois, -1.0d, mc.getName()); + Idea activationIdea = sub_ois.get("activation"); + if (activationIdea != null && activationIdea.getValue() instanceof Double) { + inputActivation = (double) activationIdea.getValue(); + } + mc.setI(sub_ois, inputActivation, mc.getName()); } } } From 2ed42fe344393de5f35303e0dc729db37a5af237 Mon Sep 17 00:00:00 2001 From: rgudwin Date: Thu, 25 Sep 2025 19:46:07 -0300 Subject: [PATCH 04/21] Small corrections in HabitExecutionerCodelet --- .../idea/HabitExecutionerCodelet.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 09a13cdf..532afcf9 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -23,11 +23,14 @@ * @author rgudwin */ public class HabitExecutionerCodelet extends Codelet { - private volatile double inputActivation = 0.0d; - MemoryContainer mc; + //private volatile double inputActivation = 0.0d; Habit h; Idea root; + public HabitExecutionerCodelet() { + this.name = "Default"; + } + public HabitExecutionerCodelet(String name) { this.name = name; } @@ -36,14 +39,11 @@ public HabitExecutionerCodelet(String name) { public void accessMemoryObjects() { root = new Idea("root", ""); for (Memory m : this.inputs) { - if (m instanceof MemoryContainer) { - mc = (MemoryContainer) m; - } - Object o = mc.getI(); + Object o = m.getI(); if (o instanceof Idea) { Idea id = (Idea)o; Object value = id.getValue(); - if (value instanceof Habit) { + if (m.getName().equalsIgnoreCase(this.getName()+"Habits") && value instanceof Habit) { h = (Habit) value; } else { @@ -66,6 +66,7 @@ public void calculateActivation() { @Override public void proc() { + double act = 0.0d; if (h != null) { Idea ois = h.exec(root); if (ois != null) { @@ -76,14 +77,15 @@ public void proc() { if (sub_ois.getName().equals(mc.getName())) { Idea activationIdea = sub_ois.get("activation"); if (activationIdea != null && activationIdea.getValue() instanceof Double) { - inputActivation = (double) activationIdea.getValue(); + act = (double) activationIdea.getValue(); } - mc.setI(sub_ois, inputActivation, mc.getName()); + mc.setI(sub_ois, act, this.getName()); } } } } } + try{setActivation(act);}catch(Exception e){}; } } -} \ No newline at end of file +} From 275adb50f2a4a1e7b1b59f668871ec6b52293898 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 30 Sep 2025 18:29:13 -0300 Subject: [PATCH 05/21] refactor (code structure, support to mos, root activation) --- .../idea/HabitExecutionerCodelet.java | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 532afcf9..43107af6 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -14,7 +14,9 @@ import br.unicamp.cst.core.entities.Memory; import br.unicamp.cst.core.entities.MemoryContainer; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -23,7 +25,6 @@ * @author rgudwin */ public class HabitExecutionerCodelet extends Codelet { - //private volatile double inputActivation = 0.0d; Habit h; Idea root; @@ -66,26 +67,41 @@ public void calculateActivation() { @Override public void proc() { - double act = 0.0d; - if (h != null) { - Idea ois = h.exec(root); - if (ois != null) { - for (Idea sub_ois : ois.getL()) { - for (Memory m : outputs) { - if (m instanceof MemoryContainer) { - MemoryContainer mc = (MemoryContainer) m; - if (sub_ois.getName().equals(mc.getName())) { - Idea activationIdea = sub_ois.get("activation"); - if (activationIdea != null && activationIdea.getValue() instanceof Double) { - act = (double) activationIdea.getValue(); - } - mc.setI(sub_ois, act, this.getName()); - } - } - } - } + if (h == null) return; + + // Get the ideas from the habit execution + Idea outputRoot = h.exec(root); + if (outputRoot == null) return; + + // Set the activation of the output root idea in this codelet + double outputRootActivation = getActivationValue(outputRoot); + try{setActivation(outputRootActivation);}catch(Exception e){}; + + // Create a map of output memories for quick access + Map outputsMap = new HashMap<>(); + for (Memory mem : outputs) outputsMap.put(mem.getName(), mem); + + // Iterate through the output ideas and update corresponding memories + for (Idea outputIdea : outputRoot.getL()) { + Memory m = outputsMap.get(outputIdea.getName()); + if (m == null) continue; // Skip to the next idea if no match is found + + if (m instanceof MemoryContainer) { + MemoryContainer mc = (MemoryContainer) m; + mc.setI(outputIdea, getActivationValue(outputIdea), this.getName()); + } + else { + m.setI(outputIdea); } - try{setActivation(act);}catch(Exception e){}; } } + + private double getActivationValue(Idea idea) { + double act = 0.0d; + Idea actIdea = idea.get("activation"); + if (actIdea != null && actIdea.getValue() instanceof Double) { + act = (double) actIdea.getValue(); + } + return act; + } } From f7827db78d487e48eb71489a7d95b18f5ddb616b Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 2 Oct 2025 16:57:00 -0300 Subject: [PATCH 06/21] remove unnecessary comments --- .../cst/representation/idea/HabitExecutionerCodelet.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 43107af6..e2618c16 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -69,19 +69,15 @@ public void calculateActivation() { public void proc() { if (h == null) return; - // Get the ideas from the habit execution Idea outputRoot = h.exec(root); if (outputRoot == null) return; - // Set the activation of the output root idea in this codelet double outputRootActivation = getActivationValue(outputRoot); try{setActivation(outputRootActivation);}catch(Exception e){}; - // Create a map of output memories for quick access Map outputsMap = new HashMap<>(); for (Memory mem : outputs) outputsMap.put(mem.getName(), mem); - - // Iterate through the output ideas and update corresponding memories + for (Idea outputIdea : outputRoot.getL()) { Memory m = outputsMap.get(outputIdea.getName()); if (m == null) continue; // Skip to the next idea if no match is found From 6cdcca57037d8e52631dc291f62c5e272be97340 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 7 Oct 2025 16:38:27 -0300 Subject: [PATCH 07/21] add timeStep and PublishSubscribe support --- .../idea/HabitExecutionerCodelet.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index e2618c16..852b0682 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -75,6 +75,10 @@ public void proc() { double outputRootActivation = getActivationValue(outputRoot); try{setActivation(outputRootActivation);}catch(Exception e){}; + setTimeStepValue(outputRoot); + + setPublishSubscribeValue(outputRoot); + Map outputsMap = new HashMap<>(); for (Memory mem : outputs) outputsMap.put(mem.getName(), mem); @@ -100,4 +104,20 @@ private double getActivationValue(Idea idea) { } return act; } + + private void setTimeStepValue(Idea idea) { + Idea timeStepIdea = idea.get("timeStep"); + if (timeStepIdea != null && timeStepIdea.getValue() instanceof Long) { + long timeStep = (long) timeStepIdea.getValue(); + try{setTimeStep(timeStep);}catch(Exception e){}; + } + } + + private void setPublishSubscribeValue(Idea idea) { + Idea publishSubscribeIdea = idea.get("publishSubscribe"); + if (publishSubscribeIdea != null && publishSubscribeIdea.getValue() instanceof Boolean) { + boolean publishSubscribe = (boolean) publishSubscribeIdea.getValue(); + try{setPublishSubscribe(publishSubscribe);}catch(Exception e){}; + } + } } From d71537abd6053fe11fa03400c7f60c536e0cf70c Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 7 Oct 2025 16:41:50 -0300 Subject: [PATCH 08/21] change logger level --- .../cst/representation/idea/HabitExecutionerCodelet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 852b0682..935fb7a4 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -53,7 +53,7 @@ public void accessMemoryObjects() { } } if (root.isLeaf() && this.inputs.size() > 1) { - Logger.getAnonymousLogger().log(Level.INFO, "I was not able to find any valid Idea at inputs"); + Logger.getAnonymousLogger().log(Level.FINE, "I was not able to find any valid Idea at inputs"); } if (h == null) { Logger.getAnonymousLogger().log(Level.INFO, "I found no habit to execute"); From a8ffc8b0dee54692fa424fe915278f3b4f1e4abc Mon Sep 17 00:00:00 2001 From: phdaccache Date: Wed, 8 Oct 2025 15:52:06 -0300 Subject: [PATCH 09/21] fix hec tests --- .../idea/HabitExecutionerCodelet.java | 4 ++-- .../idea/HabitExecutionerCodeletTest.java | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 935fb7a4..04cc6198 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -80,10 +80,10 @@ public void proc() { setPublishSubscribeValue(outputRoot); Map outputsMap = new HashMap<>(); - for (Memory mem : outputs) outputsMap.put(mem.getName(), mem); + for (Memory mem : outputs) outputsMap.put(mem.getName().toLowerCase(), mem); for (Idea outputIdea : outputRoot.getL()) { - Memory m = outputsMap.get(outputIdea.getName()); + Memory m = outputsMap.get(outputIdea.getName().toLowerCase()); if (m == null) continue; // Skip to the next idea if no match is found if (m instanceof MemoryContainer) { diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 9ed6d5f7..6f5aa6ea 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -26,7 +26,7 @@ public class HabitExecutionerCodeletTest { public HabitExecutionerCodeletTest() { m = new Mind(); - mc = m.createMemoryContainer("HabitsMemory"); + mc = m.createMemoryContainer("testHabits"); Idea sh = new Idea("Summer"); sh.setValue(summer); sh.setScope(2); @@ -37,7 +37,7 @@ public HabitExecutionerCodeletTest() { mc.setI(dh); moi = m.createMemoryObject("InputIdeasMemory"); moo = m.createMemoryObject("OutputIdeasMemory"); - HabitExecutionerCodelet hec = new HabitExecutionerCodelet(); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); hec.addInput(mc); hec.addInput(moi); hec.addOutput(moo); @@ -49,6 +49,7 @@ public HabitExecutionerCodeletTest() { Habit summer = new Habit() { @Override public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); Idea adder = idea.get("value.add"); int valuetoadd=0; if (adder != null && adder.getValue() instanceof Integer) { @@ -56,8 +57,9 @@ public Idea exec(Idea idea) { } if (idea.get("value").getValue() instanceof Integer) { int number = (int) idea.get("value").getValue(); - Idea modifiedIdea = new Idea("incremented",number+valuetoadd); - return(modifiedIdea); + Idea modifiedIdea = new Idea("OutputIdeasMemory",number+valuetoadd); + root.add(modifiedIdea); + return root; } System.out.println("Something wrong happened"); return(null); @@ -66,6 +68,7 @@ public Idea exec(Idea idea) { Habit decrementer = new Habit() { @Override public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); Idea adder = idea.get("value.add"); int valuetodec=0; if (adder != null && adder.getValue() instanceof Integer) { @@ -73,8 +76,9 @@ public Idea exec(Idea idea) { } if (idea.get("value").getValue() instanceof Integer) { int number = (int) idea.get("value").getValue(); - Idea modifiedIdea = new Idea("decremented",number-valuetodec); - return(modifiedIdea); + Idea modifiedIdea = new Idea("OutputIdeasMemory",number-valuetodec); + root.add(modifiedIdea); + return root; } System.out.println("Something wrong happened"); return(null); From f4057c6a89e84732b0a1f85ce009499a55289755 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Wed, 8 Oct 2025 17:34:28 -0300 Subject: [PATCH 10/21] organize code --- .../idea/HabitExecutionerCodelet.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 04cc6198..8b72d45c 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -72,28 +72,13 @@ public void proc() { Idea outputRoot = h.exec(root); if (outputRoot == null) return; - double outputRootActivation = getActivationValue(outputRoot); - try{setActivation(outputRootActivation);}catch(Exception e){}; + try{this.setActivation(getActivationValue(outputRoot));}catch(Exception e){}; setTimeStepValue(outputRoot); setPublishSubscribeValue(outputRoot); - Map outputsMap = new HashMap<>(); - for (Memory mem : outputs) outputsMap.put(mem.getName().toLowerCase(), mem); - - for (Idea outputIdea : outputRoot.getL()) { - Memory m = outputsMap.get(outputIdea.getName().toLowerCase()); - if (m == null) continue; // Skip to the next idea if no match is found - - if (m instanceof MemoryContainer) { - MemoryContainer mc = (MemoryContainer) m; - mc.setI(outputIdea, getActivationValue(outputIdea), this.getName()); - } - else { - m.setI(outputIdea); - } - } + setIdeasToOutputMemories(outputRoot); } private double getActivationValue(Idea idea) { @@ -109,7 +94,7 @@ private void setTimeStepValue(Idea idea) { Idea timeStepIdea = idea.get("timeStep"); if (timeStepIdea != null && timeStepIdea.getValue() instanceof Long) { long timeStep = (long) timeStepIdea.getValue(); - try{setTimeStep(timeStep);}catch(Exception e){}; + try{this.setTimeStep(timeStep);}catch(Exception e){}; } } @@ -117,7 +102,25 @@ private void setPublishSubscribeValue(Idea idea) { Idea publishSubscribeIdea = idea.get("publishSubscribe"); if (publishSubscribeIdea != null && publishSubscribeIdea.getValue() instanceof Boolean) { boolean publishSubscribe = (boolean) publishSubscribeIdea.getValue(); - try{setPublishSubscribe(publishSubscribe);}catch(Exception e){}; + try{this.setPublishSubscribe(publishSubscribe);}catch(Exception e){}; + } + } + + private void setIdeasToOutputMemories(Idea outputRoot) { + Map outputsMap = new HashMap<>(); + for (Memory mem : this.outputs) outputsMap.put(mem.getName().toLowerCase(), mem); + + for (Idea outputIdea : outputRoot.getL()) { + Memory m = outputsMap.get(outputIdea.getName().toLowerCase()); + if (m == null) continue; // Skip to the next idea if no match is found + + if (m instanceof MemoryContainer) { + MemoryContainer mc = (MemoryContainer) m; + mc.setI(outputIdea, getActivationValue(outputIdea), this.getName()); + } + else { + m.setI(outputIdea); + } } } -} +} \ No newline at end of file From 4e9fed9fe93126e191dfd36c8fe1cb83489aceb7 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Wed, 8 Oct 2025 18:24:44 -0300 Subject: [PATCH 11/21] add some tests --- .../idea/HabitExecutionerCodeletTest.java | 174 +++++++++++++----- 1 file changed, 127 insertions(+), 47 deletions(-) diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 6f5aa6ea..88cc2b8b 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -18,13 +18,24 @@ * @author rgudwin */ public class HabitExecutionerCodeletTest { - + double act; + long timeStep; + + Habit summer; + Habit decrementer; + Habit actSetter; + Habit timeStepSetter; + Mind m; MemoryContainer mc; MemoryObject moi; MemoryObject moo; - public HabitExecutionerCodeletTest() { + private void setUp() { + MockHabits mh = new MockHabits(); + summer = mh.summer; + decrementer = mh.decrementer; + m = new Mind(); mc = m.createMemoryContainer("testHabits"); Idea sh = new Idea("Summer"); @@ -45,46 +56,19 @@ public HabitExecutionerCodeletTest() { m.insertCodelet(hec); m.start(); } + + private void setUp2() { + act = 0.75d; + MockHabits mh = new MockHabits(); + actSetter = mh.actSetter; + } - Habit summer = new Habit() { - @Override - public Idea exec(Idea idea) { - Idea root = new Idea("root", ""); - Idea adder = idea.get("value.add"); - int valuetoadd=0; - if (adder != null && adder.getValue() instanceof Integer) { - valuetoadd = (int) adder.getValue(); - } - if (idea.get("value").getValue() instanceof Integer) { - int number = (int) idea.get("value").getValue(); - Idea modifiedIdea = new Idea("OutputIdeasMemory",number+valuetoadd); - root.add(modifiedIdea); - return root; - } - System.out.println("Something wrong happened"); - return(null); - } - }; - Habit decrementer = new Habit() { - @Override - public Idea exec(Idea idea) { - Idea root = new Idea("root", ""); - Idea adder = idea.get("value.add"); - int valuetodec=0; - if (adder != null && adder.getValue() instanceof Integer) { - valuetodec = (int) adder.getValue(); - } - if (idea.get("value").getValue() instanceof Integer) { - int number = (int) idea.get("value").getValue(); - Idea modifiedIdea = new Idea("OutputIdeasMemory",number-valuetodec); - root.add(modifiedIdea); - return root; - } - System.out.println("Something wrong happened"); - return(null); - } - }; - + private void setUp3() { + timeStep = 500; + MockHabits mh = new MockHabits(); + timeStepSetter = mh.timeStepSetter; + } + private void doTest() { Object oo; Random r = new Random(); @@ -131,7 +115,7 @@ private void doTest() { @Test public void testHabitExecutionerCodeletMAX() { - HabitExecutionerCodeletTest test = new HabitExecutionerCodeletTest(); + setUp(); mc.setPolicy(MemoryContainer.Policy.MAX); System.out.println("\nTesting the MAX Policy - Sums for < 50 Decs for > 50"); doTest(); @@ -139,7 +123,7 @@ public void testHabitExecutionerCodeletMAX() { @Test public void testHabitExecutionerCodeletMIN() { - HabitExecutionerCodeletTest test = new HabitExecutionerCodeletTest(); + setUp(); mc.setPolicy(MemoryContainer.Policy.MIN); System.out.println("\nTesting the MIN Policy - Sums for > 50 Decs for < 50"); doTest(); @@ -147,7 +131,7 @@ public void testHabitExecutionerCodeletMIN() { @Test public void testHabitExecutionerCodeletIterate() { - HabitExecutionerCodeletTest test = new HabitExecutionerCodeletTest(); + setUp(); mc.setPolicy(MemoryContainer.Policy.ITERATE); System.out.println("\nTesting the ITERATE Policy - Iterate Sums and Decs"); doTest(); @@ -155,10 +139,106 @@ public void testHabitExecutionerCodeletIterate() { @Test public void testHabitExecutionerCodeletRandom() { - HabitExecutionerCodeletTest test = new HabitExecutionerCodeletTest(); + setUp(); mc.setPolicy(MemoryContainer.Policy.RANDOM_FLAT); System.out.println("\nTesting the RANDOM_FLAT Policy - Sums and Decs at Random"); doTest(); } - -} + + @Test + public void testActivation() { + setUp2(); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); + hec.h = actSetter; + hec.proc(); + + assertEquals(act, hec.getActivation()); + } + + @Test + public void testTimeStep() { + setUp3(); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); + hec.h = timeStepSetter; + hec.proc(); + + assertEquals(timeStep, hec.getTimeStep()); + } + + // @Test + // public void testPublishSubscribe() { + // setUp4(); + // HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); + // hec.h = publishSubscribeSetter; + // hec.proc(); + + // assertEquals(publishSubscribe, hec.get); + // } + + class MockHabits { + public MockHabits() { + } + + Habit summer = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + Idea adder = idea.get("value.add"); + int valuetoadd=0; + if (adder != null && adder.getValue() instanceof Integer) { + valuetoadd = (int) adder.getValue(); + } + if (idea.get("value").getValue() instanceof Integer) { + int number = (int) idea.get("value").getValue(); + Idea modifiedIdea = new Idea("OutputIdeasMemory",number+valuetoadd); + root.add(modifiedIdea); + return root; + } + System.out.println("Something wrong happened"); + return(null); + } + }; + + Habit decrementer = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + Idea adder = idea.get("value.add"); + int valuetodec=0; + if (adder != null && adder.getValue() instanceof Integer) { + valuetodec = (int) adder.getValue(); + } + if (idea.get("value").getValue() instanceof Integer) { + int number = (int) idea.get("value").getValue(); + Idea modifiedIdea = new Idea("OutputIdeasMemory",number-valuetodec); + root.add(modifiedIdea); + return root; + } + System.out.println("Something wrong happened"); + return(null); + } + }; + + Habit actSetter = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + root.add(new Idea("activation", act)); + root.add(new Idea("someIdea", 123)); + root.add(new Idea("anotherIdea", "abc")); + return root; + } + }; + + Habit timeStepSetter = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + root.add(new Idea("timeStep", timeStep)); + root.add(new Idea("someIdea", 123)); + root.add(new Idea("anotherIdea", "abc")); + return root; + } + }; + } +} \ No newline at end of file From 48525b541ce9019a1ec33f52d344b2b342e134f8 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 9 Oct 2025 16:44:17 -0300 Subject: [PATCH 12/21] some tests --- .../idea/HabitExecutionerCodeletTest.java | 162 ++++++++++-------- 1 file changed, 93 insertions(+), 69 deletions(-) diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 88cc2b8b..48c088d1 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -25,6 +25,7 @@ public class HabitExecutionerCodeletTest { Habit decrementer; Habit actSetter; Habit timeStepSetter; + Habit outputSetter; Mind m; MemoryContainer mc; @@ -56,17 +57,92 @@ private void setUp() { m.insertCodelet(hec); m.start(); } + + @Test + public void testHabitExecutionerCodeletMAX() { + setUp(); + mc.setPolicy(MemoryContainer.Policy.MAX); + System.out.println("\nTesting the MAX Policy - Sums for < 50 Decs for > 50"); + doTest(); + } - private void setUp2() { - act = 0.75d; - MockHabits mh = new MockHabits(); - actSetter = mh.actSetter; + @Test + public void testHabitExecutionerCodeletMIN() { + setUp(); + mc.setPolicy(MemoryContainer.Policy.MIN); + System.out.println("\nTesting the MIN Policy - Sums for > 50 Decs for < 50"); + doTest(); } - private void setUp3() { - timeStep = 500; + @Test + public void testHabitExecutionerCodeletIterate() { + setUp(); + mc.setPolicy(MemoryContainer.Policy.ITERATE); + System.out.println("\nTesting the ITERATE Policy - Iterate Sums and Decs"); + doTest(); + } + + @Test + public void testHabitExecutionerCodeletRandom() { + setUp(); + mc.setPolicy(MemoryContainer.Policy.RANDOM_FLAT); + System.out.println("\nTesting the RANDOM_FLAT Policy - Sums and Decs at Random"); + doTest(); + } + + @Test + public void testActivation() { + System.out.println("\nTesting Activation Setting through Habits"); + Random r = new Random(); + for (int k=0;k<100;k++) { + act = r.nextDouble(); + MockHabits mh = new MockHabits(); + actSetter = mh.actSetter; + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); + hec.h = actSetter; + hec.proc(); + + assertEquals(act, hec.getActivation()); + } + } + + @Test + public void testTimeStep() { + Random r = new Random(); + for (int k=0;k<100;k++) { + timeStep = r.nextInt(1000); + MockHabits mh = new MockHabits(); + timeStepSetter = mh.timeStepSetter; + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); + hec.h = timeStepSetter; + hec.proc(); + + assertEquals(timeStep, hec.getTimeStep()); + } + + } + + // @Test + // public void testPublishSubscribe() { + // boolean f = false, t = true; + // MockHabits mh = new MockHabits(); + // } + + @Test + public void testNoOutputMemory() { MockHabits mh = new MockHabits(); - timeStepSetter = mh.timeStepSetter; + outputSetter = mh.outputSetter; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.setPublishSubscribe(true); + m.insertCodelet(hec); + m.start(); } private void doTest() { @@ -112,68 +188,6 @@ private void doTest() { else fail("The output memory object is null"); } } - - @Test - public void testHabitExecutionerCodeletMAX() { - setUp(); - mc.setPolicy(MemoryContainer.Policy.MAX); - System.out.println("\nTesting the MAX Policy - Sums for < 50 Decs for > 50"); - doTest(); - } - - @Test - public void testHabitExecutionerCodeletMIN() { - setUp(); - mc.setPolicy(MemoryContainer.Policy.MIN); - System.out.println("\nTesting the MIN Policy - Sums for > 50 Decs for < 50"); - doTest(); - } - - @Test - public void testHabitExecutionerCodeletIterate() { - setUp(); - mc.setPolicy(MemoryContainer.Policy.ITERATE); - System.out.println("\nTesting the ITERATE Policy - Iterate Sums and Decs"); - doTest(); - } - - @Test - public void testHabitExecutionerCodeletRandom() { - setUp(); - mc.setPolicy(MemoryContainer.Policy.RANDOM_FLAT); - System.out.println("\nTesting the RANDOM_FLAT Policy - Sums and Decs at Random"); - doTest(); - } - - @Test - public void testActivation() { - setUp2(); - HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); - hec.h = actSetter; - hec.proc(); - - assertEquals(act, hec.getActivation()); - } - - @Test - public void testTimeStep() { - setUp3(); - HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); - hec.h = timeStepSetter; - hec.proc(); - - assertEquals(timeStep, hec.getTimeStep()); - } - - // @Test - // public void testPublishSubscribe() { - // setUp4(); - // HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); - // hec.h = publishSubscribeSetter; - // hec.proc(); - - // assertEquals(publishSubscribe, hec.get); - // } class MockHabits { public MockHabits() { @@ -240,5 +254,15 @@ public Idea exec(Idea idea) { return root; } }; + + Habit outputSetter = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + root.add(new Idea("someIdea", 123)); + root.add(new Idea("anotherIdea", "abc")); + return root; + } + }; } } \ No newline at end of file From 01b6279d731c323d641ba4f350f3809345bab2ad Mon Sep 17 00:00:00 2001 From: rgudwin Date: Thu, 9 Oct 2025 18:05:19 -0300 Subject: [PATCH 13/21] Small changes --- .../br/unicamp/cst/core/entities/Codelet.java | 15 +++++++++++++++ .../idea/HabitExecutionerCodeletTest.java | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/br/unicamp/cst/core/entities/Codelet.java b/src/main/java/br/unicamp/cst/core/entities/Codelet.java index a29418aa..57060076 100755 --- a/src/main/java/br/unicamp/cst/core/entities/Codelet.java +++ b/src/main/java/br/unicamp/cst/core/entities/Codelet.java @@ -803,6 +803,21 @@ public synchronized void setIsMemoryObserver(boolean isMemoryObserver) { this.isMemoryObserver = isMemoryObserver; } + /** + * Check if this Codelet is in publish-subscribe mode. + * + */ + public synchronized boolean isPublishSubscribe() { + return isMemoryObserver; + } + + + /** + * Sets and unsets publish-subscribe mode. + * + * @param enable + * sets publish-subscribe mode on true or false + */ @SuppressWarnings("empty-statement") public synchronized void setPublishSubscribe(boolean enable) { if (enable) { diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 48c088d1..98925b95 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -143,6 +143,7 @@ public void testNoOutputMemory() { hec.setPublishSubscribe(true); m.insertCodelet(hec); m.start(); + while (outputSetter.) } private void doTest() { @@ -188,6 +189,16 @@ private void doTest() { else fail("The output memory object is null"); } } + + abstract class CountableHabit implements Habit { + int count = 0; + + //@Override + //public Idea exec(Idea idea) { + // sup + //} + + } class MockHabits { public MockHabits() { @@ -255,12 +266,14 @@ public Idea exec(Idea idea) { } }; - Habit outputSetter = new Habit() { + Habit outputSetter = new Habit() { + public int counter = 0; @Override public Idea exec(Idea idea) { Idea root = new Idea("root", ""); root.add(new Idea("someIdea", 123)); root.add(new Idea("anotherIdea", "abc")); + counter++; return root; } }; From 3fa8181d504f5dc97ede9950c54a25a323fe58cf Mon Sep 17 00:00:00 2001 From: rgudwin Date: Thu, 9 Oct 2025 18:07:01 -0300 Subject: [PATCH 14/21] Small changes --- .../cst/representation/idea/HabitExecutionerCodeletTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 98925b95..64fc0391 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -143,7 +143,7 @@ public void testNoOutputMemory() { hec.setPublishSubscribe(true); m.insertCodelet(hec); m.start(); - while (outputSetter.) + // while (outputSetter.) } private void doTest() { From 56ae2be1c5086d3d5dee8d1c5ea013196340eb00 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 9 Oct 2025 18:42:57 -0300 Subject: [PATCH 15/21] documentation --- .../idea/HabitExecutionerCodelet.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 8b72d45c..98fa41aa 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -21,7 +21,21 @@ import java.util.logging.Logger; /** - * + * This codelet executes a habit found in its input memories. + * + * It looks for a habit in a memory whose name is the + * same as the name of the codelet plus "Habits". + * + * It also looks for ideas in the other input memories and adds them + * to a root idea, which is passed as a parameter to the habit execution. + * + * If there is another habit in the input memories without the "Habits" + * suffix, it is added to the root idea as well, but not executed. + * + * The habit returns a root idea, which may contain several ideas inside it. + * The codelet looks for ideas inside the root idea whose names match (case insensitive) + * the names of its output memories, and sets those ideas to the respective memories. + * * @author rgudwin */ public class HabitExecutionerCodelet extends Codelet { @@ -106,6 +120,17 @@ private void setPublishSubscribeValue(Idea idea) { } } + /** + * Gets the ideas from the outputRoot and sets them to the output memories + * that match by name (case insensitive). + * + * If the memory is a MemoryContainer, it sets the MemoryObjects inside it + * with the name of the HabitExecutionerCodelet itslef. It does so to + * differentiate between different HECs writing to the same MemoryContainer. + * + * @param outputRoot + * the root idea that comes from the habit execution + */ private void setIdeasToOutputMemories(Idea outputRoot) { Map outputsMap = new HashMap<>(); for (Memory mem : this.outputs) outputsMap.put(mem.getName().toLowerCase(), mem); From 561605ea956e8760bb7e1d17772ee0399bba245a Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 9 Oct 2025 20:51:12 -0300 Subject: [PATCH 16/21] add some tests --- .../idea/HabitExecutionerCodeletTest.java | 311 ++++++++++++++++-- 1 file changed, 284 insertions(+), 27 deletions(-) diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 64fc0391..6aa3f1de 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -3,16 +3,18 @@ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package br.unicamp.cst.representation.idea; -import br.unicamp.cst.core.entities.MemoryContainer; -import br.unicamp.cst.core.entities.MemoryObject; -import br.unicamp.cst.core.entities.Mind; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Random; + import org.junit.jupiter.api.Test; +import br.unicamp.cst.core.entities.MemoryContainer; +import br.unicamp.cst.core.entities.MemoryObject; +import br.unicamp.cst.core.entities.Mind; + /** * * @author rgudwin @@ -20,17 +22,25 @@ public class HabitExecutionerCodeletTest { double act; long timeStep; + boolean publishSubscribe; + int exec_counter; + int proc_counter; Habit summer; Habit decrementer; Habit actSetter; Habit timeStepSetter; + Habit publishSubscribeSetter; Habit outputSetter; + Habit simple; + Habit notExecuted; Mind m; MemoryContainer mc; MemoryObject moi; MemoryObject moo; + + Idea global_idea; private void setUp() { MockHabits mh = new MockHabits(); @@ -38,6 +48,7 @@ private void setUp() { decrementer = mh.decrementer; m = new Mind(); + mc = m.createMemoryContainer("testHabits"); Idea sh = new Idea("Summer"); sh.setValue(summer); @@ -57,6 +68,15 @@ private void setUp() { m.insertCodelet(hec); m.start(); } + + @Test + public void testName() { + System.out.println("\nTesting Name Setting and Default Name"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet(); + assertEquals("Default", hec.getName()); + hec = new HabitExecutionerCodelet("MyName"); + assertEquals("MyName", hec.getName(), "Name should be MyName"); + } @Test public void testHabitExecutionerCodeletMAX() { @@ -93,6 +113,7 @@ public void testHabitExecutionerCodeletRandom() { @Test public void testActivation() { System.out.println("\nTesting Activation Setting through Habits"); + Random r = new Random(); for (int k=0;k<100;k++) { act = r.nextDouble(); @@ -102,12 +123,14 @@ public void testActivation() { hec.h = actSetter; hec.proc(); - assertEquals(act, hec.getActivation()); + assertEquals(act, hec.getActivation(), "Activation should be " + act); } } @Test public void testTimeStep() { + System.out.println("\nTesting TimeStep Setting through Habits"); + Random r = new Random(); for (int k=0;k<100;k++) { timeStep = r.nextInt(1000); @@ -117,19 +140,33 @@ public void testTimeStep() { hec.h = timeStepSetter; hec.proc(); - assertEquals(timeStep, hec.getTimeStep()); + assertEquals(timeStep, hec.getTimeStep(), "TimeStep should be " + timeStep); } } - // @Test - // public void testPublishSubscribe() { - // boolean f = false, t = true; - // MockHabits mh = new MockHabits(); - // } + @Test + public void testPublishSubscribe() { + System.out.println("\nTesting PublishSubscribe Setting through Habits"); + + MockHabits mh = new MockHabits(); + publishSubscribeSetter = mh.publishSubscribeSetter; + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); + hec.h = publishSubscribeSetter; + publishSubscribe = true; + hec.proc(); + assertEquals(true, hec.isPublishSubscribe(), "PublishSubscribe should be true"); + publishSubscribe = false; + hec.proc(); + + assertEquals(false, hec.isPublishSubscribe(), "PublishSubscribe should be false"); + } @Test public void testNoOutputMemory() { + System.out.println("\nTesting the case where there is no output memory"); + + exec_counter = 0; MockHabits mh = new MockHabits(); outputSetter = mh.outputSetter; m = new Mind(); @@ -140,10 +177,209 @@ public void testNoOutputMemory() { mc.setI(osh); HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); hec.addInput(mc); - hec.setPublishSubscribe(true); m.insertCodelet(hec); m.start(); - // while (outputSetter.) + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(5, exec_counter, "The habit should have been executed 5 times without errors"); + } + + @Test + public void testNoHabitMemoryContainer() { + System.out.println("\nTesting the case where there is no habit to execute"); + + proc_counter = 0; + m = new Mind(); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test") { + @Override + public void proc() { + proc_counter++; + super.proc(); + } + }; + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(proc_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertNull(hec.h, "The habit should be null"); + } + + @Test + public void testNoHabit() { + System.out.println("\nTesting the case where there is a habit memory container but no habit inside it"); + + proc_counter = 0; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test") { + @Override + public void proc() { + proc_counter++; + super.proc(); + } + }; + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(proc_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertNull(hec.h, "The habit should be null"); + } + + @Test + public void testHabitsContainerNameMatching() { + System.out.println("\nTesting the case where there is one Habit Memory Container with correct name"); + + String[] matchingNames = {"testHabits", "TESTHABITS", "TestHabits", "tEsThAbItS"}; + + for (String name : matchingNames) { + exec_counter = 0; + MockHabits mh = new MockHabits(); + simple = mh.simple; + m = new Mind(); + mc = m.createMemoryContainer(name); + Idea sh = new Idea("Simple"); + sh.setValue(simple); + sh.setScope(2); + mc.setI(sh); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(simple, hec.h, "Habit should be the same as the one set in the container with name: " + name); + } + } + + @Test + public void testHabitsContainerNameNotMatching() { + System.out.println("\nTesting the case where there is one Habit Memory Container with incorrect name"); + + String[] nonMatchingNames = {"someOtherName", "habitsTest", "test_habits", "testhabit"}; + + // Test non-matching names (should not find habit) + for (String name : nonMatchingNames) { + System.out.println("\nTesting with container name: " + name); + + proc_counter = 0; + MockHabits mh = new MockHabits(); + simple = mh.simple; + m = new Mind(); + mc = m.createMemoryContainer(name); + Idea sh = new Idea("Simple"); + sh.setValue(simple); + sh.setScope(2); + mc.setI(sh); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test") { + @Override + public void proc() { + proc_counter++; + super.proc(); + } + }; + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(proc_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertNull(hec.h, "Habit should be null for container name: " + name); + } + } + + // Test case for when there is one Habit Memory Container with correct name and one without + // In this case, the codelet should find the habit in the container with the correct name + // and add the other habit to the root idea, but not execute it + @Test + public void testDoubleHabitContainers() { + System.out.println("\nTesting the case where there are two habit memory containers, one with the correct name and one without"); + + proc_counter = 0; + m = new Mind(); + + MockHabits mh = new MockHabits(); + simple = mh.simple; + mc = m.createMemoryContainer("testHabits"); + Idea sh = new Idea("Simple"); + sh.setValue(simple); + sh.setScope(2); + mc.setI(sh); + + notExecuted = mh.notExecuted; + MemoryContainer mc2 = m.createMemoryContainer("someOtherName"); + Idea neh = new Idea("NotExecuted"); + neh.setValue(notExecuted); + neh.setScope(2); + mc2.setI(neh); + + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test") { + @Override + public void proc() { + proc_counter++; + super.proc(); + } + }; + hec.addInput(mc); + hec.addInput(mc2); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(proc_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + + // Should find the habit in the container with the correct name + assertEquals(simple, hec.h, "Habit should not be null for container with correct name"); + + Idea habit_input = global_idea.get("NotExecuted"); + // The other habit should be added to the root idea, but not executed + assertEquals(habit_input, neh, "The habit in the container with incorrect name should be added to the root idea"); } private void doTest() { @@ -189,16 +425,6 @@ private void doTest() { else fail("The output memory object is null"); } } - - abstract class CountableHabit implements Habit { - int count = 0; - - //@Override - //public Idea exec(Idea idea) { - // sup - //} - - } class MockHabits { public MockHabits() { @@ -266,14 +492,45 @@ public Idea exec(Idea idea) { } }; + Habit publishSubscribeSetter = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + root.add(new Idea("publishSubscribe", publishSubscribe)); + root.add(new Idea("someIdea", 123)); + root.add(new Idea("anotherIdea", "abc")); + return root; + } + }; + Habit outputSetter = new Habit() { - public int counter = 0; @Override public Idea exec(Idea idea) { Idea root = new Idea("root", ""); root.add(new Idea("someIdea", 123)); root.add(new Idea("anotherIdea", "abc")); - counter++; + exec_counter++; + return root; + } + }; + + Habit simple = new Habit() { + @Override + public Idea exec(Idea idea) { + global_idea = idea; + Idea root = new Idea("root", ""); + root.add(new Idea("OutputIdeasMemory", 13)); + exec_counter++; + return root; + } + }; + + Habit notExecuted = new Habit() { + @Override + public Idea exec(Idea idea) { + Idea root = new Idea("root", ""); + root.add(new Idea("OutputIdeasMemory", 9999)); + exec_counter++; return root; } }; From 57045e8ee7b54367dfd46ab6c77fa7b74d882e64 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 16 Oct 2025 17:06:27 -0300 Subject: [PATCH 17/21] add some tests --- .../idea/HabitExecutionerCodeletTest.java | 327 +++++++++++++----- 1 file changed, 249 insertions(+), 78 deletions(-) diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 6aa3f1de..29f2c979 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -32,8 +32,9 @@ public class HabitExecutionerCodeletTest { Habit timeStepSetter; Habit publishSubscribeSetter; Habit outputSetter; - Habit simple; Habit notExecuted; + Habit nullIdeaSetter; + Habit emptyIdeaSetter; Mind m; MemoryContainer mc; @@ -69,13 +70,48 @@ private void setUp() { m.start(); } - @Test - public void testName() { - System.out.println("\nTesting Name Setting and Default Name"); - HabitExecutionerCodelet hec = new HabitExecutionerCodelet(); - assertEquals("Default", hec.getName()); - hec = new HabitExecutionerCodelet("MyName"); - assertEquals("MyName", hec.getName(), "Name should be MyName"); + private void doTest() { + Object oo; + Random r = new Random(); + for (int k=0;k<100;k++) { + int major = r.nextInt(100); + if (major < 50) { + mc.setEvaluation(0.7,0); + mc.setEvaluation(0.3,1); + } + else { + mc.setEvaluation(0.3,0); + mc.setEvaluation(0.7,1); + } + int minor = r.nextInt(10); + Idea i = new Idea("value",major); + i.add(new Idea("add",minor)); + moi.setI(i); + long ti = moi.getTimestamp(); + while(moo.getTimestamp() < ti) System.out.print("."); + oo = moo.getI(); + if (oo != null) { + Idea ooi = (Idea) oo; + int sum = (int) ooi.getValue(); + Idea ih = (Idea) mc.getLastI(); + int op; + String ops; + if (ih.getName().equals("Summer")) { + op = 0; + ops = "+"; + } + else { + op = 1; + ops = "-"; + } + System.out.println(ih+" "+major+ops+minor+"="+sum); + if (op == 0) + assertEquals(sum,major+minor); + else + assertEquals(sum,major-minor); + } + else fail("The output memory object is null"); + } } @Test @@ -110,6 +146,15 @@ public void testHabitExecutionerCodeletRandom() { doTest(); } + @Test + public void testName() { + System.out.println("\nTesting Name Setting and Default Name"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet(); + assertEquals("Default", hec.getName()); + hec = new HabitExecutionerCodelet("MyName"); + assertEquals("MyName", hec.getName(), "Name should be MyName"); + } + @Test public void testActivation() { System.out.println("\nTesting Activation Setting through Habits"); @@ -153,12 +198,13 @@ public void testPublishSubscribe() { publishSubscribeSetter = mh.publishSubscribeSetter; HabitExecutionerCodelet hec = new HabitExecutionerCodelet("Name"); hec.h = publishSubscribeSetter; + publishSubscribe = true; hec.proc(); assertEquals(true, hec.isPublishSubscribe(), "PublishSubscribe should be true"); + publishSubscribe = false; hec.proc(); - assertEquals(false, hec.isPublishSubscribe(), "PublishSubscribe should be false"); } @@ -167,6 +213,7 @@ public void testNoOutputMemory() { System.out.println("\nTesting the case where there is no output memory"); exec_counter = 0; + MockHabits mh = new MockHabits(); outputSetter = mh.outputSetter; m = new Mind(); @@ -189,9 +236,10 @@ public void testNoOutputMemory() { @Test public void testNoHabitMemoryContainer() { - System.out.println("\nTesting the case where there is no habit to execute"); + System.out.println("\nTesting the case where there is no habit memory container"); proc_counter = 0; + m = new Mind(); moi = m.createMemoryObject("InputIdeasMemory"); moo = m.createMemoryObject("OutputIdeasMemory"); @@ -221,6 +269,7 @@ public void testNoHabit() { System.out.println("\nTesting the case where there is a habit memory container but no habit inside it"); proc_counter = 0; + m = new Mind(); mc = m.createMemoryContainer("testHabits"); moi = m.createMemoryObject("InputIdeasMemory"); @@ -255,14 +304,15 @@ public void testHabitsContainerNameMatching() { for (String name : matchingNames) { exec_counter = 0; + MockHabits mh = new MockHabits(); - simple = mh.simple; + outputSetter = mh.outputSetter; m = new Mind(); mc = m.createMemoryContainer(name); - Idea sh = new Idea("Simple"); - sh.setValue(simple); - sh.setScope(2); - mc.setI(sh); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); moi = m.createMemoryObject("InputIdeasMemory"); moo = m.createMemoryObject("OutputIdeasMemory"); HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); @@ -278,7 +328,7 @@ public void testHabitsContainerNameMatching() { } catch (Exception e) { fail("An error occurred: " + e.getMessage()); } - assertEquals(simple, hec.h, "Habit should be the same as the one set in the container with name: " + name); + assertEquals(outputSetter, hec.h, "Habit should be the same as the one set in the container with name: " + name); } } @@ -294,13 +344,13 @@ public void testHabitsContainerNameNotMatching() { proc_counter = 0; MockHabits mh = new MockHabits(); - simple = mh.simple; + outputSetter = mh.outputSetter; m = new Mind(); mc = m.createMemoryContainer(name); - Idea sh = new Idea("Simple"); - sh.setValue(simple); - sh.setScope(2); - mc.setI(sh); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); moi = m.createMemoryObject("InputIdeasMemory"); moo = m.createMemoryObject("OutputIdeasMemory"); HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test") { @@ -337,12 +387,12 @@ public void testDoubleHabitContainers() { m = new Mind(); MockHabits mh = new MockHabits(); - simple = mh.simple; + outputSetter = mh.outputSetter; mc = m.createMemoryContainer("testHabits"); - Idea sh = new Idea("Simple"); - sh.setValue(simple); - sh.setScope(2); - mc.setI(sh); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); notExecuted = mh.notExecuted; MemoryContainer mc2 = m.createMemoryContainer("someOtherName"); @@ -375,55 +425,155 @@ public void proc() { } // Should find the habit in the container with the correct name - assertEquals(simple, hec.h, "Habit should not be null for container with correct name"); + assertEquals(outputSetter, hec.h, "Habit should not be null for container with correct name"); Idea habit_input = global_idea.get("NotExecuted"); // The other habit should be added to the root idea, but not executed assertEquals(habit_input, neh, "The habit in the container with incorrect name should be added to the root idea"); } - private void doTest() { - Object oo; - Random r = new Random(); - for (int k=0;k<100;k++) { - int major = r.nextInt(100); - if (major < 50) { - mc.setEvaluation(0.7,0); - mc.setEvaluation(0.3,1); - } - else { - mc.setEvaluation(0.3,0); - mc.setEvaluation(0.7,1); - } - int minor = r.nextInt(10); - Idea i = new Idea("value",major); - i.add(new Idea("add",minor)); - moi.setI(i); - long ti = moi.getTimestamp(); - while(moo.getTimestamp() < ti) System.out.print("."); - oo = moo.getI(); - if (oo != null) { - Idea ooi = (Idea) oo; - int sum = (int) ooi.getValue(); - Idea ih = (Idea) mc.getLastI(); - int op; - String ops; - if (ih.getName().equals("Summer")) { - op = 0; - ops = "+"; - } - else { - op = 1; - ops = "-"; - } - System.out.println(ih+" "+major+ops+minor+"="+sum); - if (op == 0) - assertEquals(sum,major+minor); - else - assertEquals(sum,major-minor); - } - else fail("The output memory object is null"); - } + @Test + public void testNullIdea() { + System.out.println("\nTesting the case where the habit returns a null idea"); + + exec_counter = 0; + + MockHabits mh = new MockHabits(); + nullIdeaSetter = mh.nullIdeaSetter; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + Idea nish = new Idea("NullIdeaSetter"); + nish.setValue(nullIdeaSetter); + nish.setScope(2); + mc.setI(nish); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(5, exec_counter, "The habit should have been executed 5 times without errors"); + } + + @Test + public void testEmptyIdea() { + System.out.println("\nTesting the case where the habit returns an empty idea"); + + exec_counter = 0; + + MockHabits mh = new MockHabits(); + emptyIdeaSetter = mh.emptyIdeaSetter; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + Idea eish = new Idea("EmptyIdeaSetter"); + eish.setValue(emptyIdeaSetter); + eish.setScope(2); + mc.setI(eish); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(5, exec_counter, "The habit should have been executed 5 times without errors"); + } + + @Test + public void testSettingIdeaMemoryObject() { + System.out.println("\nTesting the case where the habit sets an idea to an output memory object"); + + exec_counter = 0; + + MockHabits mh = new MockHabits(); + outputSetter = mh.outputSetter; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); + moi = m.createMemoryObject("InputIdeasMemory"); + moo = m.createMemoryObject("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(5, exec_counter, "The habit should have been executed 5 times without errors"); + + Object oo = moo.getI(); + if (oo != null) { + Idea ooi = (Idea) oo; + int val = (int) ooi.getValue(); + assertEquals(13, val, "The value set in the output memory object should be 13"); + } + else fail("The output memory object is null"); + } + + @Test + public void testSettingIdeaMemoryContainer() { + System.out.println("\nTesting the case where the habit sets an idea to an output memory container"); + + exec_counter = 0; + + MockHabits mh = new MockHabits(); + outputSetter = mh.outputSetter; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); + moi = m.createMemoryObject("InputIdeasMemory"); + MemoryContainer moc = m.createMemoryContainer("OutputIdeasMemory"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moc); + + m.insertCodelet(hec); + m.start(); + + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(5, exec_counter, "The habit should have been executed 5 times without errors"); + + Object oo = moc.getLastI(); + if (oo != null) { + Idea ooi = (Idea) oo; + int val = (int) ooi.getValue(); + assertEquals(13, val, "The value set in the output memory container should be 13"); + } + else fail("The output memory container is empty"); } class MockHabits { @@ -433,6 +583,8 @@ public MockHabits() { Habit summer = new Habit() { @Override public Idea exec(Idea idea) { + exec_counter++; + Idea root = new Idea("root", ""); Idea adder = idea.get("value.add"); int valuetoadd=0; @@ -453,6 +605,8 @@ public Idea exec(Idea idea) { Habit decrementer = new Habit() { @Override public Idea exec(Idea idea) { + exec_counter++; + Idea root = new Idea("root", ""); Idea adder = idea.get("value.add"); int valuetodec=0; @@ -473,6 +627,8 @@ public Idea exec(Idea idea) { Habit actSetter = new Habit() { @Override public Idea exec(Idea idea) { + exec_counter++; + Idea root = new Idea("root", ""); root.add(new Idea("activation", act)); root.add(new Idea("someIdea", 123)); @@ -484,6 +640,8 @@ public Idea exec(Idea idea) { Habit timeStepSetter = new Habit() { @Override public Idea exec(Idea idea) { + exec_counter++; + Idea root = new Idea("root", ""); root.add(new Idea("timeStep", timeStep)); root.add(new Idea("someIdea", 123)); @@ -495,6 +653,8 @@ public Idea exec(Idea idea) { Habit publishSubscribeSetter = new Habit() { @Override public Idea exec(Idea idea) { + exec_counter++; + Idea root = new Idea("root", ""); root.add(new Idea("publishSubscribe", publishSubscribe)); root.add(new Idea("someIdea", 123)); @@ -506,32 +666,43 @@ public Idea exec(Idea idea) { Habit outputSetter = new Habit() { @Override public Idea exec(Idea idea) { + exec_counter++; + global_idea = idea; + Idea root = new Idea("root", ""); root.add(new Idea("someIdea", 123)); root.add(new Idea("anotherIdea", "abc")); - exec_counter++; + root.add(new Idea("OutputIdeasMemory", 13)); return root; } }; - Habit simple = new Habit() { + Habit notExecuted = new Habit() { @Override public Idea exec(Idea idea) { - global_idea = idea; - Idea root = new Idea("root", ""); - root.add(new Idea("OutputIdeasMemory", 13)); exec_counter++; + + Idea root = new Idea("root", ""); + root.add(new Idea("OutputIdeasMemory", 9999)); return root; } }; - Habit notExecuted = new Habit() { + Habit nullIdeaSetter = new Habit() { @Override public Idea exec(Idea idea) { - Idea root = new Idea("root", ""); - root.add(new Idea("OutputIdeasMemory", 9999)); exec_counter++; - return root; + + return null; + } + }; + + Habit emptyIdeaSetter = new Habit() { + @Override + public Idea exec(Idea idea) { + exec_counter++; + + return new Idea("root", ""); } }; } From 6c5abba0d3841096c0d01b64e9033a6ca9a1e83d Mon Sep 17 00:00:00 2001 From: phdaccache Date: Thu, 16 Oct 2025 17:57:28 -0300 Subject: [PATCH 18/21] new test --- .../idea/HabitExecutionerCodeletTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java index 29f2c979..c0e3e10d 100644 --- a/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java +++ b/src/test/java/br/unicamp/cst/representation/idea/HabitExecutionerCodeletTest.java @@ -576,6 +576,56 @@ public void testSettingIdeaMemoryContainer() { else fail("The output memory container is empty"); } + @Test + public void testSettingTwoIdeasTwoMemories() { + System.out.println("\nTesting the case where the habit sets two ideas to two output memories"); + + exec_counter = 0; + + MockHabits mh = new MockHabits(); + outputSetter = mh.outputSetter; + m = new Mind(); + mc = m.createMemoryContainer("testHabits"); + Idea osh = new Idea("OutputSetter"); + osh.setValue(outputSetter); + osh.setScope(2); + mc.setI(osh); + moi = m.createMemoryObject("InputIdeasMemory"); + MemoryContainer moc = m.createMemoryContainer("OutputIdeasMemory"); + moo = m.createMemoryObject("anotherIdea"); + HabitExecutionerCodelet hec = new HabitExecutionerCodelet("test"); + hec.addInput(mc); + hec.addInput(moi); + hec.addOutput(moc); + hec.addOutput(moo); + + m.insertCodelet(hec); + m.start(); + + try { + while(exec_counter < 5) { System.out.print("."); Thread.sleep(1); } + } catch (Exception e) { + fail("An error occurred: " + e.getMessage()); + } + assertEquals(5, exec_counter, "The habit should have been executed 5 times without errors"); + + Object oo = moc.getLastI(); + if (oo != null) { + Idea ooi = (Idea) oo; + int val = (int) ooi.getValue(); + assertEquals(13, val, "The value set in the first output memory container should be 13"); + } + else fail("The first output memory container is empty"); + + oo = moo.getI(); + if (oo != null) { + Idea ooi = (Idea) oo; + String val = (String) ooi.getValue(); + assertEquals("abc", val, "The value set in the second output memory object should be 'abc'"); + } + else fail("The second output memory object is null"); + } + class MockHabits { public MockHabits() { } From b7f0b95e11cc6419196796c2d3552e4e92f13dca Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 21 Oct 2025 19:05:52 -0300 Subject: [PATCH 19/21] fix name --- .../cst/representation/idea/HabitExecutionerCodelet.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index 98fa41aa..b2cd69cd 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -41,6 +41,7 @@ public class HabitExecutionerCodelet extends Codelet { Habit h; Idea root; + String habitName; public HabitExecutionerCodelet() { this.name = "Default"; @@ -60,6 +61,7 @@ public void accessMemoryObjects() { Object value = id.getValue(); if (m.getName().equalsIgnoreCase(this.getName()+"Habits") && value instanceof Habit) { h = (Habit) value; + habitName = id.getName(); } else { root.add((Idea)o); @@ -141,7 +143,7 @@ private void setIdeasToOutputMemories(Idea outputRoot) { if (m instanceof MemoryContainer) { MemoryContainer mc = (MemoryContainer) m; - mc.setI(outputIdea, getActivationValue(outputIdea), this.getName()); + mc.setI(outputIdea, getActivationValue(outputIdea), habitName); } else { m.setI(outputIdea); From c2e4b7ef6bec31bbd76753e7575da20749b760c3 Mon Sep 17 00:00:00 2001 From: phdaccache Date: Tue, 4 Nov 2025 15:52:04 -0300 Subject: [PATCH 20/21] improve comments --- .../cst/representation/idea/HabitExecutionerCodelet.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java index b2cd69cd..eaa3a794 100644 --- a/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java +++ b/src/main/java/br/unicamp/cst/representation/idea/HabitExecutionerCodelet.java @@ -36,6 +36,9 @@ * The codelet looks for ideas inside the root idea whose names match (case insensitive) * the names of its output memories, and sets those ideas to the respective memories. * + * If the output memory is a MemoryContainer, it sets the MemoryObjects inside it + * with the name of the Habit being executed by the HabitExecutionerCodelet itslef. + * * @author rgudwin */ public class HabitExecutionerCodelet extends Codelet { @@ -127,8 +130,8 @@ private void setPublishSubscribeValue(Idea idea) { * that match by name (case insensitive). * * If the memory is a MemoryContainer, it sets the MemoryObjects inside it - * with the name of the HabitExecutionerCodelet itslef. It does so to - * differentiate between different HECs writing to the same MemoryContainer. + * with the name of the Habit being executed by the HabitExecutionerCodelet itslef. + * It does so to differentiate between different Habits writing to the same MemoryContainer. * * @param outputRoot * the root idea that comes from the habit execution From c01c3514e0c3a8d78a850265c696c1c7be427fa7 Mon Sep 17 00:00:00 2001 From: rgudwin Date: Wed, 5 Nov 2025 10:52:00 -0300 Subject: [PATCH 21/21] Setting up 1.6.0 version --- README.md | 4 ++-- build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cd02ac83..d7fb7338 100755 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Note: This library is still under development, and some concepts or features mig ``` dependencies { ... - implementation 'com.github.CST-Group:cst:1.5.0' + implementation 'com.github.CST-Group:cst:1.6.0' } ``` @@ -53,7 +53,7 @@ Sometimes, the version number (tag) in this README gets out of date, as maintain com.github.CST-Group cst - 1.5.0 + 1.6.0 ``` diff --git a/build.gradle b/build.gradle index 87b497e5..d44fedc9 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ java { } -version = '1.5.0' +version = '1.6.0' repositories { mavenCentral() @@ -177,4 +177,4 @@ testlogger { // set to false to hide failed standard out and error streams showFailedStandardStreams true -} \ No newline at end of file +}