Skip to content

Commit

Permalink
Added example of FactBase.asp_str(sorted=True)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveraja committed May 6, 2024
1 parent b7dc53d commit 87f0e0a
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions tests/test_orm_factbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,25 +589,16 @@ class Meta:
# Test the asp output string with the sorted flag
# --------------------------------------------------------------------------
def test_factbase_aspstr_sorted(self):
class A(Predicate):
class A(Predicate, name="bb"):
a = IntegerField

class Meta:
name = "bb"

class B(Predicate):
class B(Predicate, name="aa"):
a = IntegerField

class Meta:
name = "aa"

class C(Predicate):
class C(Predicate, name="aa"):
a = IntegerField
b = IntegerField

class Meta:
name = "aa"

def tostr(facts):
return ".\n".join([str(f) for f in facts])

Expand Down Expand Up @@ -713,6 +704,20 @@ class Meta:
self.assertIn(expected_sig_predC, result)
self.assertIn(expected_sig_predA, result)

# --------------------------------------------------------------------------
# Test the asp output string with sorting and incomparable terms
# --------------------------------------------------------------------------
def test_factbase_aspstr_sorted_incomparable(self):
class A(Predicate):
x = field(SimpleField)

fb = FactBase([A(1), A(2), A("b")])
q = fb.query(A).ordered()
self.assertTrue(list(q.all()) == [A(1), A(2), A("b")])
tmpstr1 = ".\n".join(f"{x}" for x in q.all()) + ".\n"
tmpstr2 = fb.asp_str(sorted=True)
self.assertTrue(tmpstr1 == tmpstr2)


# ------------------------------------------------------------------------------
# Test QueryAPI version 1 (called via FactBase.select() and FactBase.delete())
Expand Down

0 comments on commit 87f0e0a

Please sign in to comment.