def test_multiplication(self): self.assertTrue(state.is_done(ircbot.cmd_calc("1 * 1"))) self.assertEqual(ircbot.cmd_calc("1 * 1").value, "1") self.assertTrue(state.is_done(ircbot.cmd_calc("-1 * 1"))) self.assertEqual(ircbot.cmd_calc("-1 * 1").value, "-1") self.assertTrue(state.is_done(ircbot.cmd_calc("0.1 * 0.1"))) self.assertEqual(ircbot.cmd_calc("0.1 * 0.1").value, "0.01")
def test_division(self): self.assertTrue(state.is_done(ircbot.cmd_calc("1 / 1"))) self.assertEqual(ircbot.cmd_calc("1 / 1").value, "1") self.assertTrue(state.is_done(ircbot.cmd_calc("1 / 2"))) self.assertEqual(ircbot.cmd_calc("1 / 2").value, "0") self.assertTrue(state.is_done(ircbot.cmd_calc("1.0 / 2"))) self.assertEqual(ircbot.cmd_calc("1.0 / 2").value, "0.5")
def test_subtraction(self): self.assertTrue(state.is_done(ircbot.cmd_calc("1 - 1"))) self.assertEqual(ircbot.cmd_calc("1 - 1").value, "0") self.assertTrue(state.is_done(ircbot.cmd_calc("-1 - 1"))) self.assertEqual(ircbot.cmd_calc("-1 - 1").value, "-2") self.assertTrue(state.is_done(ircbot.cmd_calc("0.6 - 0.5"))) self.assertEqual(ircbot.cmd_calc("0.6 - 0.5").value, "0.1")
def test_addition(self): self.assertTrue(state.is_done(ircbot.cmd_calc("1 + 1"))) self.assertEqual(ircbot.cmd_calc("1 + 1").value, "2") self.assertTrue(state.is_done(ircbot.cmd_calc("-1 + 1"))) self.assertEqual(ircbot.cmd_calc("-1 + 1").value, "0") self.assertTrue(state.is_done(ircbot.cmd_calc("0.5 + 0.5"))) self.assertEqual(ircbot.cmd_calc("0.5 + 0.5").value, "1.0")
def test_none(self): self.assertTrue(state.is_next(ircbot.cmd_calc(None)))
def test_incorrect_parenthesis(self): self.assertTrue(state.is_next(ircbot.cmd_calc("2 * ((1 + 2)"))) self.assertEqual(ircbot.cmd_calc("2 * ((1 + 2)").value, "2 * ((1 + 2)")
def test_correct_parenthesis(self): self.assertTrue(state.is_done(ircbot.cmd_calc("2 * (1 + 2)"))) self.assertEqual(ircbot.cmd_calc("2 * (1 + 2)").value, "6")
def test_division_by_zero(self): self.assertTrue(state.is_next(ircbot.cmd_calc("1 / 0"))) self.assertEqual(ircbot.cmd_calc("1 / 0").value, "1 / 0") self.assertTrue(state.is_next(ircbot.cmd_calc("1.0 / 0"))) self.assertEqual(ircbot.cmd_calc("1.0 / 0").value, "1.0 / 0")
def test_single_negative_number_float(self): self.assertTrue(state.is_done(ircbot.cmd_calc("-1.0"))) self.assertEqual(ircbot.cmd_calc("-1.0").value, "-1.0")
def test_single_positive_number(self): self.assertTrue(state.is_done(ircbot.cmd_calc("1"))) self.assertEquals(ircbot.cmd_calc("1").value, "1")
def test_not_math(self): self.assertTrue(state.is_next(ircbot.cmd_calc("foo +1")))