def test_set(self):
		lst = AvlTreeList()
		for _ in range(10):
			lst.append(None)
		lst[0] = "zero"
		lst[1] = "ten"
		lst[2] = "twenty"
		lst[3] = "thirty"
		lst[4] = "forty"
		lst[5] = "fifty"
		lst[6] = "sixty"
		lst[7] = "seventy"
		lst[8] = "eighty"
		lst[9] = "ninety"
		self.assertEqual(10, len(lst))
		self.assertEqual("zero"   , lst[0])
		self.assertEqual("ten"    , lst[1])
		self.assertEqual("twenty" , lst[2])
		self.assertEqual("thirty" , lst[3])
		self.assertEqual("forty"  , lst[4])
		self.assertEqual("fifty"  , lst[5])
		self.assertEqual("sixty"  , lst[6])
		self.assertEqual("seventy", lst[7])
		self.assertEqual("eighty" , lst[8])
		self.assertEqual("ninety" , lst[9])
Exemple #2
0
 def test_set(self):
     lst = AvlTreeList()
     for _ in range(10):
         lst.append(None)
     lst[0] = "zero"
     lst[1] = "ten"
     lst[2] = "twenty"
     lst[3] = "thirty"
     lst[4] = "forty"
     lst[5] = "fifty"
     lst[6] = "sixty"
     lst[7] = "seventy"
     lst[8] = "eighty"
     lst[9] = "ninety"
     self.assertEqual(10, len(lst))
     self.assertEqual("zero", lst[0])
     self.assertEqual("ten", lst[1])
     self.assertEqual("twenty", lst[2])
     self.assertEqual("thirty", lst[3])
     self.assertEqual("forty", lst[4])
     self.assertEqual("fifty", lst[5])
     self.assertEqual("sixty", lst[6])
     self.assertEqual("seventy", lst[7])
     self.assertEqual("eighty", lst[8])
     self.assertEqual("ninety", lst[9])
