Exemplo n.º 1
0
 def test_and(self):
     for i in range(algebra_repeats):
         a = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         b = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         c = a & b
         assert c == a - (a - b)
         assert c == b - (b - a)
Exemplo n.º 2
0
	def test__and__(self):
		for i in range(algebra_repeats):
			a = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			b = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			c = a & b
			try:
				# make sure __and__ and __sub__ have the
				# correct relationship to one another
				self.assertEqual(c, a - (a - b))
				self.assertEqual(c, b - (b - a))
			except AssertionError as e:
				raise AssertionError(str(e) + "\na = " + str(a) + "\nb = " + str(b))
Exemplo n.º 3
0
	def testintersects(self):
		for i in range(algebra_repeats):
			a = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			b = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			c = a - b
			d = a & b
			try:
				if len(c):
					self.assertFalse(c.intersects(b))
				if len(d):
					self.assertTrue(d.intersects(a))
					self.assertTrue(d.intersects(b))
					self.assertTrue(a.intersects(b))
			except AssertionError as e:
				raise AssertionError(str(e) + "\na = " + str(a) + "\nb = " + str(b))
Exemplo n.º 4
0
 def test__and__(self):
     for i in xrange(algebra_repeats):
         a = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         b = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         c = a & b
         try:
             # make sure __and__ and __sub__ have the
             # correct relationship to one another
             self.assertEqual(c, a - (a - b))
             self.assertEqual(c, b - (b - a))
         except AssertionError, e:
             raise AssertionError, str(e) + "\na = " + str(
                 a) + "\nb = " + str(b)
Exemplo n.º 5
0
    def test_intersects(self):
        for i in range(algebra_repeats):
            a = verifyutils.random_coalesced_list(
                random.randint(1, algebra_listlength))
            b = verifyutils.random_coalesced_list(
                random.randint(1, algebra_listlength))
            c = a - b
            d = a & b

            if len(c):
                assert not c.intersects(b)
            if len(d):
                assert d.intersects(a)
                assert d.intersects(b)
                assert a.intersects(b)
Exemplo n.º 6
0
	def test__or__(self):
		for i in range(algebra_repeats):
			a = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			b = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			c = a | b
			try:
				# make sure c is coalesced
				self.assertTrue(verifyutils.iscoalesced(c))
				# make sure c contains all of a
				self.assertEqual(a, c & a)
				# make sure c contains all of b
				self.assertEqual(b, c & b)
				# make sure c contains nothing except a and b
				self.assertEqual(segments.segmentlist([]), c - a - b)
			except AssertionError as e:
				raise AssertionError(str(e) + "\na = " + str(a) + "\nb = " + str(b))
Exemplo n.º 7
0
    def test_or(self):
        for i in range(algebra_repeats):
            a = verifyutils.random_coalesced_list(
                random.randint(1, algebra_listlength))
            b = verifyutils.random_coalesced_list(
                random.randint(1, algebra_listlength))
            c = a | b

            # make sure c is coalesced
            assert verifyutils.iscoalesced(c)
            # make sure c contains all of a
            assert a == c & a
            # make sure c contains all of b
            assert b == c & b
            # make sure c contains nothing except a and b
            assert segments.segmentlist([]) == c - a - b
Exemplo n.º 8
0
 def testintersects(self):
     for i in xrange(algebra_repeats):
         a = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         b = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         c = a - b
         d = a & b
         try:
             if len(c):
                 self.assertFalse(c.intersects(b))
             if len(d):
                 self.assertTrue(d.intersects(a))
                 self.assertTrue(d.intersects(b))
                 self.assertTrue(a.intersects(b))
         except AssertionError, e:
             raise AssertionError, str(e) + "\na = " + str(
                 a) + "\nb = " + str(b)
Exemplo n.º 9
0
	def test__xor__(self):
		for i in range(algebra_repeats):
			a = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			b = verifyutils.random_coalesced_list(random.randint(1, algebra_listlength))
			c = a ^ b
			try:
				# c contains nothing that can be found in
				# the intersection of a and b
				self.assertFalse(c.intersects(a & b))
				# c contains nothing that cannot be found
				# in either a or b
				self.assertEqual(segments.segmentlist([]), c - a - b)
				# that c + the intersection of a and b
				# leaves no part of either a or b
				# unconvered
				self.assertEqual(segments.segmentlist([]), a - (c | a & b))
				self.assertEqual(segments.segmentlist([]), b - (c | a & b))
			except AssertionError as e:
				raise AssertionError(str(e) + "\na = " + str(a) + "\nb = " + str(b))
