require 'test/unit' require 'faqagent' require 'fileutils' class TestMyAgent < Test::Unit::TestCase def setup if File.exist?('faqagent.rb') FileUtils.copy('faqagent.rb', 'faqagent.rb.save') begin FileUtils.copy('faqagent-api.yaml', 'faqagent-api.yaml.save') rescue; end end @agent = MyAgent.new #@agent.send("reset graph") end def test_defining_hello actual, s = @agent.send("add pattern /^hello/, hello") actual, s = @agent.send("hello") actual, s = @agent.send("> def hello(pattern=nil, input=nil)") actual, s = @agent.send("> if @count == nil; @count = 1; return 'I am ready for my first lesson.'; end") actual, s = @agent.send("> return 'Hello again.'") actual, s = @agent.send("> end # method_def") actual, s = @agent.send("hello") assert_match(/lesson/, actual) actual, s = @agent.send("hi is a synonym for hello") assert_match(/Okay/, actual) actual, s = @agent.send("hi") assert_match(/again/, actual) end def test_find_faq actual, s = @agent.send("find sleep") assert_match(/sleep/, actual) actual, s = @agent.send('find /\bvalue\b/') assert_match(/sleep/, actual) end def test_equals @agent.send("reset graph") @agent.send("add faq: What do you do? answer: I answer faqs.") actual, s = @agent.send("find faq: what do you do") actual, s = assert_match(/I answer faqs/i, actual) @agent.send("what does it do? = what do you do?") actual, s = @agent.send("find faq: what does it do?") assert_match(/I answer faqs/i, actual) @agent.send("what do you do == what can you do") actual, s = @agent.send("find faq: what can you do?") assert_match(/I answer faqs/i, actual) @agent.send("what can it do? = what can you do?") actual, s = @agent.send("find faq: what can it do?") assert_match(/I answer faqs/i, actual) end def teardown File.delete('faqagent.rb') unless !File.exist?('faqagent.rb.save') begin; File.delete('faqagent-api.yaml'); rescue; end if File.exist?('faqagent.rb.save') FileUtils.copy('faqagent.rb.save', 'faqagent.rb') begin; FileUtils.copy('faqagent-api.yaml.save', 'faqagent-api.yaml'); rescue; end end if File.exist?('faqagent.rb') then File.delete('faqagent.rb.save') end if File.exist?('faqagent-api.yaml.save') then File.delete('faqagent-api.yaml.save') end end end