Exemplo n.º 1
0
 public void GetAdjacentPrimeNumberLessThan_2()
 {
     for (var i = 2; i < 1000000; i++)
     {
         Aver.IsTrue(IntMath.IsPrime(IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(i)));
     }
 }
Exemplo n.º 2
0
            public bool growIfNeeded()         //must be called under write lock
            {
                var loadf   = LoadFactor;
                var options = Table.m_Options;

                if (loadf > options.LoadFactorHWM)
                {
                    var newCapacity = IntMath.GetCapacityFactoredToPrime(Entries.Length, options.GrowthFactor);
                    if (options.MaximumCapacity > 0)
                    {
                        var capacityPerBucket = (int)(options.MaximumCapacity / BUCKETS);
                        if (newCapacity > capacityPerBucket)
                        {
                            newCapacity = IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(capacityPerBucket);
                        }
                    }
                    if (resize(newCapacity))
                    {
                        Interlocked.Increment(ref Table.m_stat_Grew);
                        m_LastGrownTime = DateTime.UtcNow;
                        return(true);
                    }
                }
                return(false);
            }
Exemplo n.º 3
0
        public void GetAdjacentPrimeNumberLessThan_1()
        {
            Assert.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(-10));
            Assert.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(0));
            Assert.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1));
            Assert.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(2));
            Assert.AreEqual(3, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(3));

            Assert.AreEqual(3, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(4));
            Assert.AreEqual(5, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(5));
            Assert.AreEqual(5, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(6));
            Assert.AreEqual(7, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(7));

            Assert.AreEqual(107, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(108));
            Assert.AreEqual(107, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(108));
            Assert.AreEqual(109, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(109));

            Assert.AreEqual(631, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(633));

            Assert.AreEqual(2459, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(2465));

            Assert.AreEqual(1148747, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148747));
            Assert.AreEqual(1148747, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148748));
            Assert.AreEqual(1148747, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148752));
            Assert.AreEqual(1148753, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148753));

            Assert.AreEqual(15485857, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(15485862));
            Assert.AreEqual(15485863, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(15485863));
        }
Exemplo n.º 4
0
        public void GetAdjacentPrimeNumberLessThan_1()
        {
            Aver.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(-10));
            Aver.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(0));
            Aver.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1));
            Aver.AreEqual(2, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(2));
            Aver.AreEqual(3, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(3));

            Aver.AreEqual(3, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(4));
            Aver.AreEqual(5, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(5));
            Aver.AreEqual(5, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(6));
            Aver.AreEqual(7, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(7));

            Aver.AreEqual(107, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(107));
            Aver.AreEqual(107, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(108));
            Aver.AreEqual(109, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(109));
            Aver.AreEqual(109, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(110));
            Aver.AreEqual(109, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(111));
            Aver.AreEqual(109, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(112));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(113));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(114));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(115));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(116));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(117));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(118));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(119));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(120));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(121));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(122));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(123));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(124));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(125));
            Aver.AreEqual(113, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(126));
            Aver.AreEqual(127, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(127));


            Aver.AreEqual(631, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(633));

            Aver.AreEqual(2459, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(2465));

            Aver.AreEqual(1148747, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148747));
            Aver.AreEqual(1148747, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148748));
            Aver.AreEqual(1148747, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148752));
            Aver.AreEqual(1148753, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(1148753));

            Aver.AreEqual(15485857, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(15485862));
            Aver.AreEqual(15485863, IntMath.GetAdjacentPrimeNumberLessThanOrEqualTo(15485863));
        }