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

68
LINES

< > BotCompany Repo | #1025616 - Auto-Test philosophy engine [OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 788K of libraries. Click here for Pure Java version (11431L/64K).

!7

cmodule TestPhilosophyEngine > DynPrintLog {
  sS program = [[
    program (
      count
    
      count => proc {
        while (i < 100):
          inc i
      }
    ) with declarations (static int i;)
      and init code (
        bot.addNativePredicate("i < 100",
        () -> i < 100);
        bot.addNativePredicate("inc i",
          () -> {
            ++i;
            print("Incremented i to " + i);
            true;
          });
    ) should end with (i == 100)
  ]];

  start-thread {
    new PhilosophyBot1 main;
    main.program = program;
    main.run();
    pnl(main.facts);

    for (SS map : main.listFactsMatching(
      [[ program var_p
         with declarations var_d
         and init code var_i
         should end with var_c
      ]])) {
      S program = map.get("var_p"), declarations = map.get("var_d"),
        initCode = map.get("var_i"), endCondition = map.get("var_c");
      printVars(+program, +endCondition);

      // Now build some JavaX code!

      S javax = joinWithEmptyLines(
        declarations,
        "static new PhilosophyBot1 bot;",
        "p {",
        "bot.program = " + quote(program) + ";",
        initCode,
        "bot.run();",
        "assertTrueVerbose(" + endCondition + ");",
        "}");

      printWithIndent("JAVAX> ", javax);

      // do the JavaX super-magic

      Class c = veryQuickJava(javax);

      // now we can call the function we just made

      callMain(c);

      // assert succeeded, so we're good

      print("Test succeeded!");
    }
  }
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025616
Snippet name: Auto-Test philosophy engine [OK]
Eternal ID of this version: #1025616/15
Text MD5: a8181532550129323c547445f0017c24
Transpilation MD5: ebde80d489bc187123ea2c98b1916ff9
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-09 13:10:41
Source code size: 1534 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 6 / 613
Version history: 14 change(s)
Referenced in: [show references]