예제 #1
0
파일: tests.py 프로젝트: danielhfrank/fn.py
    def test_fib_infinite_stream(self):
        from operator import add 

        f = Stream()
        fib = f << [0, 1] << iters.map(add, f, iters.drop(1, f))

        self.assertEqual([0,1,1,2,3,5,8,13,21,34], list(iters.take(10, fib)))
        self.assertEqual(6765, fib[20])
        self.assertEqual([832040,1346269,2178309,3524578,5702887], fib[30:35])
예제 #2
0
파일: tests.py 프로젝트: Gizmo707/fn.py
    def test_fib_infinite_stream(self):
        from operator import add 

        f = Stream()
        fib = f << [0, 1] << iters.map(add, f, iters.drop(1, f))

        self.assertEqual([0,1,1,2,3,5,8,13,21,34], list(iters.take(10, fib)))
        self.assertEqual(6765, fib[20])
        self.assertEqual([832040,1346269,2178309,3524578,5702887], list(fib[30:35]))
        # 35 elements should be already evaluated
        self.assertEqual(fib.cursor(), 35)
예제 #3
0
    def test_fib_infinite_stream(self):
        from operator import add

        f = Stream()
        fib = f << [0, 1] << iters.map(add, f, iters.drop(1, f))

        self.assertEqual([0,1,1,2,3,5,8,13,21,34], list(iters.take(10, fib)))
        self.assertEqual(6765, fib[20])
        self.assertEqual([832040,1346269,2178309,3524578,5702887], list(fib[30:35]))
        # 35 elements should be already evaluated
        self.assertEqual(fib.cursor(), 35)
예제 #4
0
 def test_take(self):
     self.assertEqual([0, 1], list(iters.take(2, range(10))))
     self.assertEqual([0, 1], list(iters.take(10, range(2))))
예제 #5
0
파일: tests.py 프로젝트: Gizmo707/fn.py
 def test_unfold_infinite(self):
     doubler = op.unfold(lambda x: (x*2, x*2))
     self.assertEqual(20, next(doubler(10)))
     self.assertEqual([20, 40, 80, 160, 320], list(iters.take(5, doubler(10))))
예제 #6
0
파일: tests.py 프로젝트: Gizmo707/fn.py
 def test_take(self):
     self.assertEqual([0,1], list(iters.take(2, range(10))))
     self.assertEqual([0,1], list(iters.take(10, range(2))))
예제 #7
0
파일: tests.py 프로젝트: pawroman/fn.py
 def test_unfold_infinite(self):
     doubler = op.unfold(lambda x: (x * 2, x * 2))
     self.assertEqual(20, next(doubler(10)))
     self.assertEqual([20, 40, 80, 160, 320],
                      list(iters.take(5, doubler(10))))