A Python robot that edits Wikipedia and interacts with people over IRC https://en.wikipedia.org/wiki/User:EarwigBot
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test_calc.py 1.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. import unittest
  3. import support
  4. from commands.calc import Command
  5. class TestCalc(support.CommandTestCase):
  6. def setUp(self):
  7. super(TestCalc, self).setUp(Command)
  8. def test_check(self):
  9. self.assertFalse(self.command.check(self.make_msg("bloop")))
  10. self.assertFalse(self.command.check(self.make_join()))
  11. self.assertTrue(self.command.check(self.make_msg("calc")))
  12. self.assertTrue(self.command.check(self.make_msg("CALC", "foo")))
  13. def test_ignore_empty(self):
  14. self.command.process(self.make_msg("calc"))
  15. self.assertReply("what do you want me to calculate?")
  16. def test_maths(self):
  17. tests = [
  18. ("2 + 2", "2 + 2 = 4"),
  19. ("13 * 5", "13 * 5 = 65"),
  20. ("80 / 42", "80 / 42 = 40/21 (approx. 1.9047619047619047)"),
  21. ("2/0", "2/0 = undef"),
  22. ("π", "π = 3.141592653589793238"),
  23. ]
  24. for test in tests:
  25. q = test[0].strip().split()
  26. self.command.process(self.make_msg("calc", *q))
  27. self.assertReply(test[1])
  28. if __name__ == "__main__":
  29. unittest.main(verbosity=2)