!7 p-exp { bool newEngine = contains(args, "new"); if (newEngine) BakedBot.defaultSnippetID = #1018381; if (contains(args, "bake")) if (newEngine) ai_bakeABot(BakedBot.defaultSnippetID, ll(#1018382)); else bakeTheBot(); if (contains(args, 'advanced)) advancedTests(); callTests([[ test1 test2 test3 test4 test5 test4b test6 test7 test7b test7c test7d test7e test8 test8b test8c test8d test9 test9b test9c test10 test11 test12 test13 test13b test14 test15 test16 ]]); consoleStatus(print("BASE TESTS DONE. DOING ADVANCED TESTS.")); advancedTests(); consoleStatus(print("BASE & ADVANCED TESTS OK")); } svoid advancedTests { callTests([[ test14b ]]); } svoid callTests(S s) { for (S test : tlftj(s)) { consoleStatus(test); callMC(test); } } svoid test1 { BakedBot bot = bakedBotWithRules([[ inputContainsTokens("=>") && !inputStartsWith("!rule ") => output(Should I store this rule?) ]]); bot.setAuthorized(true); bot.check("bla => blubb", "Should I store this rule?"); assertEqualsVerbose("", unnull(callAnswerMethod(bot, "bla <= blubb"))); bot.check("!rule bla => bla", "Rule saved as *. Have 2 rules."); } svoid test2 { BakedBot bot = bakedBotWithRules([[ input(what is $chicken $wire?) => output(a $wire made from $chicken) ]]); bot.check("what is pork sausage?", "a sausage made from pork"); } svoid test3 { BakedBot bot = bakedBotWithRules([[ input(What is $gertrude $afraid_of?) && fact($gertrude is $afraid_of $wolves) => output($wolves) ]]); bot.setList("Fact-to-fact rules", [[ fact($gertrude is a $sheep) && fact($sheep are $afraid_of_wolves) => fact($gertrude is $afraid_of_wolves) ]]); bot.setList("Random Facts", [[ sheep are afraid of wolves Cats are afraid of dogs. Mice are afraid of cats. klaus is a sheep ]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); bot.answerAuthed("!deriveFacts"); assertEqualsVerbose_match("Klaus is afraid of wolves", bot.getList("Derived facts")); pnl((L) call(bot.bot, 'mL_facts)); call(bot.bot, 'setDebug, true); bot.check("What is Klaus afraid of", "Wolves"); } svoid test4 { BakedBot bot = bakedBotWithRules([[ i(what are the features) && allFacts($x is a feature|$x are a feature) => o($x1, $x2 [...] and $x_n) ]]); bot.setList("Random Facts", [[ fun is a feature love is a feature drinks are a feature music is a feature ]]); bot.check("what are the features", "fun, love, drinks and music"); } svoid test4b { BakedBot bot = bakedBotWithRules([[ i(what is that one $feature again) && allFacts($x is a $feature|$x are a $feature) => o(do you mean $x1, $x2 [...] or $x_n?) ]]); bot.setList("Random Facts", [[ fun is a feature love is a feature drinks are a feature music is a feature ]]); bot.check("what is that one feature again", "Do you mean fun, love, drinks or music?"); } svoid test5 { S rule = [[ [id: qohpbitnzaqfexmz] i(what is rule $x) => evalOutput(trim(getString(call(ai_context(), 'getRule, $x), 'originalText))) ]]; BakedBot bot = bakedBotWithRules(rule); bot.check("what is rule qohpbitnzaqfexmz", trim(rule)); } svoid test6 { BakedBot bot = bakedBotWithRules([[i($John is $in_the_playground) && $John != what => o(yo)]]); bot.check("bla is bla", "yo"); bot.check("what is bla", null); } svoid test7 { bakedBotWithRules([[i(bla) && $a, $b = eval(joinWithComma(pair("x", "y"))) => o($b and $a)]]).check("bla", "y and x"); } svoid test7b { bakedBotWithRules([[i(bla) && $a, $b = eval(joinWithComma(pair("bla bla", "this and that"))) => o($b and $a)]]).check("bla", "this and that and bla bla"); } svoid test7c { bakedBotWithRules([[i(bla) && $a, $b = eval(pair("bla bla", "this and that")) => o($b and $a)]]).check("bla", "this and that and bla bla"); } svoid test7d { bakedBotWithRules([[i(bla) && $a, $b, $c = eval(ll("let's", "do", "it")) => o($c $b $a)]]).check("bla", "it do let's"); } svoid test7e { bakedBotWithRules([[i(bla) && $a, $b, $c = eval(litorderedset("let's", "do", "it")) => o($c $b $a)]]).check("bla", "it do let's"); } sS mineralsRule = [[ [id: zrpcdxxfqzgdkzof] fact(I saw $a_man $lick $minerals) && fact($_q_licked is past tense for $_q_lick) => newID($the_man) && fact($the_man was $a_man) && fact(I saw $the_man) && fact($the_man $licked $minerals) ]]; svoid test8 { bakedBotWithRules(mineralsRule).check("!factsFrom i saw a girl eat frogs", "No new facts found"); // no result because there is no past tense for "eat" } svoid test8b { bakedBotWithRulesAndFacts(mineralsRule, [["licked" is past tense for "lick"]]) .check("!factsFrom i saw a girl eat frogs", "No new facts found"); // still no result because there is no past tense for "eat" } svoid test8c { BakedBot bot = bakedBotWithRulesAndFacts(mineralsRule, [["licked" is past tense for "lick"]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); S s = bot.answer_verbose("!factsFrom [debug] i saw a girl lick walls"); print("l(s)= " + l(s)); assertNotNull(printStruct(jmatchDollarVars([[ $x was a girl I saw $x $x $licked walls ]], s)); } svoid test8d { bakedBotWithRulesAndFacts(joinWithEmptyLines(mineralsRule, [[ [id: xxrmapvwhesonlyo] unresolvedFact($x is past tense for $_q_y) && eval(ai_isVar($x) && !ai_isVar($y)) => output(What is the past tense of $_q_y?) ]]), [["licked" is past tense for "lick"]]) .check("!askBackAboutFact i saw a girl eat frogs", [[What is the past tense of "eat"?]]); } // !deriveFacts with rules containing eval svoid test9 { new BakedBot bot; bot.setList("Fact-to-fact rules", [[ eval(1==1) => fact(ok) ]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); bot.answerAuthed("!deriveFacts"); assertEqualsVerbose_match("ok", bot.getList("Derived facts")); } // !deriveFacts with rules containing "$x in eval(...") svoid test9b { new BakedBot bot; bot.setList("Fact-to-fact rules", [[ $x in eval(ll("a", "b")) => fact($x is ok) ]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); bot.answerAuthed("!deriveFacts"); assertEqualsVerbose_match([[ a is ok b is ok ]], bot.getList("Derived facts")); } // !deriveFacts with rules containing "$x, $y in eval(...") svoid test9c { new BakedBot bot; bot.setList("Fact-to-fact rules", [[ $x, $y in eval(ll(pair("a", "b"), pair("c", "d"))) => fact($x and $y are ok) ]]); setOptAll(bot.bot, ai_deriveFacts_debug := true, ai_applyFactToFactRules_debug := true); bot.answerAuthed("!deriveFacts"); assertEqualsVerbose_match([[ a and b are ok c and d are ok ]], bot.getList("Derived facts")); } svoid test10 { BakedBot bot = bakedBotWithRulesAndFacts([[ i(is $love $nice) && eval(ai_isTrue($love + " is " + $nice)) => o(yo) ]], [[love is nice]]); bot.check("is love nice", "yo"); bot.check("is love green", ""); } svoid test11 { BakedBot bot = bakedBotWithRules([[ i(yo $x) => o[javaTokNoQuotes](well: "$x") ]]); bot.check("yo test", [[well: "test"]]); } svoid test12 { BakedBot bot = bakedBotWithRules([[ anyInput() => outputEval("You said " + ai_input()) ]]); bot.check("horse", "You said horse"); } svoid test13 { BakedBot bot = bakedBotWithRules([[ input[re]([abc]{3}) => o(triggered) ]]); bot.check("aa", ""); bot.check("aaa", "triggered"); bot.check("bab", "triggered"); bot.check("bdb", ""); bot.check("xx ccc yy", "triggered"); } svoid test13b { BakedBot bot = bakedBotWithRules([[ input[re](das ist #ADJ_BILLIG#) => o(ja) ]]); bot.lists.setText("Ctx Macros (German)", [[ ADJ_BILLIG = (_(billig|fast geschenkt|preiswert|(preis|)günstig)(|e|e[mnrs])_) ]]); bot.check("das ist fast geschenkt yo", "ja"); bot.check("das ist billig", "ja"); bot.check("das ist teuer", ""); } svoid test14 { BakedBot bot = bakedBotWithRules([[ phrase[words](hello $x) => o(i am $x) ]]); bot.useIterate(true); bot.check("hello you", "i am you"); bot.check("yo hello guy yes", "i am guy"); } svoid test14b { BakedBot bot = bakedBotWithRules([[ phrase(hello $x) => o(i am $x) ]]); bot.useIterate(true); bot.check("hello you", "i am you"); bot.check("yo hello guy yes", "i am guy"); } svoid test15 { BakedBot bot = bakedBotWithRules([[ i(test) => i(bla) i(bla) => o(ok) ]]); bot.check("test", "ok"); } svoid test16 { BakedBot bot = bakedBotWithRules([[ [id: jpltfkfmtbfiorxu] i(do i have any mails|do i have any mail|do i have any emails) => o(you have news from creator awards) [id: fwobkcfddsldvrhb] followingUpOn(jpltfkfmtbfiorxu) && i(please open it|please open|open|open it|on the screen|on screen) => o("here you go sir") ]]); bot.check("do i have any mails", "you have news from creator awards"); bot.check("open it", "here you go sir"); }