示例#1
0
def test_eq15_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(1), Item(2)), number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[1=2\]'
                                           'This equation has no solution.'
                                           '\\newline ')
def test_eq32_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 1, 1)), SquareRoot(Item(16))))
    assert eq.auto_resolution(dont_display_equations_name=True,
                              decimal_result=2) == \
        wrap_nb('\[x=\\sqrt{\mathstrut 16}\]'
                '\[x=4\]')
示例#3
0
def test_eq32_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 1, 1)), SquareRoot(Item(16))))
    assert eq.auto_resolution(dont_display_equations_name=True,
                              decimal_result=2) == \
        wrap_nb('\[x=\\sqrt{\mathstrut 16}\]'
                '\[x=4\]')
def test_eq15_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(1), Item(2)), number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[1=2\]'
                                           'This equation has no solution.'
                                           '\\newline ')
def test_eq27_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 3, 1)), Item(1)), number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[3x=1\]'
                '\[x=\\frac{1}{3}\]'
                '\[x\\simeq0.33\]')
def test_eq28_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 8, 1)), Item(6)), number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[8x=6\]'
                '\[x=\\frac{6}{8}\]'
                '\[x=0.75\]')
示例#7
0
def test_eq27_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 3, 1)), Item(1)), number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[3x=1\]'
                '\[x=\\frac{1}{3}\]'
                '\[x\\simeq0.33\]')
示例#8
0
def test_eq28_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 8, 1)), Item(6)), number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[8x=6\]'
                '\[x=\\frac{6}{8}\]'
                '\[x=0.75\]')
示例#9
0
def test_eq5_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 12, 1)), Item(8)), number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[12x=8\]'
                                           '\[x=\\frac{8}{12}\]'
                                           '\[x=\\frac{\\bcancel{4}\\times 2}'
                                           '{\\bcancel{4}\\times 3}\]'
                                           '\[x=\\frac{2}{3}\]')
def test_eq5_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 12, 1)), Item(8)), number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[12x=8\]'
                                           '\[x=\\frac{8}{12}\]'
                                           '\[x=\\frac{\\bcancel{4}\\times 2}'
                                           '{\\bcancel{4}\\times 3}\]'
                                           '\[x=\\frac{2}{3}\]')
示例#11
0
def test_eq0_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 1, 1)), Monomial(('+', 7, 0))]), Item(3)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[x+7=3\]'
                                           '\[x=3-7\]'
                                           '\[x=-4\]')
示例#12
0
def test_eq1_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('-', 8, 0)), Monomial(('+', 1, 1))]), Item(-2)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-8+x=-2\]'
                                           '\[x=-2+8\]'
                                           '\[x=6\]')
def test_eq0_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 1, 1)), Monomial(('+', 7, 0))]),
                   Item(3)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[x+7=3\]'
                                           '\[x=3-7\]'
                                           '\[x=-4\]')
def test_eq2_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(-5),
                   Polynomial([Monomial(('+', 1, 1)), Monomial(('+', 3, 0))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-5=x+3\]'
                                           '\[x=-5-3\]'
                                           '\[x=-8\]')
def test_eq1_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('-', 8, 0)),
                               Monomial(('+', 1, 1))]),
                   Item(-2)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-8+x=-2\]'
                                           '\[x=-2+8\]'
                                           '\[x=6\]')
def test_eq6_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 2, 1)), Monomial(('+', 3, 0))]),
                   Item(8)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[2x+3=8\]'
                                           '\[2x=8-3\]'
                                           '\[2x=5\]'
                                           '\[x=\\frac{5}{2}\]')
示例#17
0
def test_eq6_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 2, 1)), Monomial(('+', 3, 0))]), Item(8)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[2x+3=8\]'
                                           '\[2x=8-3\]'
                                           '\[2x=5\]'
                                           '\[x=\\frac{5}{2}\]')
示例#18
0
def test_eq7_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 19, 0)), Monomial(('+', 3, 1))]), Monomial(('+', 2, 1))),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[19+3x=2x\]'
                                           '\[3x-2x=-19\]'
                                           '\[(3-2)x=-19\]'
                                           '\[x=-19\]')