Exemplo n.º 10
0
 def test__or__(self):
     for i in xrange(algebra_repeats):
         a = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         b = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         c = a | b
         try:
             # make sure c is coalesced
             self.assertTrue(verifyutils.iscoalesced(c))
             # make sure c contains all of a
             self.assertEqual(a, c & a)
             # make sure c contains all of b
             self.assertEqual(b, c & b)
             # make sure c contains nothing except a and b
             self.assertEqual(segments.segmentlist([]), c - a - b)
         except AssertionError, e:
             raise AssertionError, str(e) + "\na = " + str(
                 a) + "\nb = " + str(b)
Exemplo n.º 11
0
    def test_xor(self):
        for i in range(algebra_repeats):
            a = verifyutils.random_coalesced_list(
                random.randint(1, algebra_listlength))
            b = verifyutils.random_coalesced_list(
                random.randint(1, algebra_listlength))
            c = a ^ b

            # c contains nothing that can be found in
            # the intersection of a and b
            assert not c.intersects(a & b)
            # c contains nothing that cannot be found
            # in either a or b
            assert segments.segmentlist([]) == c - a - b
            # that c + the intersection of a and b
            # leaves no part of either a or b
            # unconvered
            assert segments.segmentlist([]) == a - (c | a & b)
            assert segments.segmentlist([]) == b - (c | a & b)
Exemplo n.º 12
0
	def test_vote(self):
		"""
		Test vote().
		"""
		for i in range(algebra_repeats):
			seglists = []
			for j in range(random.randint(0, 10)):
				seglists.append(verifyutils.random_coalesced_list(algebra_listlength))
			n = random.randint(0, len(seglists))
			correct = reduce(lambda x, y: x | y, (votes and reduce(lambda a, b: a & b, votes) or segments.segmentlist() for votes in iterutils.choices(seglists, n)), segments.segmentlist())
			self.assertEqual(correct, segmentsUtils.vote(seglists, n))
Exemplo n.º 13
0
 def test__xor__(self):
     for i in xrange(algebra_repeats):
         a = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         b = verifyutils.random_coalesced_list(
             random.randint(1, algebra_listlength))
         c = a ^ b
         try:
             # c contains nothing that can be found in
             # the intersection of a and b
             self.assertFalse(c.intersects(a & b))
             # c contains nothing that cannot be found
             # in either a or b
             self.assertEqual(segments.segmentlist([]), c - a - b)
             # that c + the intersection of a and b
             # leaves no part of either a or b
             # unconvered
             self.assertEqual(segments.segmentlist([]), a - (c | a & b))
             self.assertEqual(segments.segmentlist([]), b - (c | a & b))
         except AssertionError, e:
             raise AssertionError, str(e) + "\na = " + str(
                 a) + "\nb = " + str(b)
Exemplo n.º 14
0
    def test_vote(self):
        """
		Test vote().
		"""
        for i in range(algebra_repeats):
            seglists = []
            for j in range(random.randint(0, 10)):
                seglists.append(
                    verifyutils.random_coalesced_list(algebra_listlength))
            n = random.randint(0, len(seglists))
            correct = reduce(lambda x, y: x | y,
                             (votes and reduce(lambda a, b: a & b, votes)
                              or segments.segmentlist()
                              for votes in iterutils.choices(seglists, n)),
                             segments.segmentlist())
            self.assertEqual(correct, segmentsUtils.vote(seglists, n))
Exemplo n.º 15
0
 def test_vote(self):
     """
     Test vote().
     """
     for i in range(algebra_repeats):
         seglists = []
         for j in range(random.randint(0, 10)):
             seglists.append(
                 verifyutils.random_coalesced_list(algebra_listlength))
         n = random.randint(0, len(seglists))
         assert utils.vote(seglists, n) == reduce(
             lambda x, y: x | y,
             (votes and reduce(lambda a, b: a & b, votes)
              or segments.segmentlist()
              for votes in itertools.combinations(seglists, n)),
             segments.segmentlist())