Exemple #1
0
    def test_function_invalid(self, parser, ctx):
        """Test that an invalid Blackbird function raises the correct exception"""
        func = blackbirdParser.FunctionContext(parser, ctx)
        func.getText = lambda: "Hello"

        with pytest.raises(NameError, match="Unknown function Hello"):
            _func(func, None)
Exemple #2
0
    def test_function_arctanh(self, parser, ctx, num):
        """Test that a Blackbird arctanh function is properly called"""
        n = "0.543"
        expected = float(n)

        func = blackbirdParser.FunctionContext(parser, ctx)
        func.ARCTANH = lambda: True
        expression = num(n, num_type='float')
        assert _func(func, expression) == np.arctanh(expected)
Exemple #3
0
    def test_function_arccos(self, parser, ctx, num):
        """Test that a Blackbird arccos function is properly called"""
        n = "0.543"
        expected = float(n)

        func = blackbirdParser.FunctionContext(parser, ctx)
        func.ARCCOS = lambda: True
        expression = num(n)
        assert np.allclose(_func(func, expression), np.arccos(expected))
Exemple #4
0
 def test_function_sqrt(self, parser, ctx, n, expected, num):
     """Test that a Blackbird sqrt function is properly called"""
     func = blackbirdParser.FunctionContext(parser, ctx)
     func.SQRT = lambda: True
     expression = num(n)
     assert _func(func, expression) == np.sqrt(expected)
Exemple #5
0
 def test_function_arccosh(self, parser, ctx, n, expected, num):
     """Test that a Blackbird arccosh function is properly called"""
     func = blackbirdParser.FunctionContext(parser, ctx)
     func.ARCCOSH = lambda: True
     expression = num(n)
     assert _func(func, expression) == np.arccosh(expected)
Exemple #6
0
 def test_function_tan(self, parser, ctx, n, expected, num):
     """Test that a Blackbird tan function is properly called"""
     func = blackbirdParser.FunctionContext(parser, ctx)
     func.TAN = lambda: True
     expression = num(n, num_type='float')
     assert _func(func, expression) == np.tan(expected)
Exemple #7
0
 def test_function_arcsinh(self, parser, ctx, n, expected, num):
     """Test that a Blackbird arcsinh function is properly called"""
     func = blackbirdParser.FunctionContext(parser, ctx)
     func.ARCSINH = lambda: True
     expression = num(n)
     assert np.allclose(_func(func, expression), np.arcsinh(expected))
Exemple #8
0
 def test_function_cosh(self, parser, ctx, n, expected, num):
     """Test that a Blackbird cosh function is properly called"""
     func = blackbirdParser.FunctionContext(parser, ctx)
     func.COSH = lambda: True
     expression = num(n)
     assert np.isclose(_func(func, expression), np.cosh(expected))