Exemple #3
0
    def test_remove(self):
        lst = AvlTreeList()
        s = "the quick brown fox jumped over the lazy dog"
        for c in s:
            lst.append(c)
        self.assertEqual(len(s), len(lst))

        self.assertEqual('e', lst.pop(2))
        self.assertEqual('u', lst.pop(4))
        self.assertEqual('q', lst.pop(3))
        self.assertEqual(' ', lst.pop(2))
        self.assertEqual('f', lst.pop(12))
        self.assertEqual(' ', lst.pop(11))
        self.assertEqual('n', lst.pop(10))
        self.assertEqual('w', lst.pop(9))
        self.assertEqual(' ', lst.pop(11))
        self.assertEqual('j', lst.pop(11))
        self.assertEqual('u', lst.pop(11))
        self.assertEqual('x', lst.pop(10))
        self.assertEqual('p', lst.pop(11))
        self.assertEqual('d', lst.pop(12))
        self.assertEqual('e', lst.pop(11))
        self.assertEqual('v', lst.pop(13))
        self.assertEqual('e', lst.pop(13))
        self.assertEqual('l', lst.pop(19))
        self.assertEqual('z', lst.pop(20))
        self.assertEqual('a', lst.pop(19))
        self.assertEqual(' ', lst.pop(18))
        self.assertEqual('g', lst.pop(22))

        s = "thick broom or they do"
        self.assertEqual(len(s), len(lst))
        for i in range(len(s)):
            self.assertEqual(s[i], lst[i])

        self.assertEqual('t', lst.pop(0))
        self.assertEqual('c', lst.pop(2))
        self.assertEqual('k', lst.pop(2))
        self.assertEqual(' ', lst.pop(2))
        self.assertEqual('b', lst.pop(2))
        self.assertEqual('r', lst.pop(2))
        self.assertEqual('o', lst.pop(2))
        self.assertEqual('o', lst.pop(2))
        self.assertEqual('o', lst.pop(4))
        self.assertEqual('h', lst.pop(7))
        self.assertEqual(' ', lst.pop(5))
        self.assertEqual('t', lst.pop(5))
        self.assertEqual('o', lst.pop(9))
        self.assertEqual(' ', lst.pop(7))
        self.assertEqual('y', lst.pop(6))

        s = "him red"
        self.assertEqual(len(s), len(lst))
        for i in range(len(s)):
            self.assertEqual(s[i], lst[i])
	def test_remove(self):
		lst = AvlTreeList()
		s = "the quick brown fox jumped over the lazy dog"
		for c in s:
			lst.append(c)
		self.assertEqual(len(s), len(lst))
		
		self.assertEqual('e', lst.pop( 2))
		self.assertEqual('u', lst.pop( 4))
		self.assertEqual('q', lst.pop( 3))
		self.assertEqual(' ', lst.pop( 2))
		self.assertEqual('f', lst.pop(12))
		self.assertEqual(' ', lst.pop(11))
		self.assertEqual('n', lst.pop(10))
		self.assertEqual('w', lst.pop( 9))
		self.assertEqual(' ', lst.pop(11))
		self.assertEqual('j', lst.pop(11))
		self.assertEqual('u', lst.pop(11))
		self.assertEqual('x', lst.pop(10))
		self.assertEqual('p', lst.pop(11))
		self.assertEqual('d', lst.pop(12))
		self.assertEqual('e', lst.pop(11))
		self.assertEqual('v', lst.pop(13))
		self.assertEqual('e', lst.pop(13))
		self.assertEqual('l', lst.pop(19))
		self.assertEqual('z', lst.pop(20))
		self.assertEqual('a', lst.pop(19))
		self.assertEqual(' ', lst.pop(18))
		self.assertEqual('g', lst.pop(22))
		
		s = "thick broom or they do";
		self.assertEqual(len(s), len(lst))
		for i in range(len(s)):
			self.assertEqual(s[i], lst[i])
		
		self.assertEqual('t', lst.pop(0))
		self.assertEqual('c', lst.pop(2))
		self.assertEqual('k', lst.pop(2))
		self.assertEqual(' ', lst.pop(2))
		self.assertEqual('b', lst.pop(2))
		self.assertEqual('r', lst.pop(2))
		self.assertEqual('o', lst.pop(2))
		self.assertEqual('o', lst.pop(2))
		self.assertEqual('o', lst.pop(4))
		self.assertEqual('h', lst.pop(7))
		self.assertEqual(' ', lst.pop(5))
		self.assertEqual('t', lst.pop(5))
		self.assertEqual('o', lst.pop(9))
		self.assertEqual(' ', lst.pop(7))
		self.assertEqual('y', lst.pop(6))
		
		s = "him red";
		self.assertEqual(len(s), len(lst))
		for i in range(len(s)):
			self.assertEqual(s[i], lst[i])
Exemple #5
0
 def test_insert_many_everywhere(self):
     N = 15
     lst = AvlTreeList()
     lst.append(0)
     for i in reversed(range(N)):
         k = 1
         for j in range(1 << i, 1 << N, 2 << i):
             lst.insert(k, j)
             k += 2
     for (i, x) in enumerate(lst):
         self.assertEqual(i, x)
	def test_insert_many_everywhere(self):
		N = 15
		lst = AvlTreeList()
		lst.append(0)
		for i in reversed(range(N)):
			k = 1
			for j in range(1 << i, 1 << N, 2 << i):
				lst.insert(k, j)
				k += 2
		for (i, x) in zip(itertools.count(), lst):
			self.assertEqual(i, x)
Exemple #7
0
    def test_iterator(self):
        lst = AvlTreeList()
        for i in range(50):
            lst.append(i * i)

        itr = iter(lst)
        for i in range(50):
            self.assertEqual(i * i, next(itr))
        try:
            next(itr)
            self.fail()
        except StopIteration:
            pass
	def test_iterator(self):
		lst = AvlTreeList()
		for i in range(50):
			lst.append(i * i)
		
		itr = iter(lst)
		for i in range(50):
			self.assertEqual(i * i, next(itr))
		try:
			next(itr)
			self.fail()
		except StopIteration:
			pass
