コード例 #1
0
        public void HexaTest()
        {
            long        lHexa;
            List <long> llHexas = new List <long>(2000);

            Assert.AreEqual(1, PolygonalSieve.GetHexagonal(1));
            Assert.AreEqual(6, PolygonalSieve.GetHexagonal(2));
            Assert.AreEqual(15, PolygonalSieve.GetHexagonal(3));
            Assert.AreEqual(28, PolygonalSieve.GetHexagonal(4));
            Assert.AreEqual(45, PolygonalSieve.GetHexagonal(5));
            for (int i = 1; i < 2000; i++)
            {
                lHexa = PolygonalSieve.GetHexagonal(i);
                Assert.AreEqual(lHexa, PolygonalSieve.GetPoly(i, 6));
                Assert.AreEqual(i, PolygonalSieve.GetHexagonalIndex(lHexa));
                Assert.AreEqual(i, PolygonalSieve.GetPolyIndex(lHexa, 6));
                llHexas.Add(lHexa);
            }
            for (int i = 1; i < 2000; i++)
            {
                Assert.AreEqual(llHexas.Contains(i), PolygonalSieve.IsHexagonal(i));
            }
        }
コード例 #2
0
        public void HeptaTest()
        {
            long        lHepta;
            List <long> llHeptas = new List <long>(2000);

            Assert.AreEqual(1, PolygonalSieve.GetHeptagonal(1));
            Assert.AreEqual(7, PolygonalSieve.GetHeptagonal(2));
            Assert.AreEqual(18, PolygonalSieve.GetHeptagonal(3));
            Assert.AreEqual(34, PolygonalSieve.GetHeptagonal(4));
            Assert.AreEqual(55, PolygonalSieve.GetHeptagonal(5));
            for (int i = 1; i < 2000; i++)
            {
                lHepta = PolygonalSieve.GetHeptagonal(i);
                Assert.AreEqual(lHepta, PolygonalSieve.GetPoly(i, 7));
                Assert.AreEqual(i, PolygonalSieve.GetHeptagonalIndex(lHepta));
                Assert.AreEqual(i, PolygonalSieve.GetPolyIndex(lHepta, 7));
                llHeptas.Add(lHepta);
            }
            for (int i = 1; i < 2000; i++)
            {
                Assert.AreEqual(llHeptas.Contains(i), PolygonalSieve.IsHeptagonal(i));
                Assert.AreEqual(llHeptas.Contains(i), PolygonalSieve.IsPoly(i, 7));
            }
        }