コード例 #1
0
    def test_numeric_range_issue(self):
        print("\n\n\n" + " Test if Numeric Range Checked ".center(75, "#"))
        test_str = "1/x"
        target_str = "1/x**20"
        response = api.check(test_str, target_str)

        self.assertTrue("error" in response, 'Expected "error" in response!')
        self.assertTrue("Too Large Range" in response["error"], 'Expected warning about numeric range "{}"!'.format(response["error"]))
        print("   PASS   ".center(75, "#"))
コード例 #2
0
    def test_unsafe_input(self):
        print("\n\n\n" + " Test if Unsafe Input Detected ".center(75, "#"))
        test_str = "A @ B"
        target_str = "A * B"
        response = api.check(test_str, target_str)

        # Implicitly we're testing no unhandled exceptions.
        self.assertTrue("error" in response, 'Expected "error" in response!')
        print("   PASS   ".center(75, "#"))
コード例 #3
0
    def test_invalid_test_str(self):
        print("\n\n\n" + " Test if Invalid Test Str Detected ".center(75, "#"))
        test_str = "A + B + "
        target_str = "A + B"
        response = api.check(test_str, target_str)

        # Implicitly we're testing no unhandled exceptions.
        self.assertTrue("error" in response, 'Expected "error" in response!')
        self.assertTrue("code" not in response, 'Expected "code" in response!')
        print("   PASS   ".center(75, "#"))
コード例 #4
0
    def test_invalid_plus_minus_values(self):
        print("\n\n\n" + " Test Invalid Plus-Minus Sign Result ".center(75, "#"))
        test_str = "x ± 1"
        target_str_1 = "x/(1 ± 1)"
        target_str_2 = "x/(1 ± -1)"
        response_1 = api.check(test_str, target_str_1)

        self.assertTrue("error" in response_1, 'Expected "error" in response!')
        self.assertTrue("case" in response_1, 'Key "case" not in response!')
        self.assertTrue(response_1["case"] == "-", 'Unexpected "case": "{}"!'.format(response_1["case"]))
        print("Negative case error correctly detected.")

        response_2 = api.check(test_str, target_str_2)

        self.assertTrue("error" in response_2, 'Expected "error" in response!')
        self.assertTrue("case" in response_2, 'Key "case" not in response!')
        self.assertTrue(response_2["case"] == "+", 'Unexpected "case": "{}"!'.format(response_2["case"]))
        print("Positive case error correctly detected.")
        print("   PASS   ".center(75, "#"))
コード例 #5
0
    def test_custom_symbols_accepted(self):
        print("\n\n\n" + " Test if Custom Symbols Work ".center(75, "#"))
        test_str = "test == abcd / d"
        target_str = "test == abc"
        symbols = "test, abcd, abc"
        response = api.check(test_str, target_str, symbols=symbols, check_symbols=False)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "{}"!'.format(response["equal"]))
        print("   PASS   ".center(75, "#"))
コード例 #6
0
    def test_syntax_error(self):
        print("\n\n\n" + " Test if Syntax Errors are Reported ".center(75, "#"))
        test_str = "(a + b +"
        target_str = "a + b"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" in response, 'Expected "error" in response!')
        self.assertTrue("syntax_error" in response, 'Key "syntax_error" not in response!')
        self.assertTrue(response["syntax_error"] == "true", 'Expected "syntax_error" to be "true", got "{}"!'.format(response["syntax_error"]))
        print("   PASS   ".center(75, "#"))
コード例 #7
0
    def test_invalid_target(self):
        print("\n\n\n" + " Test if Invalid Target Detected ".center(75, "#"))
        test_str = "A + B"
        target_str = "A + B + "
        response = api.check(test_str, target_str)

        # Implicitly we're testing no unhandled exceptions.
        self.assertTrue("error" in response, 'Expected "error" in response!')
        self.assertTrue("code" in response, 'Expected "code" in response!')
        self.assertTrue(response["code"] == 400, 'Expected error "code" 400 in response, got "{}"!'.format(response["code"]))
        print("   PASS   ".center(75, "#"))
