예제 #1
0
 public void TestPrimes(PrimeSieve pg)
 {
     Assert.AreEqual(2, pg.getPrime(0));
     Assert.AreEqual(3, pg.getPrime(1));
     Assert.AreEqual(5, pg.getPrime(2));
     Assert.AreEqual(7, pg.getPrime(3));
     Assert.AreEqual(11, pg.getPrime(4));
     Assert.AreEqual(997, pg.getPrime(167));
     Assert.IsTrue(pg.IsPrime(2));
     Assert.IsTrue(pg.IsPrime(3));
     Assert.IsTrue(pg.IsPrime(5));
     Assert.IsTrue(pg.IsPrime(7));
     Assert.IsTrue(pg.IsPrime(2));
     Assert.IsFalse(pg.IsPrime(998));
     Assert.IsFalse(pg.IsPrime(30));
     Assert.IsFalse(pg.IsPrime(9));
     Assert.IsFalse(pg.IsPrime(8));
     Assert.IsFalse(pg.IsPrime(6));
     Assert.IsFalse(pg.IsPrime(4));
     Assert.IsTrue(pg.IsPrime(pg.getPrime(pg.Count() - 1)));
     Assert.IsTrue(pg.IsPrime(pg.getPrime(pg.Count() - 2)));
     Assert.IsTrue(pg.IsPrime(pg.getPrime(pg.Count() - 90)));
     Assert.IsFalse(pg.IsPrime(pg.getPrime(pg.Count() - 1) - 1));
     Assert.IsFalse(pg.IsPrime(pg.getPrime(pg.Count() - 2) - 1));
     Assert.IsFalse(pg.IsPrime(pg.getPrime(pg.Count() - 90) - 1));
     try {
         pg.getPrime(pg.Count());
         Assert.Fail();
     } catch (IndexOutOfRangeException) {
     }
 }