Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

27
LINES

< > BotCompany Repo | #1008973 // ctxTestRule - test if a rule fires on input; uses current ctxContext - calls addTestResult

JavaX fragment (include)

1  
static void ctxTestRule(S input, S ruleName) {
2  
  ctxTestRule("", input, ruleName);
3  
}
4  
5  
static void ctxTestRule(S prelude, S input, S ruleName) {
6  
  //ruleName = addPrefix("Agent#", ruleName);
7  
  S desc = prelude + input + " -> " + ruleName;
8  
  print("\nTesting: " + desc);
9  
  try {
10  
    ctxContext().rulesFired.clear();
11  
    ctxClearOutput();
12  
    ctxProcessInput(input);
13  
    ctxProcessRules();
14  
    ctxDefaultOnEmptyOutput();
15  
    S output = ctxGetOutput();
16  
    bool ok1 = ctxContext().rulesFired.contains(ruleName);
17  
    if (!ok1) desc += " was: " + struct(ctxContext().rulesFired);
18  
    bool ok2 = nempty(output);
19  
    if (!ok2)
20  
      desc += " no output";
21  
    else
22  
      desc += " output: " + quote(output);
23  
    addTestResult(desc, (boolToInt(ok1)+boolToInt(ok2))*50);
24  
  } catch e {
25  
    addTestResult(desc, e);
26  
  }
27  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008973
Snippet name: ctxTestRule - test if a rule fires on input; uses current ctxContext - calls addTestResult
Eternal ID of this version: #1008973/14
Text MD5: ea45bafe28ce8261e8a0869439052009
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-14 19:51:43
Source code size: 833 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 527 / 570
Version history: 13 change(s)
Referenced in: [show references]