def test_eq12_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 2, 1)), Monomial(('+', 1, 0))]),
                   Item(1)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[2x+1=1\]'
                                           '\[2x=1-1\]'
                                           '\[2x=0\]'
                                           '\[x=0\]')
def test_eq25_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(('+', 5, 2)),
                   Sum([Item(('+', 4, 2)), Monomial(('+', 1, 1))])),
                  number=1)
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[5^{2}=4^{2}+x\]'
                '\[25=16+x\]'
                '\[x=25-16\]'
                '\[x=9\]')
示例#21
0
def test_eq12_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 2, 1)), Monomial(('+', 1, 0))]), Item(1)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[2x+1=1\]'
                                           '\[2x=1-1\]'
                                           '\[2x=0\]'
                                           '\[x=0\]')
def test_eq7_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 19, 0)), Monomial(('+', 3, 1))]),
                   Monomial(('+', 2, 1))),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[19+3x=2x\]'
                                           '\[3x-2x=-19\]'
                                           '\[(3-2)x=-19\]'
                                           '\[x=-19\]')
示例#23
0
def test_eq2_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Item(-5), Polynomial([Monomial(
            ('+', 1, 1)), Monomial(('+', 3, 0))])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-5=x+3\]'
                                           '\[x=-5-3\]'
                                           '\[x=-8\]')
示例#24
0
def test_eq25_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(
        ('+', 5, 2)), Sum([Item(
            ('+', 4, 2)), Monomial(('+', 1, 1))])),
                  number=1)
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[5^{2}=4^{2}+x\]'
                '\[25=16+x\]'
                '\[x=25-16\]'
                '\[x=9\]')
def test_eq8_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 4, 1)), Monomial(('+', 2, 0))]),
                   Polynomial([Monomial(('-', 3, 0)), Monomial(('+', 2, 1))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[4x+2=-3+2x\]'
                                           '\[4x-2x=-3-2\]'
                                           '\[(4-2)x=-5\]'
                                           '\[2x=-5\]'
                                           '\[x=-\\frac{5}{2}\]')
示例#26
0
def test_eq14_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial(('+', 3, 0)),
                        Monomial(('+', 10, 1))]), Monomial(('+', 10, 1))))
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}): $'
                                           '\[3+10x=10x\]'
                                           '\[10x-10x=-3\]'
                                           '\[(10-10)x=-3\]'
                                           '\[0x=-3\]'
                                           '\[0=-3\]'
                                           'This equation has no solution.'
                                           '\\newline ')
def test_eq37_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial((Fraction((Item(2), Item(3))), 1)),
                   Fraction((Item(4), Item(5)))))
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[\\frac{2}{3}x=\\frac{4}{5}\]'
                '\[x=\\frac{4}{5}\div \\frac{2}{3}\]'
                '\[x=\\frac{4}{5}\\times \\frac{3}{2}\]'
                '\[x=\\frac{4\\times 3}{5\\times 2}\]'
                '\[x=\\frac{\\bcancel{2}\\times 2\\times 3}'
                '{5\\times \\bcancel{2}}\]'
                '\[x=\\frac{6}{5}\]')
def test_eq11_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 5, 0)), Monomial(('-', 1, 1))]),
                   Polynomial([Monomial(('+', 5, 1))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5-x=5x\]'
                                           '\[-x-5x=-5\]'
                                           '\[(-1-5)x=-5\]'
                                           '\[-6x=-5\]'
                                           '\[x=\\frac{-5}{-6}\]'
                                           '\[x=\\frac{5}{6}\]')
def test_eq9_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('-', 2, 1)), Monomial(('+', 5, 0))]),
                   Polynomial([Monomial(('+', 3, 1)), Monomial(('-', 4, 0))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-2x+5=3x-4\]'
                                           '\[-2x-3x=-4-5\]'
                                           '\[(-2-3)x=-9\]'
                                           '\[-5x=-9\]'
                                           '\[x=\\frac{-9}{-5}\]'
                                           '\[x=\\frac{9}{5}\]')
示例#30
0
def test_eq21_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial(('-', 1, 0)),
                        Monomial(('-', 4, 1))]), Monomial(('-', 9, 0))))
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}): $'
                                           '\[-1-4x=-9\]'
                                           '\[-4x=-9+1\]'
                                           '\[-4x=-8\]'
                                           '\[x=\\frac{-8}{-4}\]'
                                           '\[x=\\frac{+\\bcancel{4}\\times 2}'
                                           '{+\\bcancel{4}}\]'
                                           '\[x=2\]')
