sclass GenTesting { O makeGenerators; // voidfunc(L gens, L log) // method to compare generator output & user line S comparison = "eqic"; *(O *makeGenerators) {} MultiSet scoreGenerators(L log) { ret scoreGenerators(log, null); } MultiSet scoreGenerators(L log, BitSet interestingLines) { new MultiSet scores; for (int i = 0; i < l(log); i++) if (interestingLines == null || interestingLines.get(i)) scoreGenerators1(subList(log, 0, i+1), scores); print(/*asciiHeading2("SCORES")*/); for (S name : scores.getTopTen()) print(" [" + scores.get(name) + "] " + name); print(); ret scores; } void scoreGenerators1(L log, MultiSet scores) { if (empty(log)) ret; S line = last(log); log = dropLast(log); genLog_set(log); try { L gens = makeGenerators(log); for (Gen gen : gens) { try { if (compare(callGen(gen), line)) scores.add(gen.name); } catch {} } } finally { genLog_clear(); } } S callSingle(L log, O genName) { genLog_set(log); try { L gens = makeGenerators(log); Gen gen = findByField(gens, "name", genName); if (gen == null) null; ret callGen(gen); } finally { genLog_clear(); } } bool verifySingle(L log, O genName) { if (empty(log)) false; S line = last(log); log = dropLast(log); genLog_set(log); try { L gens = makeGenerators(log); Gen gen = findByField(gens, "name", genName); if (gen == null) false; try { if (compare(callGen(gen), line)) true; } catch {} false; } finally { genLog_clear(); } } L makeGenerators(L log) { new L gens; callF(makeGenerators, gens, log); ret gens; } // returns score int scoreGenerator(L log, S genName) { int score = 0; for (int i = 1; i < l(log); i++) { S expect = log.get(i), s = null; bool ok = false; try { s = callSingle(subList(log, 0, i), genName); ok = compare(s, expect); } catch e { s = exceptionToStringShort(e); } if (ok) { ++score; print(genName + " OK: " + s + (eq(s, expect) ? "" : " / " + expect)); } else print(genName + " NO [" + s + "]: " + expect); } print(); ret score; } bool compare(S a, S b) { if (eq(comparison, "eq")) ret eq(a, b); else if (eq(comparison, "eqic")) ret eqic(a, b); else if (eq(comparison, "match")) ret match(a, b); else throw fail("Unknown comparison: " + comparison); } // run a single generator on all lines and print each line void debugSingle(L log, S name) { for (int i = 0; i < l(log); i++) debugSingle1(subList(log, 0, i+1), name); } void debugSingle1(L log, S genName) { S line = last(log); log = dropLast(log); genLog_set(log); try { L gens = makeGenerators(log); Gen gen = findByField(gens, "name", genName); if (gen == null) ret; bool ok = false; try { ok = compare(callGen(gen), line); } catch {} print((ok ? "OK" : "NO") + " " + line); } finally { genLog_clear(); } } }