Esempio n. 1
0
 def test_one_empty(self):
     e = loglinear.revorder([])
     f = loglinear.revorder([3, 2, 1])
     r = loglinear.jointrevorder(e, f)
     self.assertEqual([3, 2, 1], list(r))
     r = loglinear.jointrevorder(f, e)
     self.assertEqual([3, 2, 1], list(r))
Esempio n. 2
0
	def test_one_empty(self):
		e = loglinear.revorder([])
		f = loglinear.revorder([3, 2, 1])
		r = loglinear.jointrevorder(e, f)
		self.assertEqual([3, 2, 1], list(r))
		r = loglinear.jointrevorder(f, e)
		self.assertEqual([3, 2, 1], list(r))
Esempio n. 3
0
	def test_backing_iterators(self):
		a_yielded = []
		b_yielded = []
		def record(x, yielded):
			yielded.append(x)
			return x
		def a_gen():
			yield record(4, a_yielded)
			yield record(3, a_yielded)
			yield record(1, a_yielded)
		def b_gen():
			yield record(2, b_yielded)
			yield record(0, b_yielded)
		a = loglinear.revorder(a_gen())
		b = loglinear.revorder(b_gen())
		r = loglinear.jointrevorder(a, b)
		i = iter(r)
		self.assertEqual([], a_yielded)
		self.assertEqual([], b_yielded)
		self.assertEqual(4, i.next())
		self.assertEqual([4], a_yielded)
		self.assertEqual([2], b_yielded)
		self.assertEqual(3, i.next())
		self.assertEqual([4, 3], a_yielded)
		self.assertEqual([2], b_yielded)
		self.assertEqual(2, i.next())
		self.assertEqual([4, 3, 1], a_yielded)
		self.assertEqual([2], b_yielded)
		self.assertEqual(1, i.next())
		self.assertEqual([4, 3, 1], a_yielded)
		self.assertEqual([2, 0], b_yielded)
		self.assertEqual(0, i.next())
Esempio n. 4
0
    def test_backing_iterators(self):
        a_yielded = []
        b_yielded = []

        def record(x, yielded):
            yielded.append(x)
            return x

        def a_gen():
            yield record(4, a_yielded)
            yield record(3, a_yielded)
            yield record(1, a_yielded)

        def b_gen():
            yield record(2, b_yielded)
            yield record(0, b_yielded)

        a = loglinear.revorder(a_gen())
        b = loglinear.revorder(b_gen())
        r = loglinear.jointrevorder(a, b)
        i = iter(r)
        self.assertEqual([], a_yielded)
        self.assertEqual([], b_yielded)
        self.assertEqual(4, i.next())
        self.assertEqual([4], a_yielded)
        self.assertEqual([2], b_yielded)
        self.assertEqual(3, i.next())
        self.assertEqual([4, 3], a_yielded)
        self.assertEqual([2], b_yielded)
        self.assertEqual(2, i.next())
        self.assertEqual([4, 3, 1], a_yielded)
        self.assertEqual([2], b_yielded)
        self.assertEqual(1, i.next())
        self.assertEqual([4, 3, 1], a_yielded)
        self.assertEqual([2, 0], b_yielded)
        self.assertEqual(0, i.next())
Esempio n. 5
0
	def test_interleave(self):
		a = loglinear.revorder([7, 5, 3, 2])
		b = loglinear.revorder([9, 8, 6, 4, 1])
		r = loglinear.jointrevorder(a, b)
		self.assertEqual([9, 8, 7, 6, 5, 4, 3, 2, 1], list(r))
Esempio n. 6
0
	def test_both_empty(self):
		r = loglinear.jointrevorder(loglinear.revorder([]), 
			loglinear.revorder([]))
		self.assertEqual([], list(r))
Esempio n. 7
0
	def test_aliassing(self):
		a = loglinear.revorder([3, 2, 1])
		r = loglinear.jointrevorder(a, a)
		self.assertEqual([3, 2, 1], list(r))
Esempio n. 8
0
	def test_no_doubles(self):
		a = loglinear.revorder([3, 2])
		b = loglinear.revorder([2, 1])
		r = loglinear.jointrevorder(a, b)
		self.assertEqual([3, 2, 1], list(r))
Esempio n. 9
0
 def test_both_empty(self):
     r = loglinear.jointrevorder(loglinear.revorder([]),
                                 loglinear.revorder([]))
     self.assertEqual([], list(r))
Esempio n. 10
0
 def test_aliassing(self):
     a = loglinear.revorder([3, 2, 1])
     r = loglinear.jointrevorder(a, a)
     self.assertEqual([3, 2, 1], list(r))
Esempio n. 11
0
 def test_no_doubles(self):
     a = loglinear.revorder([3, 2])
     b = loglinear.revorder([2, 1])
     r = loglinear.jointrevorder(a, b)
     self.assertEqual([3, 2, 1], list(r))
Esempio n. 12
0
 def test_interleave(self):
     a = loglinear.revorder([7, 5, 3, 2])
     b = loglinear.revorder([9, 8, 6, 4, 1])
     r = loglinear.jointrevorder(a, b)
     self.assertEqual([9, 8, 7, 6, 5, 4, 3, 2, 1], list(r))