public void DoesLazyReturnsTheSameObjectAsAfterEvaluationTest()
        {
            var justEvaluatedMatrix    = lazyGiantMatrix.Get();
            var alreadyEvaluatedMatrix = lazyGiantMatrix.Get();

            Assert.AreSame(justEvaluatedMatrix, alreadyEvaluatedMatrix);
        }
示例#2
0
        public void GetOnlyOnce()
        {
            int number = 1;

            lazy = LazyFactory <int> .CreateMultiLazy(() => ++ number);

            Assert.AreEqual(2, lazy.Get());
            Assert.AreEqual(2, lazy.Get());
        }
示例#3
0
        public void GetShouldNotChangeValue <T>(ILazy <T> lazy)
        {
            var value = lazy.Get();

            Assert.AreEqual(value, 1);
            for (int i = 0; i < 50; i++)
            {
                Assert.AreEqual(value, lazy.Get());
            }
        }
        public void DoesConcurrentLazyReturnTheSameObjectInMultithreadedScenarioTest()
        {
            var threadCount = 20;
            var threads     = new Thread[threadCount];
            var matrices    = new GiantMatrix[threadCount];

            countdownEvent = new CountdownEvent(threadCount);
            for (var i = 0; i < threads.Length; ++i)
            {
                var threadNumber = i;
                threads[i] = new Thread(() =>
                {
                    resetEvent.WaitOne();
                    matrices[threadNumber] = lazyGiantMatrix.Get();
                    countdownEvent.Signal();
                });
            }

            foreach (var thread in threads)
            {
                thread.Start();
            }
            resetEvent.Set();
            countdownEvent.Wait();

            AreAllTheSameObject(matrices);
        }
示例#5
0
        public void GetOnlyOnceInManyThreads()
        {
            int number = 1;

            lazy = LazyFactory <int> .CreateMultiLazy(() => ++ number);

            threads = new Thread[10];
            for (int i = 0; i < 10; i++)
            {
                threads[i] = new Thread(() =>
                {
                    Assert.AreEqual(2, lazy.Get());
                    Assert.AreEqual(2, lazy.Get());
                    Assert.AreEqual(2, lazy.Get());
                });
            }
        }
示例#6
0
        public void GetTest()
        {
            int number = 1;

            lazy = LazyFactory <int> .CreateLazy(() => ++ number);

            Assert.AreEqual(2, lazy.Get());
        }
示例#7
0
            public void MultipleGetTest()
            {
                const int GetAmount = 20;
                var       count     = 0;

                testLazy = LazyFactory.CreateThreadSafeLazy <T>(() => {
                    ++count;
                    return(supplier());
                });

                for (var i = 0; i < GetAmount; ++i)
                {
                    Assert.AreEqual(expectedValue, testLazy.Get());
                }

                Assert.AreEqual(1, count);
            }
示例#8
0
 public void SingleGetTest()
 {
     testLazy = LazyFactory.CreateThreadSafeLazy <T>(supplier);
     Assert.AreEqual(expectedValue, testLazy.Get());
 }
示例#9
0
 public void ReturnsCorrectValue()
 => Assert.AreEqual(1, lazy.Get());