コード例 #1
0
    def test_syntax_errors(self):
        """
        Test a lot of math strings that give syntax errors

        Rather than have a lot of self.assertRaises, make a loop and keep track
        of those that do not throw a `ParseException`, and assert at the end.
        """
        bad_math_list = [
            '11+',
            '11*',
            'f((x)',
            'sqrt(x^)',
            '3f(x)',  # Not 3*f(x)
            '3|4',
            '3|||4'
        ]
        bad_exceptions = {}
        for math in bad_math_list:
            try:
                preview.latex_preview(math)
            except pyparsing.ParseException:
                pass  # This is what we were expecting. (not excepting :P)
            except Exception as error:  # pragma: no cover
                bad_exceptions[math] = error
            else:  # pragma: no cover
                # If there is no exception thrown, this is a problem
                bad_exceptions[math] = None

        self.assertEquals({}, bad_exceptions)
コード例 #2
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
    def test_syntax_errors(self):
        """
        Test a lot of math strings that give syntax errors

        Rather than have a lot of self.assertRaises, make a loop and keep track
        of those that do not throw a `ParseException`, and assert at the end.
        """
        bad_math_list = [
            '11+',
            '11*',
            'f((x)',
            'sqrt(x^)',
            '3f(x)',  # Not 3*f(x)
            '3|4',
            '3|||4'
        ]
        bad_exceptions = {}
        for math in bad_math_list:
            try:
                preview.latex_preview(math)
            except pyparsing.ParseException:
                pass  # This is what we were expecting. (not excepting :P)
            except Exception as error:  # pragma: no cover
                bad_exceptions[math] = error
            else:  # pragma: no cover
                # If there is no exception thrown, this is a problem
                bad_exceptions[math] = None

        self.assertEquals({}, bad_exceptions)
コード例 #3
0
 def test_no_input(self):
     """
     With no input (including just whitespace), see that no error is thrown.
     """
     self.assertEquals('', preview.latex_preview(''))
     self.assertEquals('', preview.latex_preview('  '))
     self.assertEquals('', preview.latex_preview(' \t '))
コード例 #4
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_no_input(self):
     """
     With no input (including just whitespace), see that no error is thrown.
     """
     self.assertEquals('', preview.latex_preview(''))
     self.assertEquals('', preview.latex_preview('  '))
     self.assertEquals('', preview.latex_preview(' \t '))
コード例 #5
0
ファイル: test_preview.py プロジェクト: edx/openedx-calc
 def test_number_sci_notation(self):
     """ Numbers with scientific notation should display nicely """
     self.assertEqual(
         preview.latex_preview('6.0221413E+23'),
         r'6.0221413\!\times\!10^{+23}'
     )
     self.assertEqual(
         preview.latex_preview('-6.0221413E+23'),
         r'-6.0221413\!\times\!10^{+23}'
     )
コード例 #6
0
ファイル: test_preview.py プロジェクト: jswope00/griffinx
 def test_number_sci_notation_suffix(self):
     """ Test numbers with both of these. """
     self.assertEquals(
         preview.latex_preview('6.0221413E+23k'),
         r'6.0221413\!\times\!10^{+23}\text{k}'
     )
     self.assertEquals(
         preview.latex_preview('-6.0221413E+23k'),
         r'-6.0221413\!\times\!10^{+23}\text{k}'
     )
コード例 #7
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_number_sci_notation(self):
     """ Numbers with scientific notation should display nicely """
     self.assertEquals(
         preview.latex_preview('6.0221413E+23'),
         r'6.0221413\!\times\!10^{+23}'
     )
     self.assertEquals(
         preview.latex_preview('-6.0221413E+23'),
         r'-6.0221413\!\times\!10^{+23}'
     )
コード例 #8
0
    def test_complicated(self):
        """
        Given complicated input, ensure that exactly the correct string is made.
        """
        self.assertEquals(
            preview.latex_preview('11*f(x)+x^2*(3||4)/sqrt(pi)'),
            r'11\cdot \text{f}(x)+\frac{x^{2}\cdot (3\|4)}{\sqrt{\pi}}')

        self.assertEquals(
            preview.latex_preview('log10(1+3/4/Cos(x^2)*(x+1))',
                                  case_sensitive=True),
            (r'\log_{10}\left(1+\frac{3}{4\cdot \text{Cos}\left(x^{2}\right)}'
             r'\cdot (x+1)\right)'))
