1313"""Test pddl.logic.terms module."""
1414import pytest
1515
16- from pddl .logic .terms import Variable
16+ from pddl .logic .terms import Constant , Variable
1717
1818
1919def test_no_duplicated_type_tags () -> None :
@@ -22,3 +22,47 @@ def test_no_duplicated_type_tags() -> None:
2222 ValueError , match = r"duplicate element in collection \['b', 'b'\]: 'b'"
2323 ):
2424 Variable ("a" , ["b" , "b" ])
25+
26+
27+ def test_variable_ordering () -> None :
28+ """Test variable ordering."""
29+ v1 = Variable ("x" , ["type1" ])
30+ v2 = Variable ("y" , ["type3" ])
31+ v3 = Variable ("z" , ["type2" ])
32+ assert v1 < v2
33+ assert v1 < v3
34+ assert v2 < v3
35+ assert not (v1 > v2 )
36+ assert not (v1 > v3 )
37+ assert not (v2 > v3 )
38+
39+
40+ def test_constant_ordering () -> None :
41+ """Test constant ordering."""
42+ c1 = Constant ("a" , "type1" )
43+ c2 = Constant ("b" , "type2" )
44+ c3 = Constant ("c" , "type1" )
45+ assert c1 < c2
46+ assert c1 < c3
47+ assert c2 < c3
48+ assert not (c1 > c2 )
49+ assert not (c1 > c3 )
50+ assert not (c2 > c3 )
51+
52+
53+ def test_term_ordering () -> None :
54+ """Test term ordering between variables and constants."""
55+ v1 = Variable ("x" , ["type1" ])
56+ v2 = Variable ("y" , ["type3" ])
57+ v3 = Variable ("z" , ["type2" ])
58+ c1 = Constant ("a" , "type1" )
59+ c2 = Constant ("b" , "type2" )
60+ c3 = Constant ("c" , "type1" )
61+ assert c1 < v1
62+ assert c2 < v2
63+ assert c3 < v3
64+ assert not (v1 < c1 )
65+ assert not (v2 < c2 )
66+ assert not (v3 < c3 )
67+ array = [c1 , c2 , c3 , v1 , v2 , v3 ]
68+ assert array == sorted (array )
0 commit comments