예제 #1
0
        public void MemoizeLast()
        {
            var calls = 0;
            var f     = Memoization.MemoizeLast(delegate(int i) { calls++; return(i * 2); });

            Assert.Equal(4, f(2));
            Assert.Equal(1, calls);
            Assert.Equal(4, f(2));
            Assert.Equal(1, calls);
            Assert.Equal(8, f(4));
            Assert.Equal(2, calls);
        }
예제 #2
0
        public void MemoizeLastWithCustomComparer()
        {
            var calls    = 0;
            var comparer = StringComparer.OrdinalIgnoreCase;
            var f        = Memoization.MemoizeLast(delegate(string s) { calls++; return(s.ToUpperInvariant()); }, comparer);

            Assert.Equal("FOOBAR", f("foobar"));
            Assert.Equal(1, calls);
            Assert.Equal("FOOBAR", f("FOOBAR"));
            Assert.Equal(1, calls);
            Assert.Equal("FOOBAR", f("FoObAr"));
            Assert.Equal(1, calls);
        }
예제 #3
0
        public void MemoizeLastWithNullInputComparer()
        {
            var f = Memoization.MemoizeLast <object, object>(_ => null, null);

            Assert.Null(f(new object()));
        }
예제 #4
0
        public void MemoizeLastThrowsWithNullFunction()
        {
            var e = Assert.Throws <ArgumentNullException>(() => Memoization.MemoizeLast <object, object>(null));

            Assert.Equal("function", e.ParamName);
        }