Ejemplo n.º 1
0
    def test_add_expression_variable(self):
        a = Expression(Variable('o', 10), 20, 2)
        v = Variable('v', 20)

        # should work just like add_variable
        a.add_expression(v, 2)
        self.assertEqual(len(a.terms), 2)
        self.assertEqual(a.terms.get(v), 2)
Ejemplo n.º 2
0
    def test_add_expression_variable(self):
        a = Expression(Variable('o', 10), 20, 2)
        v = Variable('v', 20)

        # should work just like add_variable
        a.add_expression(v, 2)
        self.assertEqual(len(a.terms), 2)
        self.assertEqual(a.terms.get(v), 2)
Ejemplo n.º 3
0
    def test_add_expression(self):
        va = Variable('a', 10)
        vb = Variable('b', 20)
        vc = Variable('c', 5)
        a = Expression(va, 20, 2)

        # different variable and implicit coefficient of 1, should make new term
        a.add_expression(Expression(vb, 10, 5))
        self.assertEqual(len(a.terms), 2)
        self.assertEqual(a.constant, 7)
        self.assertEqual(a.terms.get(vb), 10)

        # same variable, should reuse existing term
        a.add_expression(Expression(vb, 2, 5))
        self.assertEqual(len(a.terms), 2)
        self.assertEqual(a.constant, 12)
        self.assertEqual(a.terms.get(vb), 12)

        # another variable and a coefficient,
        # should multiply the constant and all terms in the new expression
        a.add_expression(Expression(vc, 1, 2), 2)
        self.assertEqual(len(a.terms), 3)
        self.assertEqual(a.constant, 16)
        self.assertEqual(a.terms.get(vc), 2)
Ejemplo n.º 4
0
    def test_add_expression(self):
        va = Variable('a', 10)
        vb = Variable('b', 20)
        vc = Variable('c', 5)
        a = Expression(va, 20, 2)

        # different variable and implicit coefficient of 1, should make new term
        a.add_expression(Expression(vb, 10, 5))
        self.assertEqual(len(a.terms), 2)
        self.assertEqual(a.constant, 7)
        self.assertEqual(a.terms.get(vb), 10)

        # same variable, should reuse existing term
        a.add_expression(Expression(vb, 2, 5))
        self.assertEqual(len(a.terms), 2)
        self.assertEqual(a.constant, 12)
        self.assertEqual(a.terms.get(vb), 12)

        # another variable and a coefficient,
        # should multiply the constant and all terms in the new expression
        a.add_expression(Expression(vc, 1, 2), 2)
        self.assertEqual(len(a.terms), 3)
        self.assertEqual(a.constant, 16)
        self.assertEqual(a.terms.get(vc), 2)
Ejemplo n.º 5
0
 def test_variable_expression(self):
     "Variable expressions can be constructed"
     x = Variable('x', 167)
     y = Variable('y', 2)
     cly = Expression(y)
     cly.add_expression(x)
Ejemplo n.º 6
0
 def test_variable_expression(self):
     "Variable expressions can be constructed"
     x = Variable('x', 167)
     y = Variable('y', 2)
     cly = Expression(y)
     cly.add_expression(x)