public void H_Safe_LocalImplementation()
        {
            // Here we guarantee thread safety by not using any instance properties in the implementation.
            // This is not always possible, and care must still be taken not to add them in the future.
            var results = new ConcurrentBag <int>();
            var opt     = new ParallelOptions {
                MaxDegreeOfParallelism = Iterations
            };

            ITwoPlusTwo implementation = new LocalTwoPlusTwo();

            Parallel.For(0, Iterations, opt, i =>
            {
                var result = implementation.CalculateTwoPlusTwo();
                results.Add(result);
            });

            Assert.IsEmpty(results.Where(r => r != RightAnswer));
        }
        public void A_SanityCheck()
        {
            ITwoPlusTwo implementation = new StaticTwoPlusTwo();
            var         result         = implementation.CalculateTwoPlusTwo();

            Assert.AreEqual(RightAnswer, result);

            implementation = SingletonTwoPlusTwo.Instance;
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);

            implementation = new InstanceTwoPlusTwo();
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);

            implementation = new ThreadSafeInstanceTwoPlusTwo();
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);

            implementation = new LocalTwoPlusTwo();
            result         = implementation.CalculateTwoPlusTwo();
            Assert.AreEqual(RightAnswer, result);
        }