require 'test/unit' require 'logicbot' BasicSocket.do_not_reverse_lookup = true class TestLogicBot < Test::Unit::TestCase def setup @agent = LogicBot.new actual, s = @agent.send("reset graph") assert_match(/Okay/, actual) end def test_save_mode begin; File.delete("test_graph.yaml"); rescue; end #@actual, s = @agent.send("set save mode off") #assert_match(/off/, actual) actual, s = @agent.send("mercury is the first planet from the sun") actual, s = @agent.send("quit") assert_match(/save.*graph/, actual) actual, s = @agent.send("save the graph to test_graph.yaml") assert_match(/test_graph.yaml saved/, actual) assert(File.exist?("test_graph.yaml")) actual, s = @agent.send("quit") assert_match(/(?:quit|bye)/i, actual) end def test_save_mode2 begin; File.delete("test_graph.yaml"); rescue; end actual, s = @agent.send("jupiter is a planet") assert_match(/Okay/, actual) actual, s = @agent.send("quit") assert_match(/Do.*save.*graph/, actual) actual, s = @agent.send("no") assert_match(/(?:quit|bye)/, actual) end def test_save_mode3 actual, s = @agent.send("load graph graph.yaml") actual, s = @agent.send("forget that mars is a planet") actual, s = @agent.send("set save mode off") actual, s = @agent.send("mars is a planet") actual, s = @agent.send("quit") assert_match(/do.*save.*graph/i, actual) actual, s = @agent.send("no") assert_match(/^(?:quit|bye)$/, actual) end def test_rules actual, s = @agent.send("logicagent: if input =~ /\\bmy\\b/ then response.gsub!(/\\bmy\\b/, 'your') end") assert_match(/Okay/i, actual) actual, s = @agent.send("My table is orange") actual, s = @agent.send("orange is a color") actual, s = @agent.send("what color is my table?") assert_match(/your table is orange/i, actual) actual, s = @agent.send("My table is round") actual, s = @agent.send("it = my table") actual, s = @agent.send("round is a shape") actual, s = @agent.send("what shape is it?") assert_match(/\bround\b/, actual) actual, s = @agent.send("quit") assert_match(/Do.*save.*graph/, actual) actual, s = @agent.send("no") assert_match(/(?:quit|bye)/, actual) end def teardown begin; File.delete("test_graph.yaml"); rescue; end end end