def test_constructor_with_constants(self): """The order must not change when the parameters are constant.""" l_op = Number(3) r_op = Number(4) operation = LessThan(l_op, r_op) eq_(l_op, operation.master_operand) eq_(r_op, operation.slave_operand)
def test_constructor_with_constant_before_variable(self): """ The order *must* change when the first parameter is a constant and the second is a variable. """ l_op = Number(2) r_op = PedestriansCrossingRoad() operation = GreaterThan(l_op, r_op) eq_(r_op, operation.master_operand) eq_(l_op, operation.slave_operand)
def test_constructor_with_variable_before_constant(self): """ The order must not change when the first parameter is a variable and the second is a constant. """ l_op = PedestriansCrossingRoad() r_op = Number(2) operation = LessThan(l_op, r_op) eq_(l_op, operation.master_operand) eq_(r_op, operation.slave_operand)
def test_mixed_arguments(self): l_op = PedestriansCrossingRoad() r_op = Number(2) operation = GreaterEqual(l_op, r_op) # |{"carla", "yolmary", "manuel"}| > 2 <=> 3 > 2 context = {'pedestrians_crossroad': ("carla", "yolmary", "manuel")} ok_(operation(context)) # |{"carla"}| > 2 <=> 1 > 2 context = {'pedestrians_crossroad': ("carla", )} assert_false(operation(context))
def test_mixed_arguments(self): l_op = PedestriansCrossingRoad() r_op = Number(2) operation = LessEqual(l_op, r_op) # |{"carla"}| < 2 <=> 1 < 2 context = {'pedestrians_crossroad': ("carla", )} ok_(operation(context)) # |{"carla", "carlos", "liliana"}| < 2 <=> 1 < 2 context = {'pedestrians_crossroad': ("carla", "carlos", "liliana")} assert_false(operation(context))
def test_constant_evaluation(self): subset = Set(Number(3), Number(1), Number(7)) set_ = Set(Number(1), Number(3), Number(5), Number(7), Number(11)) operation = IsSubset(subset, set_) ok_(operation(None))
def test_non_set_and_non_set(self): subset = Number(1) set_ = Number(2) assert_raises(InvalidOperationError, IsSubset, subset, set_)
def test_set_and_set(self): subset = Set(Number(2), Number(4)) set_ = Set(Number(1), Number(3), Number(5), Number(7), Number(11)) operation = IsSubset(subset, set_) eq_(operation.master_operand, set_) eq_(operation.slave_operand, subset)
def test_constant_evaluation(self): item = Number(3) set_ = Set(Number(1), Number(3), Number(5), Number(7), Number(11)) operation = BelongsTo(item, set_) ok_(operation(None))
def test_item_and_non_set(self): item = Number(1) set_ = Number(2) assert_raises(InvalidOperationError, BelongsTo, item, set_)
def test_item_and_set(self): item = Number(3) set_ = Set(Number(1), Number(3), Number(5), Number(7), Number(11)) operation = BelongsTo(item, set_) eq_(operation.master_operand, set_) eq_(operation.slave_operand, item)
def test_two_constants(self): l_op = Number(4) r_op = Number(3) operation = GreaterEqual(l_op, r_op) ok_(operation(None))
def test_identical_values(self): l_op = Number(3) r_op = Number(3) operation = GreaterEqual(l_op, r_op) ok_(operation(None))
def test_identical_values(self): l_op = Number(3) r_op = Number(3) operation = GreaterThan(l_op, r_op) assert_false(operation(None))
def test_two_constants(self): l_op = Number(3) r_op = Number(4) operation = LessThan(l_op, r_op) ok_(operation(None))