def test_CLLN_03(self): # len x = CLLN(1) self.assertEqual(1, len(x)) x = x.after(2).before(3).after(4).before(5) self.check(x) self.assertEqual(5, len(x))
def test_CLLN_07(self): # map big; should be efficient enough not to be recursion depth limited x = CLLN(0) for i in range(1, 2000): x.after(i) self.check(x) y = x.map(lambda v: v * v) self.assertEqual(2000, len(y)) self.assertEqual(2664667000, sum([nd.val for nd in y.nodes()]))
def test_CLLN_06(self): # reversed x = CLLN(1).after(2).after(3).after(4).next self.assertEqual("<CLLN 1 2 3 4>", repr(x)) y = x.reversed() self.check(x) self.check(y) self.assertEqual("<CLLN 4 3 2 1>", repr(y)) self.assertEqual([4, 3, 2, 1], list(y)) # y reversed self.assertEqual([1, 2, 3, 4], list(x)) # should not change x
def test_CLLN_01(self): # after (two nodes) x = CLLN(1) y = x.after(2) self.assertEqual(1, x.val) self.assertEqual(2, y.val) self.assertEqual("<CLLN 1 2>", repr(x)) self.assertEqual("<CLLN 2 1>", repr(y)) self.assertEqual(2, len(x)) self.assertEqual(2, len(y)) self.check(x) self.check(y)
def test_CLLN_08(self): # reversed big; dhould be efficient enough not to be recursion depth limited size = 2000 x = CLLN(0) for i in range(2, size * 2, 2): x = x.after(i) x = x.next self.check(x) y = x.reversed() self.check(y) self.check(x) self.assertEqual(list(range((size - 1) * 2, -2, -2)), list(y)) self.assertEqual(list(range(0, size * 2, 2)), list(x)) # x should not change
def test_CLLN_02(self): # after (three nodes) x = CLLN(1) y = x.after(2).after(3) self.assertEqual("<CLLN 1 2 3>", repr(x)) self.assertEqual("<CLLN 2 3 1>", repr(x.next)) self.assertEqual("<CLLN 3 1 2>", repr(y)) self.check(x) self.check(y) # before should also work z = x.before(4) self.check(x) self.check(z) self.assertEqual("<CLLN 1 2 3 4>", repr(x)) self.assertEqual("<CLLN 4 1 2 3>", repr(z))
def test_CLLN_05(self): # map a = CLLN(10) b = a.map(lambda v: v - 4) self.assertEqual("<CLLN 6>", repr(b)) self.assertEqual("<CLLN 10>", repr(a)) x = CLLN(1).after(2).after(3).after(4).next self.assertEqual("<CLLN 1 2 3 4>", repr(x)) xm = x.map(lambda v: v * v) self.assertEqual("<CLLN 1 4 9 16>", repr(xm)) self.assertEqual("<CLLN 1 2 3 4>", repr(x)) self.check(x) self.check(xm)
def test_CLLN_04(self): # remove x = CLLN(1).after(2).after(3).after(4).next y = x.next self.check(x) self.check(y) z = y.remove() self.assertEqual(str(z), str(y), msg="removed object incorrect") self.assertEqual(str(z.next), str(z), msg="removed object incorrect") self.assertEqual(str(z.prev), str(z), msg="removed object incorrect") self.assertEqual("<CLLN 2>", repr(y)) self.check(x) self.assertEqual("<CLLN 1 3 4>", repr(x)) y.remove() self.check(x) self.check(y) self.assertEqual("<CLLN 2>", repr(y)) self.assertEqual("<CLLN 1 3 4>", repr(x)) x.next.remove() self.check(x) self.check(y) self.assertEqual("<CLLN 1 4>", repr(x))