public void DoesLazyReturnsTheSameObjectAsAfterEvaluationTest() { var justEvaluatedMatrix = lazyGiantMatrix.Get(); var alreadyEvaluatedMatrix = lazyGiantMatrix.Get(); Assert.AreSame(justEvaluatedMatrix, alreadyEvaluatedMatrix); }
public void GetOnlyOnce() { int number = 1; lazy = LazyFactory <int> .CreateMultiLazy(() => ++ number); Assert.AreEqual(2, lazy.Get()); Assert.AreEqual(2, lazy.Get()); }
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); }
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()); }); } }
public void GetTest() { int number = 1; lazy = LazyFactory <int> .CreateLazy(() => ++ number); Assert.AreEqual(2, lazy.Get()); }
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); }
public void SingleGetTest() { testLazy = LazyFactory.CreateThreadSafeLazy <T>(supplier); Assert.AreEqual(expectedValue, testLazy.Get()); }
public void ReturnsCorrectValue() => Assert.AreEqual(1, lazy.Get());