class TestCalculator(unittest.TestCase): print("Start of the test", datetime.datetime.now()) def setUp(self): self.calculator = Calculator(random.randint(1, 100)) def test_add(self): calc_value = self.calculator.value + 6 self.assertEqual(calc_value, self.calculator.add(1, 2, 3).value) def test_subtract(self): calc_value = self.calculator.value - 2 self.assertEqual(calc_value, self.calculator.subtract(1, 1).value) def test_mul(self): calc_value = self.calculator.value * 900 self.assertEqual(calc_value, self.calculator.multiply(5, 2, 90).value) def test_divide(self): calc_value = self.calculator.value / 4 self.assertEquals(calc_value, self.calculator.divide(4).value) def test_pow_and_root(self): calc_value = sqrt(self.calculator.value**4) self.assertEqual(calc_value, self.calculator.power(4).root().value) def test_chain(self): calc_value = (((sqrt(self.calculator.value**2)) + 12 - 33) * 10) / 2 self.assertEqual( calc_value, self.calculator.power(2).root().add(4, 8).subtract(11, 22).multiply( 5, 2).divide(2).value) def kek(self): self.assertEqual(1, 2) print("End of the test", datetime.datetime.now())
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): 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