コード例 #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);
        }