示例#31
0
def test_eq37_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial((Fraction(
        (Item(2), Item(3))), 1)), Fraction((Item(4), Item(5)))))
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[\\frac{2}{3}x=\\frac{4}{5}\]'
                '\[x=\\frac{4}{5}\div \\frac{2}{3}\]'
                '\[x=\\frac{4}{5}\\times \\frac{3}{2}\]'
                '\[x=\\frac{4\\times 3}{5\\times 2}\]'
                '\[x=\\frac{\\bcancel{2}\\times 2\\times 3}'
                '{5\\times \\bcancel{2}}\]'
                '\[x=\\frac{6}{5}\]')
def test_eq14_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial(('+', 3, 0)), Monomial(('+', 10, 1))]),
                   Monomial(('+', 10, 1))))
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}): $'
                                           '\[3+10x=10x\]'
                                           '\[10x-10x=-3\]'
                                           '\[(10-10)x=-3\]'
                                           '\[0x=-3\]'
                                           '\[0=-3\]'
                                           'This equation has no solution.'
                                           '\\newline ')
def test_eq21_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial(('-', 1, 0)),
                        Monomial(('-', 4, 1))]),
                   Monomial(('-', 9, 0))))
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}): $'
                                           '\[-1-4x=-9\]'
                                           '\[-4x=-9+1\]'
                                           '\[-4x=-8\]'
                                           '\[x=\\frac{-8}{-4}\]'
                                           '\[x=\\frac{+\\bcancel{4}\\times 2}'
                                           '{+\\bcancel{4}}\]'
                                           '\[x=2\]')
def test_eq23_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(5), Sum([Expandable((Item(1),
                                             Sum([Monomial(('+', 1, 1)),
                                                  Monomial(('-', 2, 0))]))),
                                 Item(7)])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5=(x-2)+7\]'
                                           '\[5=x-2+7\]'
                                           '\[5=x+5\]'
                                           '\[x=5-5\]'
                                           '\[x=0\]')
示例#35
0
def test_eq11_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(
        ('+', 5, 0)), Monomial(
            ('-', 1, 1))]), Polynomial([Monomial(('+', 5, 1))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5-x=5x\]'
                                           '\[-x-5x=-5\]'
                                           '\[(-1-5)x=-5\]'
                                           '\[-6x=-5\]'
                                           '\[x=\\frac{-5}{-6}\]'
                                           '\[x=\\frac{5}{6}\]')
def test_eq13_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 1, 1)), Monomial(('+', 5, 0))]),
                   Polynomial([Monomial(('+', 1, 1)), Monomial(('+', 2, 0))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[x+5=x+2\]'
                                           '\[x-x=2-5\]'
                                           '\[(1-1)x=-3\]'
                                           '\[0x=-3\]'
                                           '\[0=-3\]'
                                           'This equation has no solution.'
                                           '\\newline ')
示例#37
0
class Q_Equation(Q_Structure):

    # --------------------------------------------------------------------------
    ##
    #   @brief Constructor.
    #   @param **options Any options
    #   @return One instance of question.Q_Equation
    def __init__(self, q_kind='default_nothing', **options):
        self.derived = True

        # The call to the mother class __init__() method will set the
        # fields matching optional arguments which are so far:
        # self.q_kind, self.q_subkind
        # plus self.options (modified)
        Q_Structure.__init__(self,
                             q_kind, AVAILABLE_Q_KIND_VALUES,
                             **options)
        # The purpose of this next line is to get the possibly modified
        # value of **options
        options = self.options

        # That's the number of the question, not of the expressions it might
        # contain !
        self.number = ""
        # if 'number_of_questions' in options:
        #    self.number = options['number_of_questions']

        self.equation = Equation((RANDOMLY, q_kind))

        if 'expression_number' in options:
            self.equation.set_number(options['expression_number'])

    # --------------------------------------------------------------------------
    ##
    #   @brief Returns the text of the question as a str
    def text_to_str(self):
        M = shared.machine

        result = M.write_math_style2(M.type_string(self.equation,
                                                   display_name='OK'))
        result += M.write_new_line()

        return result

    # --------------------------------------------------------------------------
    ##
    #   @brief Returns the answer of the question as a str
    def answer_to_str(self):
        M = shared.machine

        return M.write(self.equation.auto_resolution())
示例#38
0
def test_eq8_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Polynomial([Monomial(
            ('+', 4, 1)), Monomial(('+', 2, 0))]),
         Polynomial([Monomial(
             ('-', 3, 0)), Monomial(('+', 2, 1))])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[4x+2=-3+2x\]'
                                           '\[4x-2x=-3-2\]'
                                           '\[(4-2)x=-5\]'
                                           '\[2x=-5\]'
                                           '\[x=-\\frac{5}{2}\]')