Exemple #9
0
 def test_add(self):
     lst = AvlTreeList()
     lst.append("January")
     lst.append("February")
     lst.append("March")
     lst.append("April")
     lst.append("May")
     lst.append("June")
     lst.check_structure()
     self.assertEqual(6, len(lst))
     self.assertEqual("January", lst[0])
     self.assertEqual("February", lst[1])
     self.assertEqual("March", lst[2])
     self.assertEqual("April", lst[3])
     self.assertEqual("May", lst[4])
     self.assertEqual("June", lst[5])
	def test_add(self):
		lst = AvlTreeList()
		lst.append("January")
		lst.append("February")
		lst.append("March")
		lst.append("April")
		lst.append("May")
		lst.append("June")
		lst.check_structure()
		self.assertEqual(6, len(lst))
		self.assertEqual("January" , lst[0])
		self.assertEqual("February", lst[1])
		self.assertEqual("March"   , lst[2])
		self.assertEqual("April"   , lst[3])
		self.assertEqual("May"     , lst[4])
		self.assertEqual("June"    , lst[5])
Exemple #11
0
    def test_clear(self):
        lst = AvlTreeList()
        for i in range(20):
            lst.append(i * i)

        lst.clear()
        self.assertEqual(0, len(lst))

        lst.append(-1)
        lst.append(-8)
        lst.append(-27)
        self.assertEqual(3, len(lst))
        self.assertEqual(-1, lst[0])
        self.assertEqual(-8, lst[1])
        self.assertEqual(-27, lst[2])
	def test_clear(self):
		lst = AvlTreeList()
		for i in range(20):
			lst.append(i * i)
		
		lst.clear()
		self.assertEqual(0, len(lst))
		
		lst.append(- 1)
		lst.append(- 8)
		lst.append(-27)
		self.assertEqual(3, len(lst))
		self.assertEqual(- 1, lst[0])
		self.assertEqual(- 8, lst[1])
		self.assertEqual(-27, lst[2])
Exemple #13
0
 def test_insert_many_beginning(self):
     lst = AvlTreeList()
     for i in range(30000):
         lst.append(i)
     for (i, x) in enumerate(lst):
         self.assertEqual(i, x)
Exemple #14
0
    def test_insert_list(self):
        lst = AvlTreeList()

        def extend(dest, i, src):
            for (j, val) in enumerate(src):
                dest.insert(i + j, val)

        small = AvlTreeList()
        small.append("1")
        small.append("2")
        small.append("3")
        small.append("5")
        extend(lst, 0, small)

        small = AvlTreeList()
        small.append("377")
        small.append("610")
        small.append("987")
        extend(lst, 4, small)

        small = AvlTreeList()
        small.append("8")
        small.append("13")
        small.append("21")
        small.append("144")
        small.append("233")
        extend(lst, 4, small)

        small = AvlTreeList()
        small.append("34")
        small.append("55")
        small.append("89")
        extend(lst, 7, small)

        self.assertEqual(15, len(lst))
        self.assertEqual("1", lst[0])
        self.assertEqual("2", lst[1])
        self.assertEqual("3", lst[2])
        self.assertEqual("5", lst[3])
        self.assertEqual("8", lst[4])
        self.assertEqual("13", lst[5])
        self.assertEqual("21", lst[6])
        self.assertEqual("34", lst[7])
        self.assertEqual("55", lst[8])
        self.assertEqual("89", lst[9])
        self.assertEqual("144", lst[10])
        self.assertEqual("233", lst[11])
        self.assertEqual("377", lst[12])
        self.assertEqual("610", lst[13])
        self.assertEqual("987", lst[14])
	def test_insert_many_beginning(self):
		lst = AvlTreeList()
		for i in range(30000):
			lst.append(i)
		for (i, x) in zip(itertools.count(), lst):
			self.assertEqual(i, x)
