Ejemplo n.º 1
0
        public void Factor_31()
        {
            IntegerFactorizer factorizer = new IntegerFactorizer();

            IList<long> factors = factorizer.Factor(31);

            Assert.That(factors.Count, Is.EqualTo(1));
            Assert.That(factors[0], Is.EqualTo(31));
        }
Ejemplo n.º 2
0
        public void Factor_27()
        {
            IntegerFactorizer factorizer = new IntegerFactorizer();

            IList<long> factors = factorizer.Factor(27);

            Assert.That(factors.Count, Is.EqualTo(3));
            Assert.That(factors[0], Is.EqualTo(3));
            Assert.That(factors[1], Is.EqualTo(3));
            Assert.That(factors[2], Is.EqualTo(3));
        }
Ejemplo n.º 3
0
        public void Factor_Huge_Number()
        {
            IntegerFactorizer factorizer = new IntegerFactorizer();

            Random random = new Random();

            long value = (long) (random.NextDouble()*10000000000000);

            IList<long> factors = factorizer.Factor(value);

            Assert.That(factors.Count, Is.GreaterThan(0));

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Factoring {0} into ", value);

            foreach (long factor in factors)
            {
                sb.AppendFormat("{0:f0} ", factor);
            }

            Debug.WriteLine(sb.ToString());
        }