def test_eq29_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Monomial(('+', 1, 1)), Sum([Fraction((Item(1), Item(4))),
                                               Fraction((Item(1), Item(8)))])),
                  number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[x=\\frac{1}{4}+\\frac{1}{8}\]'
                '\[x=\\frac{1\\times 2}{4\\times 2}'
                '+\\frac{1}{8}\]'
                '\[x=\\frac{2}{8}+\\frac{1}{8}\]'
                '\[x=\\frac{2+1}{8}\]'
                '\[x=\\frac{3}{8}\]'
                '\[x\\simeq0.38\]')
示例#40
0
def test_eq39_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([
        Monomial((Fraction((Item(2), Item(1))).simplified(), 1)),
        Fraction((Item(1), Item(5)))
    ]), Fraction(('-', Item(4), Item(5)))))
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[2x+\\frac{1}{5}=-\\frac{4}{5}\]'
                '\[2x=-\\frac{4}{5}-\\frac{1}{5}\]'
                '\[2x=\\frac{-4-1}{5}\]'
                '\[2x=-\\frac{5}{5}\]'
                '\[2x=-\\frac{\\bcancel{5}}{\\bcancel{5}}\]'
                '\[2x=-1\]'
                '\[x=-\\frac{1}{2}\]')
def test_eq39_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial((Fraction((Item(2),
                                            Item(1))).simplified(), 1)),
                        Fraction((Item(1), Item(5)))]),
                   Fraction(('-', Item(4), Item(5)))))
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[2x+\\frac{1}{5}=-\\frac{4}{5}\]'
                '\[2x=-\\frac{4}{5}-\\frac{1}{5}\]'
                '\[2x=\\frac{-4-1}{5}\]'
                '\[2x=-\\frac{5}{5}\]'
                '\[2x=-\\frac{\\bcancel{5}}{\\bcancel{5}}\]'
                '\[2x=-1\]'
                '\[x=-\\frac{1}{2}\]')
示例#42
0
class Q_Equation(Q_Structure):

    # --------------------------------------------------------------------------
    ##
    #   @brief Constructor.
    #   @param **options Any options
    #   @return One instance of question.Q_Equation
    def __init__(self, q_kind='default_nothing', **options):
        self.derived = True

        # The call to the mother class __init__() method will set the
        # fields matching optional arguments which are so far:
        # self.q_kind, self.q_subkind
        # plus self.options (modified)
        Q_Structure.__init__(self, q_kind, AVAILABLE_Q_KIND_VALUES, **options)
        # The purpose of this next line is to get the possibly modified
        # value of **options
        options = self.options

        # That's the number of the question, not of the expressions it might
        # contain !
        self.number = ""
        # if 'number_of_questions' in options:
        #    self.number = options['number_of_questions']

        self.equation = Equation((RANDOMLY, q_kind))

        if 'expression_number' in options:
            self.equation.set_number(options['expression_number'])

    # --------------------------------------------------------------------------
    ##
    #   @brief Returns the text of the question as a str
    def text_to_str(self):
        M = shared.machine

        result = M.write_math_style2(
            M.type_string(self.equation, display_name='OK'))
        result += M.write_new_line()

        return result

    # --------------------------------------------------------------------------
    ##
    #   @brief Returns the answer of the question as a str
    def answer_to_str(self):
        M = shared.machine

        return M.write(self.equation.auto_resolution())
