def test_copy(self): eprint(">> Continuum.copy(self)") for i in range(self.__nb_unit_test): # Emptyset c_ = Continuum() c = c_.copy() self.assertTrue(c.is_empty()) self.assertEqual(c.get_min_value(), None) self.assertEqual(c.get_max_value(), None) self.assertEqual(c.min_included(), None) self.assertEqual(c.max_included(), None) # Non empty min = random.uniform(self.__min_value, self.__max_value) max = random.uniform(min, self.__max_value) min_included = random.choice([True, False]) max_included = random.choice([True, False]) c_ = Continuum(min, max, min_included, max_included) c = c_.copy() self.assertFalse(c.is_empty()) self.assertEqual(c.get_min_value(), min) self.assertEqual(c.get_max_value(), max) self.assertEqual(c.min_included(), min_included) self.assertEqual(c.max_included(), max_included)
def test_set_upper_bound(self): eprint(">> Continuum.set_upper_bound(self, value, included)") for i in range(self.__nb_unit_test): # Empty set c = Continuum() self.assertRaises(TypeError, c.set_upper_bound, "string", True) self.assertRaises(TypeError, c.set_upper_bound, "string", False) self.assertRaises(TypeError, c.set_upper_bound, 0.5, 10) value = random.uniform(self.__min_value, self.__max_value) # extend with exclusion gives empty set, mistake expected from user # or both min and max will be changed and constructor must be used self.assertRaises(ValueError, c.set_upper_bound, value, False) c.set_upper_bound(value, True) # Empty set to one value interval self.assertEqual(c, Continuum(value, value, True, True)) # Regular continuum # over min value c = Continuum.random(self.__min_value, self.__max_value) value = random.uniform(self.__min_value, c.get_min_value()) while value == c.get_min_value(): value = random.uniform(self.__min_value, c.get_min_value()) self.assertRaises(ValueError, c.set_upper_bound, value, True) self.assertRaises(ValueError, c.set_upper_bound, value, False) # on min value c = Continuum.random(self.__min_value, self.__max_value) c_old = c.copy() value = c.get_min_value() if not c.max_included() or not c.min_included(): c.set_upper_bound(value, False) self.assertEqual(c, Continuum()) # continuum reduced to empty set else: c.set_upper_bound(value, True) self.assertEqual(c.get_max_value(), value) self.assertEqual(c.max_included(), True) self.assertEqual(c.get_max_value(), c.get_min_value()) self.assertEqual(c.get_min_value(), c_old.get_min_value()) self.assertEqual(c.min_included(), c_old.min_included()) # other valid value c = Continuum.random(self.__min_value, self.__max_value) c_old = c.copy() value = random.uniform(c.get_min_value(), self.__max_value) while value == c.get_min_value(): value = random.uniform(c.get_min_value(), self.__max_value) c.set_upper_bound(value, True) self.assertEqual(c.get_max_value(), value) self.assertEqual(c.max_included(), True) c = Continuum.random(self.__min_value, self.__max_value) c_old = c.copy() value = random.uniform(c.get_min_value(), self.__max_value) while value == c.get_min_value(): value = random.uniform(c.get_min_value(), self.__max_value) c.set_upper_bound(value, False) self.assertEqual(c.get_max_value(), value) self.assertEqual(c.max_included(), False)
def test__eq__(self): eprint(">> Continuum.__eq__(self, continuum)") for i in range(self.__nb_unit_test): # emptyset c = Continuum() self.assertTrue(Continuum() == Continuum()) self.assertTrue(c == Continuum()) self.assertTrue(c == c) self.assertFalse(Continuum() != Continuum()) self.assertFalse(c != Continuum()) self.assertFalse(c != c) c = Continuum.random(self.__min_value, self.__max_value) self.assertTrue(c == c) self.assertFalse(c != c) self.assertEqual(c == Continuum(), c.is_empty()) c_ = Continuum.random(self.__min_value, self.__max_value) if c.is_empty() and c_.is_empty(): self.assertTrue(c == c_) self.assertTrue(c != c_) if c.is_empty() != c_.is_empty(): self.assertFalse(c == c_) self.assertTrue(c != c_) if c.get_min_value() != c_.get_min_value(): self.assertFalse(c == c_) self.assertTrue(c != c_) if c.get_max_value() != c_.get_max_value(): self.assertFalse(c == c_) self.assertTrue(c != c_) if c.min_included() != c_.min_included(): self.assertFalse(c == c_) self.assertTrue(c != c_) if c.max_included() != c_.max_included(): self.assertFalse(c == c_) self.assertTrue(c != c_) # exaustive modifications if not c.is_empty(): c_ = c.copy() value = random.uniform(1, 100) c_.set_lower_bound(c.get_min_value() - value, True) self.assertFalse(c == c_) self.assertTrue(c != c_) c_.set_lower_bound(c.get_min_value() - value, False) self.assertFalse(c == c_) self.assertTrue(c != c_) c_ = c.copy() c_.set_lower_bound(c.get_min_value(), not c.min_included()) self.assertFalse(c == c_) self.assertTrue(c != c_) c_ = c.copy() value = random.uniform(1, 100) c_.set_upper_bound(c.get_min_value() + value, True) self.assertFalse(c == c_) self.assertTrue(c != c_) c_.set_upper_bound(c.get_min_value() + value, False) self.assertFalse(c == c_) self.assertTrue(c != c_) c_ = c.copy() c_.set_upper_bound(c.get_max_value(), not c.max_included()) self.assertFalse(c == c_) self.assertTrue(c != c_) # different type self.assertFalse(c == "test") self.assertFalse(c == 0) self.assertFalse(c == True) self.assertFalse(c == [])