class TestCalculator(unittest.TestCase): def setUp(self): self.calculator = Calculator(random.randint(1, 100)) #print(self.calculator.value) self.timestart = time.time() def tearDown(self): print(time.time() - self.timestart) def test_add(self): calc_value = self.calculator.value self.assertEqual(self.calculator.add(1, 2, 3).value, calc_value + 6) def test_mul(self): calc_value = self.calculator.value self.assertEqual( self.calculator.multiply(5, 2, 90).value, calc_value * 900) def test_divide(self): calc_value = self.calculator.value self.assertEqual(self.calculator.divide(2, 3).value, calc_value / 6) def test_accuracy(self): calc_value = self.calculator.value self.assertEqual( self.calculator.add(3).root(12).power(12, integer_power=True).value, calc_value + 3) def test_chain(self): calc_value = self.calculator.value self.assertEqual( self.calculator.add(7, -5, 0).divide(2, 1 / 2, 3).power(2).add(127).value, ((calc_value + 2) / 3)**2 + 127) def test_float(self): calc_value = self.calculator.value self.assertEqual( self.calculator.root(6).divide(10, 2, 1 / 2).multiply(2.28).value, (calc_value**(1 / 6)) / 10 * 2.28) def test_divide_by_zero(self): with self.assertRaises(ValueError): self.calculator.divide(10, 0) def test_long_calc(self): calc_value = self.calculator.value for i in range(500000): self.calculator.power(100) self.calculator.root(100) self.assertTrue(-1e-6 < self.calculator.value - calc_value < 1e-6)
class TestCalculator(unittest.TestCase): def setUp(self): self.calculator = Calculator(1) def test_add(self): calc_value = self.calculator.value self.assertEqual(self.calculator.add(1, 2, 3).value, calc_value + 6) def test_mul(self): calc_value = self.calculator.value self.assertEqual( self.calculator.multiply(5, 2, 90).value, calc_value * 900) def test_divide(self): calc_value = self.calculator.value self.assertEqual(self.calculator.divide(2, 3).value, calc_value / 6) def kek(self): self.assertEqual(1, 2) def test_power(self): calc_value = self.calculator.value self.assertEqual(self.calculator.power(2, 3).value, calc_value**6) def test_root(self): calc_value = self.calculator.value self.assertEqual( self.calculator.root(2, 3).value, calc_value**(1. / 6)) def test_power_add_mul(self): calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.power(2, 5).add(12, 18).multiply(5, 6).value, (calc_value**10 + 30) * 30) def test_add_mul(self): self.calculator = Calculator(random.random() * 20) calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.add(12, 17).multiply(11, 12).value, (calc_value + 29) * 132) def test_xor(self): calc_value = self.calculator.value self.assertEqual(self.calculator.xor(3, 4).value, calc_value ^ 7) def test_xor2(self): calc_value = self.calculator.value self.assertEqual(self.calculator.xor(3, 3).value, calc_value ^ 0)
class TestCalculator(unittest.TestCase): def setUp(self): self.calculator = Calculator(randint(1, 100000)) def test_add(self): """ Test add function with regular data :rtype: object """ print('Start time: ', datetime.now().minute, 'm ', datetime.now().second, 's ', datetime.now().microsecond, 'ms') calc_value = self.calculator.value self.assertEqual(self.calculator.add(1, 2, 3).value, calc_value + 6) def test_mul(self): calc_value = self.calculator.value self.assertEqual(self.calculator.multiply(5, 2, 90).value, calc_value * 900) def test_divide(self): calc_value = self.calculator.value self.assertEquals(self.calculator.divide(2, 3).value, calc_value / 6) def test_power(self): calc_value = self.calculator.value self.assertEqual(self.calculator.power(4).root(2).value, calc_value**2) def test_power_zero(self): calc_value = 0 self.calculator.value = 0 self.assertEqual(self.calculator.power(5).root(7).value, 0) def test_root(self): calc_value = self.calculator.value self.assertEqual(self.calculator.root(2).value, sqrt(calc_value)) print('End time: ', datetime.now().minute, 'm ', datetime.now().second, 's ', datetime.now().microsecond, 'ms') def test_all(self): calc_value = self.calculator.value self.assertEqual(self.calculator.multiply(6, 3, 1, 9, 4).root(8).add(6, 2, 1).divide(4, 5).value, (sqrt(sqrt(sqrt(calc_value*648)))+9)/20)
class TestCalculator(unittest.TestCase): def setUp(self): self.calculator = Calculator(randint(0, 100)) def test_add(self): print('Start: ' + str(datetime.datetime.now().second) + ' ' + str(datetime.datetime.now().microsecond)) """ Test add function with regular data :rtype: object """ calc_value = self.calculator.value self.assertEqual(self.calculator.add(1, 2, 3).value, calc_value + 6) def test_mul(self): calc_value = self.calculator.value self.assertEqual( self.calculator.multiply(5, 2, 90).value, calc_value * 900) def test_mul_zero(self): self.calculator.value = 4 calc_value = self.calculator.value self.assertEqual(self.calculator.multiply(5, 2, 90, 0).value, 0) def test_divide(self): calc_value = self.calculator.value self.assertEqual(self.calculator.divide(2, 3).value, calc_value / 6) def test_divide_int(self): self.calculator.value = 20 calc_value = self.calculator.value self.assertEqual( self.calculator.divide(2, 4, integer_divide=True).value, calc_value // 8) def test_subtract(self): calc_value = self.calculator.value self.assertEqual( self.calculator.subtract(1, 2).value, calc_value - (1 + 2)) def test_subtract_negative(self): self.calculator.value = 10 calc_value = self.calculator.value self.assertEqual( self.calculator.subtract(-11, -2).value, calc_value + 11 + 2) def test_power(self): calc_value = self.calculator.value self.assertEqual(self.calculator.power(1, 2).value, calc_value**2) def test_zero_power(self): self.calculator = 10 self.assertEqual(self.calculator.power(1, 2, 0).value, 1) def test_negative_power(self): self.calculator.value = 10 calc_value = self.calculator.value self.assertEqual((self.calculator.power(-1, -2).value + 1) // 1, calc_value**2) def test_root(self): calc_value = self.calculator.value self.assertEqual(self.calculator.root().value, sqrt(calc_value)) def test_zero_root(self): self.calculator.value = 0 calc_value = self.calculator.value self.assertEqual(self.calculator.root().value, 0) print('End: ' + str(datetime.datetime.now().second) + ' ' + str(datetime.datetime.now().microsecond)) def test_all(self): self.calculator.value = 40 calc_value = self.calculator.value self.assertEqual( self.calculator.add(3, 5, 6, 9, self=self.calculator.power( 5, self=(self.calculator.root()))).value, sqrt(calc_value)**5 + 3 + 5 + 6 + 9) #3+5+6+9+( (sqrt(value))^5) def kek(self): self.assertEqual(1, 2)
class TestCalculator(unittest.TestCase): def setUp(self): print('Set_up test begin:', time.asctime()) self.calculator = Calculator(random.randint(1, 1000)) print('Set_up test end:', time.asctime(), '\n --------------') def test_add(self): print('test_add begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual(self.calculator.add(1, 2, 3).value, calc_value + 6) print('test_add end:', time.asctime(), '\n --------------') def test_mul(self): print('test_mul begin:', (time.asctime())) calc_value = self.calculator.value self.assertEqual( self.calculator.multiply(5, 2, 90).value, calc_value * 900) print('test_mul end:', time.asctime(), '\n --------------') def test_divide(self): print('test_divide begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual(self.calculator.divide(2, 3).value, calc_value / 6) print('test_divide end:', time.asctime(), '\n --------------') def test_power(self): print('test_power begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual(self.calculator.power(2, 3).value, calc_value**6) print('test_power end:', time.asctime(), '\n --------------') def test_power_long(self): print('test_power_long begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual( self.calculator.power(2, 3, 3, 4, 4, 5).value, calc_value**1440) print('test_root_long end:', time.asctime(), '\n --------------') def test_power_smaller(self): print('test_power_smaller begin:', time.asctime()) calc_value = self.calculator.value self.assertLessEqual( self.calculator.power(10, 2).value, calc_value**100) print('test_power_smaller end:', time.asctime(), '\n --------------') def test_root_zero(self): print('test_root_zero begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual(self.calculator.root(0).value, calc_value) print('test_root_zero end:', time.asctime(), '\n --------------') def test_power_zero(self): print('test_root_zero begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual(self.calculator.power(0).value, 1) print('test_root_zero end:', time.asctime(), '\n --------------') def test_root(self): print('test_root begin:', time.asctime()) calc_value = self.calculator.value self.assertEqual(self.calculator.root(2, 3).value, calc_value**(1 / 6)) print('test_root end:', time.asctime(), '\n --------------') print('Использованное число:', calc_value)
class TestCalculator(unittest.TestCase): def setUp(self): self.calculator = Calculator(1) def test_add(self): self.calculator.value = random.random() * 100 calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.add(1, 22, 3, 0).value, calc_value + 26) def test_mul(self): self.calculator.value = random.random() * 100 calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.multiply(5, 2, 90).value, calc_value * 900) def test_divide(self): self.calculator.value = random.random() * 100 calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.divide(5, 3, 1, 7).value, calc_value / 105) def test_subtract(self): self.calculator.value = random.random() * 100 calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.subtract(8, 10, 37).value, calc_value - 55) def test_power(self): get_start_time("power") self.calculator = Calculator(random.random() * 100) calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.power(1.3, 3.7).value, calc_value**(1.3 * 3.7)) get_end_time("power") def test_root(self): get_start_time("root") self.calculator = Calculator(random.random() * 100) calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.root(1.9 * 4.5).value, calc_value**(1 / (1.9 * 4.5))) get_end_time("root") def test_root_divide_subtract(self): get_start_time("root_divide_subtract") self.calculator = Calculator(random.random() * 1000000) calc_value = self.calculator.value self.assertEqual( self.calculator.root(2, 3).divide(5, 3.2).subtract(228, 666).value, (calc_value**(1 / 6)) / (5 * 3.2) - 228 - 666) get_end_time("root_divide_subtract") def test_multi_power_add(self): get_start_time("multi_power_add") self.calculator = Calculator(random.random() * 100) calc_value = self.calculator.value self.assertAlmostEqual( self.calculator.multiply(1.2, 3.4).power(2, 1.3).add(13, 19).value, (calc_value * 1.2 * 3.4)**(2 * 1.3) + (13 + 19)) Calculator(3).add().multiply() get_end_time("multi_power_add")
class TestCalculator(unittest.TestCase): def setUp(self): global cnt cnt += 1 print('Test', cnt, ': ', clock()) self.calculator = Calculator(randint(-1000, 1000)) def test_add(self): self.assertEqual(self.calculator.value + 6, self.calculator.add(1, 2, 3).value) self.assertEqual(self.calculator.value + 3 * INF, self.calculator.add(INF, INF, INF).value) # maxTest self.assertRaises(TypeError, self.calculator.add, 'asda') # typeErorTest self.assertRaises(TypeError, self.calculator.add, '1212 1212') # typeErorWithNumberInStringTest self.assertEqual(self.calculator.value - 500, self.calculator.add(-500).value) # negativeTest self.assertEqual(self.calculator.value + eps + eps, self.calculator.add(eps, eps).value) # minTest def test_multiply(self): self.assertEqual(self.calculator.value * 900, self.calculator.multiply(5, 2, 90).value) self.assertEqual(self.calculator.value * INF * INF, self.calculator.multiply(INF, INF).value) # maxTest self.assertEqual(self.calculator.value * 0 * 5, self.calculator.multiply(0, 5).value) # zeroTest self.assertEqual(self.calculator.value * -500, self.calculator.multiply(-500).value) # negativeTest self.assertRaises(TypeError, self.calculator.multiply, 'asda') # typeErorTest self.assertRaises(TypeError, self.calculator.multiply, '1212 1212') # typeErorWithNumberInStringTest self.assertEqual(self.calculator.value * -500 * -500, self.calculator.multiply( -500, -500).value) # negativeAndNegativeTest self.assertEqual(self.calculator.value * eps * eps, self.calculator.multiply(eps, eps).value) # minTest def test_divide(self): self.assertAlmostEqual(self.calculator.value / 9, self.calculator.divide(3, 3).value) self.assertAlmostEqual(self.calculator.value / INF / INF, self.calculator.divide(INF, INF).value) #maxTest self.assertAlmostEqual(self.calculator.value / eps / eps, self.calculator.divide(eps, eps).value) #minTest self.assertAlmostEqual(self.calculator.value / -5 / 100, self.calculator.divide( -5, 100).value) #negativeTest self.assertRaises(TypeError, self.calculator.divide, 'asda') # typeErorTest self.assertRaises(ZeroDivisionError, self.calculator.divide, 0) # typeErorTest self.assertRaises(TypeError, self.calculator.divide, '1212 1212') # typeErorWithNumberInStringTest def test_power(self): if self.calculator.value > 0: self.assertAlmostEqual(self.calculator.value**0, self.calculator.power(0).value) # zeroTest self.assertAlmostEqual(self.calculator.value**2, self.calculator.power(2).value) self.assertAlmostEqual(self.calculator.value**5, self.calculator.power(5).value) self.assertAlmostEqual(self.calculator.value**200, self.calculator.power(200).value) # maxTest self.assertAlmostEqual( self.calculator.value**-200, self.calculator.power(-200).value) # maxTest self.assertRaises(TypeError, self.calculator.power, 'asda') # typeErorTest self.assertRaises(TypeError, self.calculator.power, '1212 1212') # typeErorWithNumberInStringTest self.calculator.value = -200 self.assertAlmostEqual( self.calculator.value, self.calculator.power(10).value ) # baseNegativeTest return vales_last , becouse pow(10) is not exist def test_root(self): print(self.calculator.value) if self.calculator.value > 0: self.assertAlmostEqual(self.calculator.value**(1 / 2), self.calculator.root(2).value) self.assertAlmostEqual( self.calculator.value, self.calculator.root(0).value ) # zeroTest, return vales_last , becouse root(0) is not exist self.assertAlmostEqual(self.calculator.value**(1 / 5), self.calculator.root(5).value) self.assertAlmostEqual(self.calculator.value**(1 / 200), self.calculator.root(200).value) # maxTest self.assertRaises(TypeError, self.calculator.root, 'asda') # typeErorTest self.assertRaises(TypeError, self.calculator.root, '1212 1212') # typeErorWithNumberInStringTest self.calculator.value = -200 self.assertAlmostEqual( self.calculator.value, self.calculator.root(10).value ) # baseNegativeTest return vales_last , becouse root(10) is not exist def test_subtract(self): self.assertAlmostEqual(self.calculator.value - 6, self.calculator.subtract(1, 2, 3).value) self.assertAlmostEqual(self.calculator.value - 3 * INF, self.calculator.subtract(INF, INF, INF).value) # maxTest self.assertRaises(TypeError, self.calculator.subtract, 'asda') # typeErorTest self.assertRaises(TypeError, self.calculator.subtract, '1212 1212') # typeErorWithNumberInStringTest self.assertAlmostEqual( self.calculator.value + 500, self.calculator.subtract(-500).value) # negativeTest self.assertAlmostEqual(self.calculator.value - eps - eps, self.calculator.subtract(eps, eps).value) # minTest