Example #1
0
    def test_equivalence(self):
        """
        Two function calls are equivalent not only if they share the same class,
        but also if their arguments are equivalent.
        
        """
        class FooFunction(Function):
            required_arguments = ("abc", )
            optional_arguments = {"xyz": LeafNode("123")}

        class CommutativeFunction(Function):
            required_arguments = range(2)
            argument_types = BooleanType
            is_commutative = True

        func1 = FooFunction(LeafNode("whatever"))
        func2 = FooFunction(LeafNode("whatever"))
        func3 = PermissiveFunction(BranchNode("baz"))
        func4 = PermissiveFunction(LeafNode("foo"))
        func5 = FooFunction(LeafNode("something"))
        func6 = CommutativeFunction(BoolVar(), TrafficLightVar())
        func7 = CommutativeFunction(TrafficLightVar(), BoolVar())

        assert_node_equivalence(
            (func1, func2),
            (func3, ),
            (func4, ),
            (func5, ),
            (func6, func7),
        )
Example #2
0
 def test_equivalence(self):
     """
     Two function calls are equivalent not only if they share the same class,
     but also if their arguments are equivalent.
     
     """
     class FooFunction(Function):
         required_arguments = ("abc", )
         optional_arguments = {"xyz": LeafNode("123")}
     
     class CommutativeFunction(Function):
         required_arguments = range(2)
         argument_types = BooleanType
         is_commutative = True
     
     func1 = FooFunction(LeafNode("whatever"))
     func2 = FooFunction(LeafNode("whatever"))
     func3 = PermissiveFunction(BranchNode("baz"))
     func4 = PermissiveFunction(LeafNode("foo"))
     func5 = FooFunction(LeafNode("something"))
     func6 = CommutativeFunction(BoolVar(), TrafficLightVar())
     func7 = CommutativeFunction(TrafficLightVar(), BoolVar())
     
     assert_node_equivalence(
         (func1, func2),
         (func3, ),
         (func4, ),
         (func5, ),
         (func6, func7),
         )
Example #3
0
    def test_equivalence(self):
        """Two conjunctions are equivalent if they have the same operands."""
        op1 = And(BoolVar(), TrafficLightVar())
        op2 = And(TrafficLightVar(), BoolVar())
        op3 = And(DriversAwaitingGreenLightVar(), BoolVar())
        op4 = And(DriversAwaitingGreenLightVar(), BoolVar())
        op5 = Or(DriversAwaitingGreenLightVar(), BoolVar())

        assert_node_equivalence(
            (op1, op2),
            (op3, op4),
            (op5, ),
        )
Example #4
0
 def test_equivalence(self):
     """Two conjunctions are equivalent if they have the same operands."""
     op1 = And(BoolVar(), TrafficLightVar())
     op2 = And(TrafficLightVar(), BoolVar())
     op3 = And(DriversAwaitingGreenLightVar(), BoolVar())
     op4 = And(DriversAwaitingGreenLightVar(), BoolVar())
     op5 = Or(DriversAwaitingGreenLightVar(), BoolVar())
     
     assert_node_equivalence(
         (op1, op2),
         (op3, op4),
         (op5, ),
         )
Example #5
0
    def test_equivalence(self):
        """
        Two exclusive disjunctions are equivalent if they have the same
        operands.
        
        """
        op1 = Xor(BoolVar(), PedestriansCrossingRoad())
        op2 = Xor(PedestriansCrossingRoad(), BoolVar())
        op3 = Xor(DriversAwaitingGreenLightVar(), BoolVar())
        op4 = Xor(DriversAwaitingGreenLightVar(), BoolVar())
        op5 = Or(DriversAwaitingGreenLightVar(), BoolVar())

        assert_node_equivalence(
            (op1, op2),
            (op3, op4),
            (op5, ),
        )
Example #6
0
 def test_equivalence(self):
     """
     Two exclusive disjunctions are equivalent if they have the same
     operands.
     
     """
     op1 = Xor(BoolVar(), PedestriansCrossingRoad())
     op2 = Xor(PedestriansCrossingRoad(), BoolVar())
     op3 = Xor(DriversAwaitingGreenLightVar(), BoolVar())
     op4 = Xor(DriversAwaitingGreenLightVar(), BoolVar())
     op5 = Or(DriversAwaitingGreenLightVar(), BoolVar())
     
     assert_node_equivalence(
         (op1, op2),
         (op3, op4),
         (op5, ),
         )