Skip to content

Commit

Permalink
tests for bidirectional rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Marketa Opichalova committed Feb 27, 2024
1 parent 52f30b5 commit a954518
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Testing/objects_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
side_parser = Parser("side")
rate_complex_parser = Parser("rate_complex")
rule_parser = Parser("rule")
rules_parser = Parser("rules")
model_parser = Parser("model")

# atomic
Expand Down Expand Up @@ -246,13 +247,27 @@
r3 = Rule(sequence_3, mid_3, compartments_3, complexes_3, pairs_3, rate_3)

sequence_4 = (s34, s35, s36, s37)
reversed_sequence_4 = (s36, s37, s34, s35)
mid_4 = 2
compartments_4 = ["cyt"] * 4
complexes_4 = [(0, 1), (2, 2), (3, 3)]
reversed_complexes_4 = [(0, 0), (1, 1), (2, 3)]
pairs_4 = [(0, 2), (1, 3)]
rate_4 = Rate("3.0*[K()::cyt]/2.0*v_1")
reversed_rate4 = Rate("2.0*[K()::cyt]/3.0*v_1")

r4 = Rule(sequence_4, mid_4, compartments_4, complexes_4, pairs_4, rate_4)
reversed_r4a = Rule(
reversed_sequence_4, mid_4, compartments_4, reversed_complexes_4, pairs_4, rate_4
)
reversed_r4b = Rule(
reversed_sequence_4,
mid_4,
compartments_4,
reversed_complexes_4,
pairs_4,
reversed_rate4,
)

sequence_5 = (s34, s35, s36, s37, s38)
mid_5 = 2
Expand All @@ -272,6 +287,9 @@

r6 = Rule(sequence_6, mid_6, compartments_6, complexes_6, pairs_6, rate_6)
rule_no_rate = Rule(sequence_4, mid_4, compartments_4, complexes_4, pairs_4, None)
reversed_no_rate = Rule(
reversed_sequence_4, mid_4, compartments_4, reversed_complexes_4, pairs_4, None
)

sequence_c1 = (s34, s35, s36, s37, s2)
mid_c1 = 2
Expand Down
25 changes: 22 additions & 3 deletions Testing/parsing/test_rule.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest

from eBCSgen.Core.Rule import Rule
from eBCSgen.Core.Rate import Rate

import Testing.objects_testing as objects


def test_parser():
rule_expr = "K(S{u}).B()::cyt => K(S{p})::cyt + B()::cyt + D(B{_})::cell @ 3*[K()::cyt]/2*v_1"
assert objects.rule_parser.parse(rule_expr).data[1] == objects.r5
Expand All @@ -20,3 +18,24 @@ def test_parser():

rule_expr = "K(S{u}).B()::cyt => K(S{p})::cyt + B()::cyt"
assert objects.rule_parser.parse(rule_expr).data[1] == objects.rule_no_rate


def test_bidirectional():
rule_expr = "#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt"
parsed = objects.rules_parser.parse(rule_expr)
assert objects.rule_no_rate in parsed.data["rules"]
assert objects.reversed_no_rate in parsed.data["rules"]

rule_expr = (
"#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1"
)
parsed = objects.rules_parser.parse(rule_expr)
assert objects.r4 in parsed.data["rules"]
assert objects.reversed_r4a in parsed.data["rules"]

rule_expr = (
"#! rules\nK(S{u}).B()::cyt <=> K(S{p})::cyt + B()::cyt @ 3*[K()::cyt]/2*v_1 | 2*[K()::cyt]/3*v_1"
)
parsed = objects.rules_parser.parse(rule_expr)
assert objects.r4 in parsed.data["rules"]
assert objects.reversed_r4b in parsed.data["rules"]

0 comments on commit a954518

Please sign in to comment.