Exemple #16
0
    def test_add_list(self):
        lst = AvlTreeList()

        small = AvlTreeList()
        small.append("January")
        lst.extend(small)

        small = AvlTreeList()
        small.append("February")
        small.append("March")
        small.append("April")
        lst.extend(small)

        small = AvlTreeList()
        small.append("May")
        small.append("June")
        small.append("July")
        small.append("August")
        small.append("September")
        small.append("October")
        small.append("November")
        small.append("December")
        lst.extend(small)

        self.assertEqual(12, len(lst))
        self.assertEqual("January", lst[0])
        self.assertEqual("February", lst[1])
        self.assertEqual("March", lst[2])
        self.assertEqual("April", lst[3])
        self.assertEqual("May", lst[4])
        self.assertEqual("June", lst[5])
        self.assertEqual("July", lst[6])
        self.assertEqual("August", lst[7])
        self.assertEqual("September", lst[8])
        self.assertEqual("October", lst[9])
        self.assertEqual("November", lst[10])
        self.assertEqual("December", lst[11])
	def test_add_list(self):
		lst = AvlTreeList()
		
		small = AvlTreeList()
		small.append("January")
		lst.extend(small)
		
		small = AvlTreeList()
		small.append("February")
		small.append("March")
		small.append("April")
		lst.extend(small)
		
		small = AvlTreeList()
		small.append("May")
		small.append("June")
		small.append("July")
		small.append("August")
		small.append("September")
		small.append("October")
		small.append("November")
		small.append("December")
		lst.extend(small)
		
		self.assertEqual(12, len(lst))
		self.assertEqual("January"  , lst[ 0])
		self.assertEqual("February" , lst[ 1])
		self.assertEqual("March"    , lst[ 2])
		self.assertEqual("April"    , lst[ 3])
		self.assertEqual("May"      , lst[ 4])
		self.assertEqual("June"     , lst[ 5])
		self.assertEqual("July"     , lst[ 6])
		self.assertEqual("August"   , lst[ 7])
		self.assertEqual("September", lst[ 8])
		self.assertEqual("October"  , lst[ 9])
		self.assertEqual("November" , lst[10])
		self.assertEqual("December" , lst[11])
 def test_insert_many_beginning(self):
     lst = AvlTreeList()
     for i in range(30000):
         lst.append(i)
     for (i, x) in zip(itertools.count(), lst):
         self.assertEqual(i, x)
	def test_insert_list(self):
		lst = AvlTreeList()
		def extend(dest, i, src):
			for (j, val) in enumerate(src):
				dest.insert(i + j, val)
		
		small = AvlTreeList()
		small.append("1")
		small.append("2")
		small.append("3")
		small.append("5")
		extend(lst, 0, small)
		
		small = AvlTreeList()
		small.append("377")
		small.append("610")
		small.append("987")
		extend(lst, 4, small)
		
		small = AvlTreeList()
		small.append("8")
		small.append("13")
		small.append("21")
		small.append("144")
		small.append("233")
		extend(lst, 4, small)
		
		small = AvlTreeList()
		small.append("34")
		small.append("55")
		small.append("89")
		extend(lst, 7, small)
		
		self.assertEqual(15, len(lst))
		self.assertEqual(  "1", lst[ 0])
		self.assertEqual(  "2", lst[ 1])
		self.assertEqual(  "3", lst[ 2])
		self.assertEqual(  "5", lst[ 3])
		self.assertEqual(  "8", lst[ 4])
		self.assertEqual( "13", lst[ 5])
		self.assertEqual( "21", lst[ 6])
		self.assertEqual( "34", lst[ 7])
		self.assertEqual( "55", lst[ 8])
		self.assertEqual( "89", lst[ 9])
		self.assertEqual("144", lst[10])
		self.assertEqual("233", lst[11])
		self.assertEqual("377", lst[12])
		self.assertEqual("610", lst[13])
		self.assertEqual("987", lst[14])