コード例 #9
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
    def test_complicated(self):
        """
        Given complicated input, ensure that exactly the correct string is made.
        """
        self.assertEquals(
            preview.latex_preview('11*f(x)+x^2*(3||4)/sqrt(pi)'),
            r'11\cdot \text{f}(x)+\frac{x^{2}\cdot (3\|4)}{\sqrt{\pi}}'
        )

        self.assertEquals(
            preview.latex_preview('log10(1+3/4/Cos(x^2)*(x+1))',
                                  case_sensitive=True),
            (r'\log_{10}\left(1+\frac{3}{4\cdot \text{Cos}\left(x^{2}\right)}'
             r'\cdot (x+1)\right)')
        )
コード例 #10
0
ファイル: test_preview.py プロジェクト: edx/openedx-calc
 def test_product_keep_going(self):
     """
     Complex products/quotients should split into many '\frac's when needed.
     """
     self.assertEqual(
         preview.latex_preview('2/3*4/5*6'),
         r'\frac{2}{3}\cdot \frac{4}{5}\cdot 6'
     )
コード例 #11
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_product_keep_going(self):
     """
     Complex products/quotients should split into many '\frac's when needed.
     """
     self.assertEquals(
         preview.latex_preview('2/3*4/5*6'),
         r'\frac{2}{3}\cdot \frac{4}{5}\cdot 6'
     )
コード例 #12
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_sum(self):
     """ Sums should combine its elements. """
     # Use 'x' as the first term (instead of, say, '1'), so it can't be
     # interpreted as a negative number.
     self.assertEquals(
         preview.latex_preview('-x+2-3+4', variables=['x']),
         '-x+2-3+4'
     )
コード例 #13
0
ファイル: test_preview.py プロジェクト: edx/openedx-calc
 def test_sum(self):
     """ Sums should combine its elements. """
     # Use 'x' as the first term (instead of, say, '1'), so it can't be
     # interpreted as a negative number.
     self.assertEqual(
         preview.latex_preview('-x+2-3+4', variables=['x']),
         '-x+2-3+4'
     )
コード例 #14
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_power_simple(self):
     """ Powers should wrap the elements with braces correctly. """
     self.assertEquals(preview.latex_preview('2^3^4'), '2^{3^{4}}')
コード例 #15
0
 def test_product_single_frac(self):
     """ Division should ignore parens if they are extraneous. """
     self.assertEquals(preview.latex_preview('(2+3)/(4+5)'),
                       r'\frac{2+3}{4+5}')
コード例 #16
0
 def test_product_mult_only(self):
     r""" Simple products should combine with a '\cdot'. """
     self.assertEquals(preview.latex_preview('2*3'), r'2\cdot 3')
コード例 #17
0
 def test_power_parens(self):
     """ Powers should ignore the parenthesis of the last math. """
     self.assertEquals(preview.latex_preview('2^3^(4+5)'), '2^{3^{4+5}}')
コード例 #18
0
 def test_function_log2(self):
     """ log2 function should be handled specially. """
     self.assertEquals(preview.latex_preview('log2(3)'), r'\log_2(3)')
コード例 #19
0
 def test_function_tall(self):
     r""" Functions surrounding a tall element should have \left, \right """
     self.assertEquals(preview.latex_preview('f(3^2)', functions=['f']),
                       r'\text{f}\left(3^{2}\right)')
コード例 #20
0
 def test_variable_subscript(self):
     """ Things like 'epsilon_max' should display nicely """
     self.assertEquals(
         preview.latex_preview('epsilon_max', variables=['epsilon_max']),
         r'\epsilon_{max}')
コード例 #21
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_product_single_frac(self):
     """ Division should ignore parens if they are extraneous. """
     self.assertEquals(
         preview.latex_preview('(2+3)/(4+5)'),
         r'\frac{2+3}{4+5}'
     )
コード例 #22
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_product_big_frac(self):
     """ Division should combine with '\frac'. """
     self.assertEquals(
         preview.latex_preview('2*3/4/5'),
         r'\frac{2\cdot 3}{4\cdot 5}'
     )
コード例 #23
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_product_mult_only(self):
     r""" Simple products should combine with a '\cdot'. """
     self.assertEquals(preview.latex_preview('2*3'), r'2\cdot 3')
コード例 #24
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_parallel(self):
     r""" Parallel items should combine with '\|'. """
     self.assertEquals(preview.latex_preview('2||3'), r'2\|3')
