def test_merging_interval_rules_generally(self): """Merging `0 < x < 4` and `2 < x < 6` should produce `2 < x < 4`.""" rule1 = IntervalRule("Rule", ContinuousRule("Rule", True, 0), ContinuousRule("Rule", False, 4)) rule2 = IntervalRule("Rule", ContinuousRule("Rule", True, 2), ContinuousRule("Rule", False, 6)) new_rule = rule1.merge_with(rule2) self.assertEqual(new_rule.left_rule.value, 2) self.assertEqual(new_rule.right_rule.value, 4)
def test_merging_interval_rules_with_smaller_lt_component(self): """Merging `1 < x < 2` and `0 < x < 2` should produce `1 < x < 2`.""" rule1 = IntervalRule("Rule", ContinuousRule("Rule", True, 1), ContinuousRule("Rule", False, 2)) rule2 = IntervalRule("Rule", ContinuousRule("Rule", True, 0), ContinuousRule("Rule", False, 2)) new_rule = rule1.merge_with(rule2) self.assertEqual(new_rule.left_rule.value, 1) self.assertEqual(new_rule.right_rule.value, 2)
def test_merge_commutativity_on_interval_rules(self): """Interval rule merging should be commutative.""" rule1 = IntervalRule("Rule", ContinuousRule("Rule", True, 0), ContinuousRule("Rule", False, 4)) rule2 = IntervalRule("Rule", ContinuousRule("Rule", True, 2), ContinuousRule("Rule", False, 6)) new_rule1 = rule1.merge_with(rule2) new_rule2 = rule2.merge_with(rule1) self.assertEqual(new_rule1.left_rule.value, new_rule2.left_rule.value) self.assertEqual(new_rule1.right_rule.value, new_rule2.right_rule.value)
def test_merging_interval_rules_with_larger_lt_component(self): """Merging `0 < x < 4` and `1 < x < 4` should produce `1 < x < 4`.""" rule1 = IntervalRule('Rule', ContinuousRule('Rule', True, 0), ContinuousRule('Rule', False, 4)) rule2 = IntervalRule('Rule', ContinuousRule('Rule', True, 1), ContinuousRule('Rule', False, 4)) new_rule = rule1.merge_with(rule2) self.assertEqual(new_rule.left_rule.value, 1) self.assertEqual(new_rule.right_rule.value, 4)
def test_merging_interval_rule_with_smaller_gt_continuous_rule(self): """Merging `0 < x < 3` and `x < 2` should produce `0 < x < 2`.""" rule1 = IntervalRule("Rule", ContinuousRule("Rule", True, 0), ContinuousRule("Rule", False, 3)) rule2 = ContinuousRule("Rule", False, 2) new_rule = rule1.merge_with(rule2) self.assertIsInstance(new_rule, IntervalRule) self.assertEqual(new_rule.right_rule.value, 2)
def test_merging_interval_rule_with_larger_lt_continuous_rule(self): """Merging `0 < x < 3` and `x > 1` should produce `1 < x < 3`.""" rule1 = IntervalRule("Rule", ContinuousRule("Rule", True, 0), ContinuousRule("Rule", False, 3)) rule2 = ContinuousRule("Rule", True, 1) new_rule = rule1.merge_with(rule2) self.assertIsInstance(new_rule, IntervalRule) self.assertEqual(new_rule.left_rule.value, 1)
def test_merging_interval_rule_with_larger_continuous_rule(self): """Merging `1 < x < 2` and `x < 3` should produce `1 < x < 2`.""" rule1 = IntervalRule('Rule', ContinuousRule('Rule', True, 1), ContinuousRule('Rule', False, 2)) rule2 = ContinuousRule('Rule', False, 3) new_rule = rule1.merge_with(rule2) self.assertIsInstance(new_rule, IntervalRule) self.assertEqual(new_rule.left_rule.value, 1)