Skip to content

Commit

Permalink
Clear associative and commutative Relations before each test
Browse files Browse the repository at this point in the history
  • Loading branch information
LALAYANG authored and brandonwillard committed Nov 17, 2021
1 parent 1f846de commit b4580aa
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions tests/test_assoccomm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Sequence
from copy import copy

import pytest
from cons import cons
Expand All @@ -21,6 +22,21 @@
from kanren.term import arguments, operator, term


@pytest.fixture(autouse=True)
def clear_assoccomm():
old_commutative_index = copy(commutative.index)
old_commutative_facts = copy(commutative.facts)
old_associative_index = copy(associative.index)
old_associative_facts = copy(associative.facts)
try:
yield
finally:
commutative.index = old_commutative_index
commutative.facts = old_commutative_facts
associative.index = old_associative_index
associative.facts = old_associative_facts


class Node(object):
def __init__(self, op, args):
self.op = op
Expand Down Expand Up @@ -83,9 +99,6 @@ def results(g, s=None):
def test_eq_comm():
x, y, z = var(), var(), var()

commutative.facts.clear()
commutative.index.clear()

comm_op = "comm_op"

fact(commutative, comm_op)
Expand Down Expand Up @@ -326,9 +339,6 @@ def test_eq_assoc():

assoc_op = "assoc_op"

associative.index.clear()
associative.facts.clear()

fact(associative, assoc_op)

assert run(0, True, eq_assoc(1, 1)) == (True,)
Expand Down Expand Up @@ -449,9 +459,6 @@ def test_eq_assoccomm():

ac = "commassoc_op"

commutative.index.clear()
commutative.facts.clear()

fact(commutative, ac)
fact(associative, ac)

Expand Down Expand Up @@ -545,11 +552,6 @@ def test_assoccomm_algebra():
add = "add"
mul = "mul"

commutative.index.clear()
commutative.facts.clear()
associative.index.clear()
associative.facts.clear()

fact(commutative, add)
fact(associative, add)
fact(commutative, mul)
Expand All @@ -565,11 +567,6 @@ def test_assoccomm_algebra():

def test_assoccomm_objects():

commutative.index.clear()
commutative.facts.clear()
associative.index.clear()
associative.facts.clear()

fact(commutative, Add)
fact(associative, Add)

Expand Down

0 comments on commit b4580aa

Please sign in to comment.