def test_square_root(self): logger = logging.getLogger() test_case = [[4], [25], [2], [-1], ['a']] expected_result = [2, 5, 1.4142135623730951, None, None] for i in range(len(expected_result)): if expected_result[i] == calculator.square_root(test_case[i]): print('{} Square Root-{}\nTest Case: {}\nExpected: {}\nOutput: {}'.format( datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), i, test_case[i], expected_result[i], calculator.square_root(test_case[i]))) print('Pass\n') logger.info('Square Root-{}, {}, {}, {}, Pass, '.format( i, ' '.join((str(x) for x in test_case[i])), calculator.square_root(test_case[i]), expected_result[i])) else: print('{} Square Root-{}\nTest Case: {}\nExpected: {}\nOutput: {}'.format( datetime.datetime.now().strftime("%Y-%m-%d %H:%M"), i, test_case[i], expected_result[i], calculator.square_root(test_case[i]))) logger.info('Square Root-{}, {}, {}, {}, Fail, '.format( i, ' '.join((str(x) for x in test_case[i])), calculator.square_root(test_case[i]), expected_result[i])) print('Fail\n') print('------------------------------------------')
def test_square_root(self): self.assertEqual(cl.square_root(0), 0.0) self.assertEqual(cl.square_root(1), 1.0) self.assertEqual(cl.square_root(4), 2.0) self.assertEqual(cl.square_root(1.2), 1.095) with self.assertRaises(ValueError): cl.square_root(-2) with self.assertRaises(TypeError): cl.square_root('abc') cl.square_root(True)
def prob3(a,b): """Calculate and return the length of the hypotenuse of a right triangle. Do not use any methods other than those that are imported from the 'calculator' module. Parameters: a (float): the length one of the sides of the triangle. b (float): the length the other nonhypotenuse side of the triangle. Returns: The length of the triangle's hypotenuse. """ return calc.square_root(calc.add(calc.mult(a,a),calc.mult(b,b)))
def prob3(a,b): """Calculate and return the length of the hypotenuse of a right triangle. Do not use any methods other than those that are imported from the 'calculator' module. Parameters: a (float): the length one of the sides of the triangle. b (float): the length the other nonhypotenuse side of the triangle. Returns: The length of the triangle's hypotenuse. """ import calculator leg_1 = calculator.product(a,a) leg_2 = calculator.product(b,b) sum_squared = calculator.sum(leg_1,leg_2) hypotenuse = calculator.square_root(sum_squared) return hypotenuse
def SquareRoot(self, request, context): print("[DEBUG] %s" % request) resp = calc_pb2.Number() resp.value = calculator.square_root(request.value) return resp
def SquareRoot(self, request, context): print("Recieved Request with input: ", request.value) response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response
def SquareRoot(self, request, context): response = calculator_pb2.Number() print("Server response prepared with type: ", type(response), response) response.value = calculator.square_root(request.value) return response
def SquareRoot(self, request, context): print('GRPC Server SquareRoot called with:', request.value) response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response
def squareRoot(number): return str(calculator.square_root(number))
def SquareRoot(self, request, context): response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response
def test_square_root_integers(self): sq = square_root(2345.23) self.assertEqual(sq, 48.42757478957624)
def test_square_root_integers(self): sq = square_root(144) self.assertEqual(sq, 12)
def testSquare_root(self): self.assertEqual(4.0, square_root(16)) self.assertEqual(7.0, square_root(60 - 11)) self.assertEqual(3.872983346207417, square_root(15)) self.assertEqual(8, square_root(2 * 32)) self.assertEqual(4.949747468305833, square_root(24.5))
def getValue(self, value): # this is an exposed method return calculator.square_root(value)
def test_squareroot(self): assert 5 == calculator.square_root(25)
def test_sqroot(self): assert 2 == calculator.square_root(4)
def SquareRoot(self, request, context): print("Executando Square") response = calculator_pb2.Number() response.value = calculator.square_root(request.value) return response
def SquareRoot(self, request, context): response = calculator_pb2.Test() response.value, response.val = calculator.square_root( request.value, request.test) return response