コード例 #25
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_power_parens(self):
     """ Powers should ignore the parenthesis of the last math. """
     self.assertEquals(preview.latex_preview('2^3^(4+5)'), '2^{3^{4+5}}')
コード例 #26
0
 def test_function_log10(self):
     """ log10 function should be handled specially. """
     self.assertEqual(preview.latex_preview('log10(3)'), r'\log_{10}(3)')
コード例 #27
0
 def test_greek(self):
     """ Variable names that are greek should be formatted accordingly. """
     self.assertEquals(preview.latex_preview('pi'), r'\pi')
コード例 #28
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_sum_tall(self):
     """ A complicated expression should not hide the tallness. """
     self.assertEquals(
         preview.latex_preview('(2+3^2)'),
         r'\left(2+3^{2}\right)'
     )
コード例 #29
0
 def test_function_simple(self):
     """ Valid function names should be escaped. """
     self.assertEquals(preview.latex_preview('f(3)', functions=['f']),
                       r'\text{f}(3)')
コード例 #30
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_function_sqrt(self):
     """ Sqrt function should be handled specially. """
     self.assertEquals(preview.latex_preview('sqrt(3)'), r'\sqrt{3}')
コード例 #31
0
 def test_function_sqrt(self):
     """ Sqrt function should be handled specially. """
     self.assertEquals(preview.latex_preview('sqrt(3)'), r'\sqrt{3}')
コード例 #32
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_greek(self):
     """ Variable names that are greek should be formatted accordingly. """
     self.assertEquals(preview.latex_preview('pi'), r'\pi')
コード例 #33
0
 def test_power_simple(self):
     """ Powers should wrap the elements with braces correctly. """
     self.assertEquals(preview.latex_preview('2^3^4'), '2^{3^{4}}')
コード例 #34
0
 def test_number_suffix(self):
     """ Suffixes should be escaped. """
     self.assertEquals(preview.latex_preview('1.618%'), r'1.618\text{%}')
コード例 #35
0
 def test_parallel(self):
     r""" Parallel items should combine with '\|'. """
     self.assertEquals(preview.latex_preview('2||3'), r'2\|3')
コード例 #36
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_function_tall(self):
     r""" Functions surrounding a tall element should have \left, \right """
     self.assertEquals(
         preview.latex_preview('f(3^2)', functions=['f']),
         r'\text{f}\left(3^{2}\right)'
     )
コード例 #37
0
 def test_product_big_frac(self):
     """ Division should combine with '\frac'. """
     self.assertEquals(preview.latex_preview('2*3/4/5'),
                       r'\frac{2\cdot 3}{4\cdot 5}')
コード例 #38
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_function_simple(self):
     """ Valid function names should be escaped. """
     self.assertEquals(
         preview.latex_preview('f(3)', functions=['f']),
         r'\text{f}(3)'
     )
コード例 #39
0
 def test_sum_tall(self):
     """ A complicated expression should not hide the tallness. """
     self.assertEquals(preview.latex_preview('(2+3^2)'),
                       r'\left(2+3^{2}\right)')
コード例 #40
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_function_log2(self):
     """ log2 function should be handled specially. """
     self.assertEquals(preview.latex_preview('log2(3)'), r'\log_2(3)')
コード例 #41
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_variable_simple(self):
     """ Simple valid variables should pass through. """
     self.assertEquals(preview.latex_preview('x', variables=['x']), 'x')
コード例 #42
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_number_suffix(self):
     """ Suffixes should be escaped. """
     self.assertEquals(preview.latex_preview('1.618%'), r'1.618\text{%}')
コード例 #43
0
 def test_number_simple(self):
     """ Simple numbers should pass through. """
     self.assertEquals(preview.latex_preview('3.1415'), '3.1415')
コード例 #44
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_variable_subscript(self):
     """ Things like 'epsilon_max' should display nicely """
     self.assertEquals(
         preview.latex_preview('epsilon_max', variables=['epsilon_max']),
         r'\epsilon_{max}'
     )
コード例 #45
0
 def test_variable_simple(self):
     """ Simple valid variables should pass through. """
     self.assertEquals(preview.latex_preview('x', variables=['x']), 'x')
コード例 #46
0
ファイル: test_preview.py プロジェクト: jolyonb/edx-platform
 def test_number_simple(self):
     """ Simple numbers should pass through. """
     self.assertEquals(preview.latex_preview('3.1415'), '3.1415')