def test_returns_division(self): for ltv in super()._TEST_VALUES: for rtv in super()._TEST_VALUES: op = pydician.DivideOp(pydician.LiteralValueOp(ltv), pydician.LiteralValueOp(rtv)) if rtv == 0: with self.assertRaises(ZeroDivisionError): op.run() else: self.assertEqual(op.run(), ltv / rtv)
def test_returns_unmodified(self): test_values = [ None, True, False, 0, 1, -1, 0.5, -0.5, 'Something', 'Something else' ] for tv in test_values: self.assertEqual(pydician.LiteralValueOp(tv).run(), tv)
def test_returns_multiplication(self): for ltv in super()._TEST_VALUES: for rtv in super()._TEST_VALUES: op = pydician.MultiplyOp(pydician.LiteralValueOp(ltv), pydician.LiteralValueOp(rtv)) self.assertEqual(op.run(), ltv * rtv)
def test_returns_subtraction(self): for ltv in super()._TEST_VALUES: for rtv in super()._TEST_VALUES: op = pydician.SubtractOp(pydician.LiteralValueOp(ltv), pydician.LiteralValueOp(rtv)) self.assertEqual(op.run(), ltv - rtv)
def test_returns_arithmetic_negate(self): for tv in super()._TEST_VALUES: op = pydician.NegateOp(pydician.LiteralValueOp(tv)) self.assertEqual(op.run(), -tv)
def test_returns_int(self): op = pydician.SingleDieRollOp( pydician.DieOp(pydician.LiteralValueOp(6))) result = op.run() self.assertEqual(type(result), int)
def test_die_generates_int(self): op = pydician.DieOp(pydician.LiteralValueOp(6)) die = op.run() self.assertEqual(type(die()), int)
def test_returns_callable(self): op = pydician.DieOp(pydician.LiteralValueOp(6)) self.assertTrue(callable(op.run()))
def test_returns_not_equals_to(self): for lv in super()._TEST_VALUES: for rv in super()._TEST_VALUES: op = pydician.NotEqualOp(pydician.LiteralValueOp(lv), pydician.LiteralValueOp(rv)) self.assertEqual(op.run(), 1 if lv != rv else 0)
def test_returns_greater_than_or_equals_to(self): for lv in super()._TEST_VALUES: for rv in super()._TEST_VALUES: op = pydician.GreaterOrEqualOp(pydician.LiteralValueOp(lv), pydician.LiteralValueOp(rv)) self.assertEqual(op.run(), 1 if lv >= rv else 0)
def test_returns_less_than(self): for lv in super()._TEST_VALUES: for rv in super()._TEST_VALUES: op = pydician.SmallerOp(pydician.LiteralValueOp(lv), pydician.LiteralValueOp(rv)) self.assertEqual(op.run(), 1 if lv < rv else 0)