Exemplo n.º 1
0
 def test_insert(self):
     r = list(range(10))
     self.l.insert(0, 10)
     r.insert(0, 10)
     self.assertEqual(self.l, r)
     self.l.insert(2, 11)
     r.insert(2, 11)
     self.assertEqual(self.l, r)
     r.insert(12, 12)
     self.l.insert(12, 12)
     self.assertEqual(self.l, r)
     self.l.insert(-2, 13)
     r.insert(-2, 13)
     self.assertEqual(self.l, r)
     self.l.insert(-20, 14)
     r.insert(-20, 14)
     self.assertEqual(self.l, r)
     self.l.insert(20, 15)
     r.insert(20, 15)
     self.assertEqual(self.l, r)
     empty = orange.IntList()
     empty.insert(0, 0)
     self.assertEqual(empty, [0])
     empty = orange.IntList()
     empty.insert(10, 0)
     self.assertEqual(empty, [0])
     empty = orange.IntList()
     empty.insert(-10, 0)
     self.assertEqual(empty, [0])
Exemplo n.º 2
0
 def test_concat(self):
     first = orange.IntList(range(5))
     second = orange.IntList(range(5, 10))
     empty = orange.IntList()
     self.assertEqual(first + second, self.l)
     self.assertEqual(first + [], first)
     self.assertEqual(first + empty, first)
     self.assertEqual(empty + first, first)
     self.assertEqual(empty + empty, empty)
Exemplo n.º 3
0
 def test_slice_and_cmp(self):
     self.assertEqual(self.l[2:5], orange.IntList(range(2, 5)))
     self.assertEqual(self.l[2:5], range(2, 5))
     self.assertGreater(self.l[2:5], orange.IntList(range(1, 5)))
     self.assertGreater(self.l[2:5], orange.IntList([1]))
     self.assertGreater(self.l[2:5], orange.IntList())
     self.assertGreater(self.l[2:5], [])
     self.assertGreater(self.l[2:5], [])
     self.assertLess([], self.l[2:5])
     self.assertLess([1, 2, 3], self.l[2:5])
     self.assertEqual(self.l[::-1], range(9, -1, -1))
Exemplo n.º 4
0
 def test_slice_and_cmp(self):
     self.assertEqual(self.l[1:3], "bc")
     self.assertGreater(self.l[1:3], "ab")
     self.assertGreater(self.l[2:5], orange.StringList("ab"))
     self.assertGreater(self.l[2:5], orange.StringList())
     with self.assertRaises(TypeError):
         self.assertGreater(self.l[2:5], orange.IntList([1, 2]))
Exemplo n.º 5
0
 def test_sort(self):
     import random
     r = [random.randint(1, 100) for i in range(20)]
     l = orange.IntList(r)
     l.sort()
     r.sort()
     self.assertEqual(l, r)
Exemplo n.º 6
0
 def test_reverse(self):
     self.l.reverse()
     self.assertEqual(self.l, range(9, -1, -1))
     empty = orange.IntList()
     empty.reverse()
     self.assertEqual(empty, [])
     self.assertFalse(empty)
Exemplo n.º 7
0
 def test_pop(self):
     self.assertEqual(self.l.pop(), 9)
     self.assertEqual(self.l, range(9))
     self.l.pop(1)
     self.assertEqual(self.l, [0, 2, 3, 4, 5, 6, 7, 8])
     self.l.pop(0)
     self.assertEqual(self.l, [2, 3, 4, 5, 6, 7, 8])
     l = orange.IntList([1])
     self.assertEqual(l.pop(), 1)
     self.assertFalse(l)
     with self.assertRaises(IndexError):
         l.pop()
Exemplo n.º 8
0
 def test_repeat(self):
     self.assertEqual(self.l * 3, list(range(10)) * 3)
     self.assertEqual(orange.IntList([]) * 3, [])
Exemplo n.º 9
0
 def test_empty(self):
     l = orange.IntList()
     self.assertEqual(len(l), 0)
     l = orange.IntList([])
     self.assertEqual(len(l), 0)
Exemplo n.º 10
0
 def setUp(self):
     self.l = orange.IntList(range(10))