示例#43
0
def test_eq9_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Polynomial([Monomial(
            ('-', 2, 1)), Monomial(('+', 5, 0))]),
         Polynomial([Monomial(
             ('+', 3, 1)), Monomial(('-', 4, 0))])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-2x+5=3x-4\]'
                                           '\[-2x-3x=-4-5\]'
                                           '\[(-2-3)x=-9\]'
                                           '\[-5x=-9\]'
                                           '\[x=\\frac{-9}{-5}\]'
                                           '\[x=\\frac{9}{5}\]')
def test_eq10_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Polynomial([Monomial(('+', 5, 0)), Monomial(('+', 4, 1))]),
                   Polynomial([Monomial(('-', 20, 1)),
                               Monomial(('+', 3, 0))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5+4x=-20x+3\]'
                                           '\[4x+20x=3-5\]'
                                           '\[(4+20)x=-2\]'
                                           '\[24x=-2\]'
                                           '\[x=-\\frac{2}{24}\]'
                                           '\[x=-\\frac{\\bcancel{2}}'
                                           '{\\bcancel{2}\\times 12}\]'
                                           '\[x=-\\frac{1}{12}\]')
def test_t4_pyth_eq_autoresolution(t4):
    """
    Check the auto-resolution of the pythagorean equation created from t4.
    """
    eq_t4 = Equation(t4.pythagorean_substequality().substitute())
    assert eq_t4.auto_resolution(dont_display_equations_name=True,
                                 decimal_result=HUNDREDTH,
                                 pythagorean_mode=True,
                                 unit='cm') == \
        wrap_nb('\[\\text{OP}^{2}=7^{2}-1.5^{2}\]'
                '\[\\text{OP}^{2}=49-2.25\]'
                '\[\\text{OP}^{2}=46.75\]'
                '\[\\text{OP}=\\sqrt{\mathstrut 46.75}'
                '\\text{ because \\text{OP} is positive.}\]'
                '\[\\text{OP}\\simeq6.84\\text{ cm}\]')
def test_eq36_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(('+', "EF", 2)),
                   Sum([Item(('+', 60, 2)), Item(('+', 91, 2))])),
                  number=1, variable_letter_name="AB")
    assert eq.auto_resolution(dont_display_equations_name=True,
                              pythagorean_mode=True,
                              unit='cm') == \
        wrap_nb('\[\\text{EF}^{2}=60^{2}+91^{2}\]'
                '\[\\text{EF}^{2}=3600+8281\]'
                '\[\\text{EF}^{2}=11881\]'
                '\[\\text{EF}='
                '\\sqrt{\mathstrut 11881}'
                '\\text{ because \\text{EF} '
                'is positive.}\]'
                '\[\\text{EF}=109\\text{ cm}\]')
def test_eq20_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial(('+', 5, 1))]),
                   Sum([Expandable((Item(1), Sum([Monomial(('+', 2, 0)),
                                                  Monomial(('-', 5, 1))]))),
                        Monomial(('-', 2, 0))])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5x=(2-5x)-2\]'
                                           '\[5x=2-5x-2\]'
                                           '\[5x=2-2-5x\]'
                                           '\[5x=-5x\]'
                                           '\[5x+5x=0\]'
                                           '\[(5+5)x=0\]'
                                           '\[10x=0\]'
                                           '\[x=0\]')
示例#48
0
def test_eq13_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Polynomial([Monomial(
            ('+', 1, 1)), Monomial(('+', 5, 0))]),
         Polynomial([Monomial(
             ('+', 1, 1)), Monomial(('+', 2, 0))])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[x+5=x+2\]'
                                           '\[x-x=2-5\]'
                                           '\[(1-1)x=-3\]'
                                           '\[0x=-3\]'
                                           '\[0=-3\]'
                                           'This equation has no solution.'
                                           '\\newline ')
示例#49
0
def test_eq29_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Monomial(('+', 1, 1)),
         Sum([Fraction((Item(1), Item(4))),
              Fraction((Item(1), Item(8)))])),
        number=1)
    assert eq.auto_resolution(decimal_result=2) == \
        wrap_nb('$(\\text{E}_{1}): $'
                '\[x=\\frac{1}{4}+\\frac{1}{8}\]'
                '\[x=\\frac{1\\times 2}{4\\times 2}'
                '+\\frac{1}{8}\]'
                '\[x=\\frac{2}{8}+\\frac{1}{8}\]'
                '\[x=\\frac{2+1}{8}\]'
                '\[x=\\frac{3}{8}\]'
                '\[x\\simeq0.38\]')
