require 'alicebot' require 'test/unit' class TestALICEBot < Test::Unit::TestCase def setup @agent = ALICEBot.new actual = @agent.send("alice loud") assert_match(/0/, actual.to_s) end def test_hello actual = @agent.send("hello") assert_match(/Hi/, actual.to_s) actual = @agent.send("alice: help") assert_match(/Richard Wallace/, actual.to_s) actual = @agent.send("Alice: loud") assert_match(/2/, actual.to_s) actual = @agent.send("Alice: threshhold") assert_match(/-1/, actual.to_s) # delete the existing rules actual, s = @agent.send('alice: delete rule 1') assert_match(/Okay/, actual) actual, s = @agent.send('alice: delete all the rules, please') assert_match(/Okay/, actual) actual, s = @agent.send('alice: show rules') assert_match(//, actual) actual, s = @agent.send('alice: delete rule 1') assert_match(/rules/, actual) actual = @agent.send('ALICE: if response =~ /JUDGE/ then score = -1 end') assert_match(/Okay/, actual.to_s) actual, score = @agent.send("haha") assert_match(/JUDGE/, actual) assert_equal(score,1) actual = @agent.send('Alice: if response =~ /YourBot/ then score = -1 end') assert_match(/Okay/, actual.to_s) actual, score = @agent.send("alice: show rules") assert_match(/if.*\nif/m, actual) actual = @agent.send('Alice: if response =~ /JUDGE/ then response = "foo!" end') assert_match(/Okay/, actual.to_s) actual = @agent.send('haha') assert_match(/foo!/, actual.to_s) actual = @agent.send('Alice: if response =~ /foo!/ then response = "bar!!" end') assert_match(/Okay/, actual.to_s) actual = @agent.send('haha') assert_match(/bar!!/, actual.to_s) actual = @agent.send('alice: delete rule 1000') assert_match(/The rules go from 1 to 4/, actual.to_s) actual = @agent.send('alice: please delete the rule number 1') assert_match(/Okay/, actual.to_s) actual = @agent.send('alice: show the rules') assert_match(/if.*\nif.*\nif/m, actual.to_s) actual = @agent.send('alice: set the safety level to high please') assert_match(/Okay/, actual) actual = @agent.send('alice: if response =~ /ALICE/ then score -= 1 end') assert_match(/can't/, actual) actual = @agent.send('alice: please turn the safe level off.') assert_match(/Okay/, actual) actual = @agent.send('alice: if response =~ /ALICE/ then score -= 1 end') assert_match(/Okay/, actual) end end