public void HybridTableOptimizationHandsOffAllValuesToDictionary(int count)
        {
            KeyedMemoizer<int?, int> memoizer = new KeyedMemoizer<int?, int>();
            for (int i = 0; i < count; i++)
                Assert.AreEqual(i, memoizer.Memoize(i, () => i));

            for (int i = 0; i < count; i++)
                Assert.AreEqual(i, memoizer.Memoize(i, () => { throw new InvalidOperationException("Should not happen."); }));
        }
Example #2
0
        public void HybridTableOptimizationHandsOffAllValuesToDictionary(int count)
        {
            KeyedMemoizer <int?, int> memoizer = new KeyedMemoizer <int?, int>();

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, memoizer.Memoize(i, () => i));
            }

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, memoizer.Memoize(i, () => { throw new InvalidOperationException("Should not happen."); }));
            }
        }
        public void WhenValueNotPresentPopulatesAndMemoizesItByKey(int initialSize)
        {
            KeyedMemoizer<string, int> memoizer = new KeyedMemoizer<string, int>();

            for (int i = 0; i < initialSize; i++)
                Assert.AreEqual(i, memoizer.Memoize(i + "x", () => i));

            Assert.AreEqual(42, memoizer.Memoize("42", () => 42));
            Assert.AreEqual(42, memoizer.Memoize("42", () => { throw new InvalidOperationException("Should not be called"); }));

            Assert.AreEqual(31, memoizer.Memoize("31", () => 31));
            Assert.AreEqual(31, memoizer.Memoize("31", () => { throw new InvalidOperationException("Should not be called"); }));

            Assert.AreEqual(-1, memoizer.Memoize(null, () => -1));

            Assert.AreEqual(42, memoizer.Memoize("42", () => { throw new InvalidOperationException("Should not be called"); }));
            Assert.AreEqual(-1, memoizer.Memoize(null, () => { throw new InvalidOperationException("Should not be called"); }));
            Assert.AreEqual(31, memoizer.Memoize("31", () => { throw new InvalidOperationException("Should not be called"); }));
        }
Example #4
0
        public void WhenValueNotPresentPopulatesAndMemoizesItByKey(int initialSize)
        {
            KeyedMemoizer <string, int> memoizer = new KeyedMemoizer <string, int>();

            for (int i = 0; i < initialSize; i++)
            {
                Assert.AreEqual(i, memoizer.Memoize(i + "x", () => i));
            }

            Assert.AreEqual(42, memoizer.Memoize("42", () => 42));
            Assert.AreEqual(42, memoizer.Memoize("42", () => { throw new InvalidOperationException("Should not be called"); }));

            Assert.AreEqual(31, memoizer.Memoize("31", () => 31));
            Assert.AreEqual(31, memoizer.Memoize("31", () => { throw new InvalidOperationException("Should not be called"); }));

            Assert.AreEqual(-1, memoizer.Memoize(null, () => - 1));

            Assert.AreEqual(42, memoizer.Memoize("42", () => { throw new InvalidOperationException("Should not be called"); }));
            Assert.AreEqual(-1, memoizer.Memoize(null, () => { throw new InvalidOperationException("Should not be called"); }));
            Assert.AreEqual(31, memoizer.Memoize("31", () => { throw new InvalidOperationException("Should not be called"); }));
        }
 public CachingTestCaseFactory(ITestCaseFactory testCaseFactory, TestProperty testIdProperty)
 {
     this.testCaseFactory = testCaseFactory;
     this.testIdProperty  = testIdProperty;
     testCases            = new KeyedMemoizer <string, TestCase>();
 }
 public CachingTestCaseFactory(ITestCaseFactory testCaseFactory, TestProperty testIdProperty)
 {
     this.testCaseFactory = testCaseFactory;
     this.testIdProperty = testIdProperty;
     testCases = new KeyedMemoizer<string, TestCase>();
 }