示例#1
0
class TestMyNumber(unittest.TestCase):
    def setUp(self):
        self.num = MyNumber()

    def test_add(self):
        x = random.randint(1, 10)
        y = random.randint(1, 10)
        result = self.num.add(x, y)
        self.assertTrue(result == (x + y))

    def test_sub(self):
        x = random.randint(1, 10)
        y = random.randint(1, 10)
        result = self.num.sub(x, y)
        self.assertTrue(result == (x - y))

    def test_mul(self):
        x = random.randint(1, 10)
        y = random.randint(1, 10)
        result = self.num.mul(x, y)
        self.assertTrue(result == (x * y))

    def test_div(self):
        x = random.randint(1, 10)
        y = random.randint(1, 10)
        result = self.num.div(x, y)
        self.assertTrue(result == (x / y))

    def tearDown(self):
        del self.num
示例#2
0
class TestMyNumber(unittest.TestCase):
    def setUp(self):
        self.num = MyNumber()

    def test_add(self):
        x = random.randint(1,10)
        y = random.randint(1,10)
        result = self.num.add(x,y)
        self.assertTrue(result == (x + y))

    def test_sub(self):
        x = random.randint(1,10)
        y = random.randint(1,10)
        result = self.num.sub(x,y)
        self.assertTrue(result == (x - y))

    def test_mul(self):
        x = random.randint(1,10)
        y = random.randint(1,10)
        result = self.num.mul(x,y)
        self.assertTrue(result == (x * y))

    def test_div(self):
        x = random.randint(1,10)
        y = random.randint(1,10)
        result = self.num.div(x,y)
        self.assertTrue(result == (x / y))

    def tearDown(self):
        del self.num