예제 #1
0
        public void Test1()
        {
            var counter = 0;
            var fib     = YCombinator <int> .Fix(f => x =>
            {
                counter++;
                return(x < 2 ? 1 : f(x - 1) + f(x - 2));
            });

            counter = 0;
            fib(7);
            Assert.Equal(41, counter);

            counter = 0;
            fib(7);
            Assert.Equal(41, counter);
        }
예제 #2
0
        public void Test2()
        {
            var counter = 0;
            var fib     = YCombinator <int> .Fix(f => x =>
            {
                counter++;
                return(x < 2 ? 1 : f(x - 1) + f(x - 2));
            });

            var m_fib = Memoization.Create(fib);

            counter = 0;
            m_fib(7);
            Assert.Equal(41, counter);

            counter = 0;
            m_fib(7);
            Assert.Equal(0, counter);
        }