コード例 #1
0
 private void TestDivisibilityChecker(ICheckDivisibilityBySeven divisibilityChecker)
 {
     for (uint i = 0; i <= MaxTestValue; ++i)
     {
         Assert.AreEqual(_modChecker.IsDivisibleBySeven(i), divisibilityChecker.IsDivisibleBySeven(i));
     }
 }
コード例 #2
0
 private long TimeTakenInMilliseconds(ICheckDivisibilityBySeven checker)
 {
     Stopwatch stopWatch = new Stopwatch();
     stopWatch.Start();
     for (uint i = 0; i <= TestValueCount; ++i)
     {
         checker.IsDivisibleBySeven(i);
     }
     stopWatch.Stop();
     return stopWatch.ElapsedMilliseconds;
 }
コード例 #3
0
        private void PerformanceTestBitShiftAlgorithm(ICheckDivisibilityBySeven standardChecker, double acceptableFactor)
        {
            // Code to prime the jitter.
            _bitShiftChecker.IsDivisibleBySeven(1337);
            standardChecker.IsDivisibleBySeven(1337);

            long bitShiftMilliseconds = TimeTakenInMilliseconds(_bitShiftChecker);
            long typicalMethodMilliseconds = TimeTakenInMilliseconds(standardChecker);

            var speedUpFactor = typicalMethodMilliseconds/(double) bitShiftMilliseconds;
            Assert.GreaterOrEqual(speedUpFactor, acceptableFactor);
        }
コード例 #4
0
        private long TimeTakenInMilliseconds(ICheckDivisibilityBySeven checker)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            for (uint i = 0; i <= TestValueCount; ++i)
            {
                checker.IsDivisibleBySeven(i);
            }
            stopWatch.Stop();
            return(stopWatch.ElapsedMilliseconds);
        }
コード例 #5
0
        private void PerformanceTestBitShiftAlgorithm(ICheckDivisibilityBySeven standardChecker, double acceptableFactor)
        {
            // Code to prime the jitter.
            _bitShiftChecker.IsDivisibleBySeven(1337);
            standardChecker.IsDivisibleBySeven(1337);

            long bitShiftMilliseconds      = TimeTakenInMilliseconds(_bitShiftChecker);
            long typicalMethodMilliseconds = TimeTakenInMilliseconds(standardChecker);

            var speedUpFactor = typicalMethodMilliseconds / (double)bitShiftMilliseconds;

            Assert.GreaterOrEqual(speedUpFactor, acceptableFactor);
        }
コード例 #6
0
 private void TestDivisibilityChecker(ICheckDivisibilityBySeven divisibilityChecker)
 {
     for (uint i = 0; i <= MaxTestValue; ++i)
         Assert.AreEqual(_modChecker.IsDivisibleBySeven(i), divisibilityChecker.IsDivisibleBySeven(i));
 }