コード例 #8
0
    def test_missing_plus_minus(self):
        print("\n\n\n" + " Test Missing Plus-Minus Sign ".center(75, "#"))
        test_str = "A ± B"
        target_str = "A + B"
        response = api.check(test_str, target_str)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #9
0
    def test_single_variables_unequal(self):
        print("\n\n\n" + " Test if Two Single Variables can be found Unequal ".center(75, "#"))
        test_str = "x"
        target_str = "y"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols, check_symbols=False)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #10
0
    def test_simplify_fractions_symbolic(self):
        print("\n\n\n" + " Test Fractions can be Simplified for Symbolic not Exact Match ".center(75, "#"))
        test_str = "(2*x*y*x)/(2*x*y*y)"
        target_str = "x/y"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #11
0
    def test_lone_unary_minus(self):
        print("\n\n\n" + " Test Lone Unary Minus is Consistent ".center(75, "#"))
        test_str = "-xyz"
        target_str = "-(xyz)"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #12
0
    def test_main_trig_functions_symbolic(self):
        print("\n\n\n" + " Test if sin, cos and tan and inverses Work Symbolically ".center(75, "#"))
        test_str = "arcsin(x) + arccos(x) + arctan(x) + sin(x)**2 + cos(x)**2 + tan(x)"
        target_str = "1 + tan(x) + arcsin(x) + arccos(x) + arctan(x)"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #13
0
    def test_brackets_expand_symbolic(self):
        print("\n\n\n" + " Test Brackets can be Expanded for Symbolic Match ".center(75, "#"))
        test_str = "(x + 1)(x + 1)"
        target_str = "x**2 + 2*x + 1"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #14
0
    def test_plus_or_minus(self):
        print("\n\n\n" + " Test if The ± Symbol Works ".center(75, "#"))
        test_str = "a ± b"
        target_str = "a ± b"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #15
0
    def test_single_variables_equal(self):
        print("\n\n\n" + " Test if Single Variables can be Equal ".center(75, "#"))
        test_str = "x"
        target_str = "x"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #16
0
    def test_compound_symbols_accepted(self):
        print("\n\n\n" + " Test if Compound Symbols Work ".center(75, "#"))
        test_str = "v_zmf**(2) == v_x**2 + v_y**2"
        target_str = "v_zmf * v_zmf == v_x * v_x + v_y * v_y"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #17
0
    def test_main_trig_functions_capitalised_symbolic(self):
        print("\n\n\n" + " Test if Trig Functions Work with Title Case Names ".center(75, "#"))
        test_str = "ArcSin(x) + ArcCos(x) + ArcTan(x) + Sin(x)**2 + Cos(x)**2 + Tan(x)"
        target_str = "1 + tan(x) + arcsin(x) + arccos(x) + arctan(x)"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #18
0
    def test_addition_order_exact_match(self):
        print("\n\n\n" + " Test if Addition Order matters for Exact Match ".center(75, "#"))
        test_str = "1 + x"
        target_str = "x + 1"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #19
0
    def test_large_bracket_expression(self):
        print("\n\n\n" + " Test Lots of Brackets and ^ in Expression ".center(75, "#"))
        test_str = "720 + 1764 x + 1624 x^2 + 735 x^3 + 175 x^4 + 21 x^5 + x^6"
        target_str = "(x+1)(x+2)(x+3)(x+4)(x+5)(x+6)"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #20
0
    def test_logarithms(self):
        print("\n\n\n" + " Test if Logarithms Work ".center(75, "#"))
        test_str = "x*log(x)/log(10) + ln(3) + ln(2)"
        target_str = "log(x,10)*x + ln(6)"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #21
0
    def test_equations(self):
        print("\n\n\n" + " Test if Equations Can be Parsed and Checked ".center(75, "#"))
        test_str = "x**2 + x + 1 == 0"
        target_str = "x + 1 + x**2 == 0"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #22
0
    def test_disallowed_extra_variables(self):
        print("\n\n\n" + " Enforce Only Allowed Symbols ".center(75, "#"))
        test_str = "sin(exp(sqrt(2*x)))**2 + cos(exp(sqrt(x))**sqrt(2))**2"
        target_str = "1"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols, check_symbols=True)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For enforced symbols, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #23