示例#50
0
def test_eq10_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Polynomial([Monomial(
            ('+', 5, 0)), Monomial(('+', 4, 1))]),
         Polynomial([Monomial(
             ('-', 20, 1)), Monomial(('+', 3, 0))])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5+4x=-20x+3\]'
                                           '\[4x+20x=3-5\]'
                                           '\[(4+20)x=-2\]'
                                           '\[24x=-2\]'
                                           '\[x=-\\frac{2}{24}\]'
                                           '\[x=-\\frac{\\bcancel{2}}'
                                           '{\\bcancel{2}\\times 12}\]'
                                           '\[x=-\\frac{1}{12}\]')
def test_eq17_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Expandable((Item(-1),
                               Sum([Monomial((-11, 1)), Item(-10)]))),
                   Sum([Expandable((Item(1),
                                    Sum([Item(-15), Monomial((12, 1))]))),
                        Item(-1)])),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-(-11x-10)=(-15+12x)-1\]'
                                           '\[11x+10=-15+12x-1\]'
                                           '\[11x+10=-15-1+12x\]'
                                           '\[11x+10=-16+12x\]'
                                           '\[11x-12x=-16-10\]'
                                           '\[(11-12)x=-26\]'
                                           '\[-x=-26\]'
                                           '\[x=26\]')
def test_eq35_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(('+', 73, 2)),
                   Sum([Item(('+', 48, 2)), Item(('+', "AB", 2))])),
                  number=1, variable_letter_name="AB")
    assert eq.auto_resolution(dont_display_equations_name=True,
                              decimal_result=2,
                              pythagorean_mode=True) == \
        wrap_nb('\[73^{2}=48^{2}+\\text{AB}^{2}\]'
                '\[5329=2304+\\text{AB}^{2}\]'
                '\[\\text{AB}^{2}=5329-2304\]'
                '\[\\text{AB}^{2}=3025\]'
                '\[\\text{AB}='
                '\\sqrt{\mathstrut 3025}'
                '\\text{ because \\text{AB} '
                'is positive.}\]'
                '\[\\text{AB}=55\]')
示例#53
0
def test_eq23_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Item(5),
         Sum([
             Expandable(
                 (Item(1), Sum([Monomial(('+', 1, 1)),
                                Monomial(('-', 2, 0))]))),
             Item(7)
         ])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5=(x-2)+7\]'
                                           '\[5=x-2+7\]'
                                           '\[5=x+5\]'
                                           '\[x=5-5\]'
                                           '\[x=0\]')
def test_eq16_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([Monomial(('+', 9, 1)),
                        Expandable((Monomial(('+', 9, 0)),
                                    Sum([Monomial(('-', 4, 0)),
                                         Monomial(('-', 1, 1))])))]),
                   Item(8)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[9x+9(-4-x)=8\]'
                                           '\[9x+9\\times (-4)+9\\times '
                                           '(-x)=8\]'
                                           '\[9x-36-9x=8\]'
                                           '\[(9-9)x-36=8\]'
                                           '\[0x-36=8\]'
                                           '\[-36=8\]'
                                           'This equation has no solution.'
                                           '\\newline ')
示例#55
0
def test_eq36_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(
        ('+', "EF", 2)), Sum([Item(
            ('+', 60, 2)), Item(('+', 91, 2))])),
                  number=1,
                  variable_letter_name="AB")
    assert eq.auto_resolution(dont_display_equations_name=True,
                              pythagorean_mode=True,
                              unit='cm') == \
        wrap_nb('\[\\text{EF}^{2}=60^{2}+91^{2}\]'
                '\[\\text{EF}^{2}=3600+8281\]'
                '\[\\text{EF}^{2}=11881\]'
                '\[\\text{EF}='
                '\\sqrt{\mathstrut 11881}'
                '\\text{ because \\text{EF} '
                'is positive.}\]'
                '\[\\text{EF}=109\\text{ cm}\]')
