Skip to content

Commit

Permalink
eval: cast left-hand operand to a set if the right-hand operand is a set
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tornblom committed Feb 5, 2018
1 parent ff08702 commit dae339b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rsl/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def accept_BinaryOpNode(self, node):

if self.runtime.is_set(lhs):
rhs = self.runtime.cast_to_set(rhs)

if self.runtime.is_set(rhs):
lhs = self.runtime.cast_to_set(lhs)

value = ops[node.sign](lhs, rhs)

Expand Down
40 changes: 40 additions & 0 deletions tests/test_binop.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,43 @@ def test_instance_minus_same_instance(self):
rc = self.eval_text(text)
self.assertEqual(0, rc)


def test_instance_set_minus_instance_set(self):
self.metamodel.define_class('A', [('Name', 'string')])

text = '''
.create object instance a1 of A
.create object instance a2 of A
.assign a1.Name = "A1"
.assign a2.Name = "A2"
.select many an_set from instances of A
.select many a0_set from instances of A where (false)
.if ((cardinality (an_set - a0_set)) != 2)
.exit 1
.end if
.if ((cardinality (a0_set - an_set)) != 0)
.exit 2
.end if
.if ((cardinality (an_set - a1)) != 1)
.exit 3
.end if
.if ((cardinality (a1 - an_set)) != 0)
.exit 4
.end if
.if ((cardinality (a0_set - a1)) != 0)
.exit 5
.end if
.if ((cardinality (a1 - a0_set)) != 1)
.exit 6
.end if
.exit 0
'''
rc = self.eval_text(text)
self.assertEqual(0, rc)

0 comments on commit dae339b

Please sign in to comment.