Пример #1
0
    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)
Пример #3
0
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)))
Пример #4
0
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
Пример #5
0
 def SquareRoot(self, request, context):
     print("[DEBUG] %s" % request)
     resp = calc_pb2.Number()
     resp.value = calculator.square_root(request.value)
     return resp
Пример #6
0
 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
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
def squareRoot(number):
    return str(calculator.square_root(number))
Пример #10
0
 def SquareRoot(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
Пример #11
0
 def test_square_root_integers(self):
     sq = square_root(2345.23)
     self.assertEqual(sq, 48.42757478957624)
Пример #12
0
 def test_square_root_integers(self):
     sq = square_root(144)
     self.assertEqual(sq, 12)
Пример #13
0
 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))
Пример #14
0
 def getValue(self, value):  # this is an exposed method
     return calculator.square_root(value)
 def test_squareroot(self):
     assert 5 == calculator.square_root(25)
Пример #16
0
 def test_sqroot(self):
     assert 2 == calculator.square_root(4)
Пример #17
0
 def SquareRoot(self, request, context):
     print("Executando Square")
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
Пример #18
0
 def SquareRoot(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.square_root(request.value)
     return response
Пример #19
0
 def SquareRoot(self, request, context):
     response = calculator_pb2.Test()
     response.value, response.val = calculator.square_root(
         request.value, request.test)
     return response