示例#56
0
def test_eq35_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Item(
        ('+', 73, 2)), Sum([Item(
            ('+', 48, 2)), Item(('+', "AB", 2))])),
                  number=1,
                  variable_letter_name="AB")
    assert eq.auto_resolution(dont_display_equations_name=True,
                              decimal_result=2,
                              pythagorean_mode=True) == \
        wrap_nb('\[73^{2}=48^{2}+\\text{AB}^{2}\]'
                '\[5329=2304+\\text{AB}^{2}\]'
                '\[\\text{AB}^{2}=5329-2304\]'
                '\[\\text{AB}^{2}=3025\]'
                '\[\\text{AB}='
                '\\sqrt{\mathstrut 3025}'
                '\\text{ because \\text{AB} '
                'is positive.}\]'
                '\[\\text{AB}=55\]')
示例#57
0
def test_eq16_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([
        Monomial(('+', 9, 1)),
        Expandable((Monomial(
            ('+', 9, 0)), Sum([Monomial(
                ('-', 4, 0)), Monomial(('-', 1, 1))])))
    ]), Item(8)),
                  number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[9x+9(-4-x)=8\]'
                                           '\[9x+9\\times (-4)+9\\times '
                                           '(-x)=8\]'
                                           '\[9x-36-9x=8\]'
                                           '\[(9-9)x-36=8\]'
                                           '\[0x-36=8\]'
                                           '\[-36=8\]'
                                           'This equation has no solution.'
                                           '\\newline ')
示例#58
0
def test_eq17_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Expandable((Item(-1), Sum([Monomial(
            (-11, 1)), Item(-10)]))),
         Sum([
             Expandable((Item(1), Sum([Item(-15), Monomial((12, 1))]))),
             Item(-1)
         ])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[-(-11x-10)=(-15+12x)-1\]'
                                           '\[11x+10=-15+12x-1\]'
                                           '\[11x+10=-15-1+12x\]'
                                           '\[11x+10=-16+12x\]'
                                           '\[11x-12x=-16-10\]'
                                           '\[(11-12)x=-26\]'
                                           '\[-x=-26\]'
                                           '\[x=26\]')
示例#59
0
def test_eq38_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation((Sum([
        Monomial((Fraction((Item(1), Item(4))), 1)),
        Fraction((Item(1), Item(7)))
    ]), Fraction(('-', Item(3), Item(14)))))
    assert eq.auto_resolution(dont_display_equations_name=True) == \
        wrap_nb('\[\\frac{1}{4}x+\\frac{1}{7}=-\\frac{3}{14}\]'
                '\[\\frac{1}{4}x=-\\frac{3}{14}-\\frac{1}{7}\]'
                '\[\\frac{1}{4}x=-\\frac{3}{14}-\\frac{1\\times 2}'
                '{7\\times 2}\]'
                '\[\\frac{1}{4}x=-\\frac{3}{14}-\\frac{2}{14}\]'
                '\[\\frac{1}{4}x=\\frac{-3-2}{14}\]'
                '\[\\frac{1}{4}x=-\\frac{5}{14}\]'
                '\[x=-\\frac{5}{14}\div \\frac{1}{4}\]'
                '\[x=-\\frac{5}{14}\\times \\frac{4}{1}\]'
                '\[x=-\\frac{5\\times 4}{14\\times 1}\]'
                '\[x=-\\frac{5\\times \\bcancel{2}\\times 2}'
                '{\\bcancel{2}\\times 7}\]'
                '\[x=-\\frac{10}{7}\]')
示例#60
0
def test_eq20_autoresolution():
    """Is this Equation correctly auto-resolved?"""
    eq = Equation(
        (Sum([Monomial(('+', 5, 1))]),
         Sum([
             Expandable(
                 (Item(1), Sum([Monomial(('+', 2, 0)),
                                Monomial(('-', 5, 1))]))),
             Monomial(('-', 2, 0))
         ])),
        number=1)
    assert eq.auto_resolution() == wrap_nb('$(\\text{E}_{1}): $'
                                           '\[5x=(2-5x)-2\]'
                                           '\[5x=2-5x-2\]'
                                           '\[5x=2-2-5x\]'
                                           '\[5x=-5x\]'
                                           '\[5x+5x=0\]'
                                           '\[(5+5)x=0\]'
                                           '\[10x=0\]'
                                           '\[x=0\]')