RecognitionMemory { public void reset() { this.production_firing_count.reset(); this.FIRING_TYPE = SavedFiringType.IE_PRODS; } RecognitionMemory(Agent context); RhsFunctionContext getRhsFunctionContext(); void initialize(); void reset(); SymbolImpl instantiate_rhs_value(RhsValue rv, int new_id_level, char new_id_letter, Token tok, WmeImpl w); void fill_in_new_instantiation_stuff(Instantiation inst, boolean need_to_do_support_calculations); void add_preference_to_tm(Preference pref); void remove_preference_from_tm(Preference pref); void do_preference_phase(IdentifierImpl top_goal); public Instantiation newly_created_instantiations; public SavedFiringType FIRING_TYPE; }
@Test public void testRhsFunctionThatCreatesStructure() throws Exception { new CycleCountInput(agent.getInputOutput()); RhsFunctionHandler func = new AbstractRhsFunctionHandler("rhs-structure", 0, 0) { @Override public Symbol execute(RhsFunctionContext context, List<Symbol> arguments) throws RhsFunctionException { Identifier r1 = context.getSymbols().createIdentifier('R'); final SymbolFactory syms = context.getSymbols(); context.addWme(r1, syms.createString("x"), syms.createInteger(1)); context.addWme(r1, syms.createString("y"), syms.createInteger(2)); context.addWme(r1, syms.createString("z"), syms.createInteger(3)); context.addWme(r1, syms.createString("name"), syms.createString("hello")); return r1; }}; agent.getRhsFunctions().registerHandler(func); agent.getTrace().setEnabled(Category.WM_CHANGES, true); agent.getProperties().set(SoarProperties.WAITSNC, true); agent.getProductions().loadProduction("" + "testRhsFunctionThatCreatesStructure\n" + "(state <s> ^superstate nil ^io.input-link.cycle-count 1)\n" + "-->" + "(<s> ^result (rhs-structure))"); agent.runFor(1, RunType.DECISIONS); final Identifier s1 = agent.getSymbols().findIdentifier('S', 1); final MatcherBuilder m = Wmes.matcher(agent); Wme result = m.attr("result").find(s1); assertNotNull(result); final Identifier r1 = result.getValue().asIdentifier(); Wme x, y, z, name; assertNotNull(x = m.reset().attr("x").value(1).find(r1)); assertNotNull(y = m.reset().attr("y").value(2).find(r1)); assertNotNull(z = m.reset().attr("z").value(3).find(r1)); assertNotNull(name = m.reset().attr("name").value("hello").find(r1)); agent.runFor(1, RunType.DECISIONS); assertNull(m.reset().attr("result").find(s1)); assertFalse(agent.getAllWmesInRete().contains(x)); assertFalse(agent.getAllWmesInRete().contains(y)); assertFalse(agent.getAllWmesInRete().contains(z)); assertFalse(agent.getAllWmesInRete().contains(name)); }