0
    def test_extra_test_variables(self):
        print("\n\n\n" + " Test N+1 Variable Test Expression ".center(75, "#"))
        test_str = "sin(exp(sqrt(2*x)))**2 + cos(exp(sqrt(x))**sqrt(2))**2"
        target_str = "1"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols, check_symbols=False)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #24
0
    def test_unary_minus_fraction(self):
        print("\n\n\n" + " Test Unary Minus in Fractions ".center(75, "#"))
        test_str = "-x/-y"
        target_str = "x/y"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #25
0
    def test_strict_inequalities(self):
        print("\n\n\n" + " Test if Strict Inequalities Can be Distinguished ".center(75, "#"))
        test_str = "x**2 + x + 1 > 0"
        target_str = "x + 1 + x**2 >= 0"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #26
0
    def test_sqrt_x_squared(self):
        print("\n\n\n" + " Test Square Root of x Squared ".center(75, "#"))
        test_str = "sqrt(x**2)"
        target_str = "x"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #27
0
    def test_derivatives_not_simplifed(self):
        print("\n\n\n" + " Test Derivatives Are Not Simplified ".center(75, "#"))
        test_str = "Derivative(cos(x)**2, x)"
        target_str = "-2 sin(x)cos(x)"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "numeric", 'For these expressions, expected "equality_type" to be "symbolic", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #28
0
    def test_keywords_not_special(self):
        print("\n\n\n" + " Test if Python Keywords are Ignored ".center(75, "#"))
        test_str = "2as + 4for + is + print"
        target_str = "2*a*s + 4*f*o*r + i*s + p*r*i*n*t"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))
コード例 #29
0
def check_maths():
    """Check the equivalence of two mathematical expressions."""
    body = request.get_json(force=True)

    if not (("test" in body) and ("target" in body)):
        print("=" * 50)
        print("ERROR: Ill-formed request!")
        print(body)
        print("=" * 50)
        abort(400)  # Probably want to just abort with a '400 BAD REQUEST'

    target_str = body.get("target")
    test_str = body.get("test")
    description = body.get("description")

    if (target_str == "") or (test_str == ""):
        print("=" * 50)
        if description is not None:
            print(description)
            print("=" * 50)
        print("ERROR: Empty string in request!")
        print("Target: '{0}'\nTest: '{1}'".format(target_str, test_str))
        print("=" * 50)
        abort(400)  # Probably want to just abort with a '400 BAD REQUEST'

    symbols = body.get("symbols")
    check_symbols = str(body.get("check_symbols", "true")).lower() == "true"

    # To reduce computation issues on single-threaded server, institute a timeout
    # for requests. If it takes longer than this to process, return an error.
    # This cannot interrupt numpy's computation, so care must be taken in selecting
    # a value for MAX_REQUEST_COMPUTATION_TIME.
    try:
        with TimeoutProtection(MAX_REQUEST_COMPUTATION_TIME):
            response_dict = maths.check(test_str,
                                        target_str,
                                        symbols=symbols,
                                        check_symbols=check_symbols,
                                        description=description)
            return jsonify(**response_dict)
    except TimeoutException as e:
        print("ERROR: {} - Request took too long to process, aborting!".format(
            type(e).__name__))
        print("=" * 50)
        error_dict = dict(
            target=target_str,
            test=test_str,
            error="Request took too long to process!",
        )
        return jsonify(**error_dict)
コード例 #30
0
    def test_implicit_multiplication(self):
        print("\n\n\n" + " Test that Implicit Multiplication Works ".center(75, "#"))
        test_str = "xyz"
        target_str = "x * y * z"
        symbols = None
        response = api.check(test_str, target_str, symbols=symbols)

        self.assertTrue("error" not in response, 'Unexpected "error" in response!')
        self.assertTrue("equal" in response, 'Key "equal" not in response!')
        self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "{}"!'.format(response["equal"]))
        self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!')
        self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "{}"!'.format(response["equality_type"]))
        self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "{}"!'.format(response["equality_type"]))
        print("   PASS   ".center(75, "#"))