Exemplo n.º 1
0
 public void Generate()
 {
     CollectionAssert.AreEqual(Enumerable.Empty <int>(), PrimeFactors.Generate(1));
     CollectionAssert.AreEqual(new List <int> {
         2
     }, PrimeFactors.Generate(2));
     CollectionAssert.AreEqual(new List <int> {
         3
     }, PrimeFactors.Generate(3));
     CollectionAssert.AreEqual(new List <int> {
         2, 2
     }, PrimeFactors.Generate(4));
     CollectionAssert.AreEqual(new List <int> {
         5
     }, PrimeFactors.Generate(5));
     CollectionAssert.AreEqual(new List <int> {
         2, 3
     }, PrimeFactors.Generate(6));
     CollectionAssert.AreEqual(new List <int> {
         7
     }, PrimeFactors.Generate(7));
     CollectionAssert.AreEqual(new List <int> {
         2, 2, 2
     }, PrimeFactors.Generate(8));
     CollectionAssert.AreEqual(new List <int> {
         3, 3
     }, PrimeFactors.Generate(9));
     CollectionAssert.AreEqual(new List <int> {
         2, 2, 3, 5, 7, 11
     }, PrimeFactors.Generate(4620));
 }
Exemplo n.º 2
0
        public void ShouldReturn(int x, params int[] expectedFactors)
        {
            List <int> primeFactors  = PrimeFactors.Calculate(x);
            List <int> expectedValue = expectedFactors.ToList();

            Assert.That(primeFactors, Is.EqualTo(expectedValue));
        }
Exemplo n.º 3
0
        public void TestPrimeFactorsOutLists()
        {
            try
            {
                PrimeFactors     pF   = new PrimeFactors();
                LinkedList <int> list = new LinkedList <int>();
                list.AddLast(228);
                list.AddLast(189);
                list.AddLast(300);
                list.AddLast(39847);

                var output = pF.PrimeFactorsOut(list);

                if (output.Length > 1)
                {
                    Assert.True(true);
                }
                else
                {
                    Assert.True(false);
                }
            }
            catch (Exception e)
            {
                Assert.True(false);
            }
        }
Exemplo n.º 4
0
        public void PrimeFactors_1_Retursn_1(int number, int[] expectedFactors)
        {
            var primeFactors = new PrimeFactors();
            var factors = primeFactors.Get(number);

            Assert.IsTrue(expectedFactors.SequenceEqual(factors));
        }
Exemplo n.º 5
0
    public void Example()
    {
        int expected = 6 * 9;
        int actual   = new PrimeFactors().Answer;

        Assert.AreEqual(expected, actual);
    }
Exemplo n.º 6
0
        public PrimeFactorsModule()
        {
            Get["/primeFactors"] = parameters =>
            {
                var primeFactors    = new PrimeFactors();
                var numberParameter = Request.Query.number;

                if (!numberParameter.HasValue)
                {
                    return(BuildJsonResponse(new { error = "number parameter is not present in the querystring" }));
                }

                string [] numbers = numberParameter.ToString().Split(',');

                if (numbers.Length > 1)
                {
                    var dynamicArray = numbers.Select(number => ProcessNumber(primeFactors, number)).ToList();
                    return(BuildJsonResponse(dynamicArray));
                }

                return(BuildJsonResponse(ProcessNumber(primeFactors, numberParameter)));
            };

            Get["/primeFactors/ui"] = _ => View["Index"];
        }
 public void PrimeFactors_of_2_are_2()
 {
     Assert.Equal(new List <int>()
     {
         2
     }, PrimeFactors.Of(2));
 }
        public void PrimeFactors_ReceivesBigNumber_PrimeFactorizationIsCorrect()
        {
            var primeFactors = PrimeFactors.Generate(4569878);

            CollectionAssert.AreEqual(primeFactors, new List <int> {
                2, 29, 78791
            });
        }
        public void PrimeFactors_ReceivesTen_ReturnsTwoFive()
        {
            var primeFactors = PrimeFactors.Generate(10);

            CollectionAssert.AreEqual(primeFactors, new List <int> {
                2, 5
            });
        }
        public void PrimeFactors_ReceivesNine_ReturnsThreeThree()
        {
            var primeFactors = PrimeFactors.Generate(9);

            CollectionAssert.AreEqual(primeFactors, new List <int> {
                3, 3
            });
        }
        public void PrimeFactors_ReceivesEight_ReturnsTwoTwoTwo()
        {
            var primeFactors = PrimeFactors.Generate(8);

            CollectionAssert.AreEqual(primeFactors, new List <int> {
                2, 2, 2
            });
        }
        public void PrimeFactors_ReceivesSix_ReturnsTwoThree()
        {
            var primeFactors = PrimeFactors.Generate(6);

            CollectionAssert.AreEqual(primeFactors, new List <int> {
                2, 3
            });
        }
        public void PrimeFactors_ReceivesAnotherBigNumber_PrimeFactorizationIsCorrect()
        {
            var primeFactors = PrimeFactors.Generate(793800);

            CollectionAssert.AreEqual(primeFactors, new List <int> {
                2, 2, 2, 3, 3, 3, 3, 5, 5, 7, 7
            });
        }
Exemplo n.º 14
0
        public void CheckPrimeReturnsFalseWhenInputIs6()
        {
            PrimeFactors primeFactors = new PrimeFactors();

            var actual = primeFactors.isPrime(4);

            Assert.IsFalse(actual);
        }
Exemplo n.º 15
0
        public void CheckPrimeReturnsTrueWhenInputIs2()
        {
            PrimeFactors primeFactors = new PrimeFactors();
            var          expected     = true;
            var          actual       = primeFactors.isPrime(2);

            Assert.AreEqual(expected, actual);
        }
        public void It_generates_prime_factors(int input, List <int> output)
        {
            var factors = new PrimeFactors();

            var excepted = factors.Generate(input);

            Assert.Equal(excepted, output);
        }
Exemplo n.º 17
0
 public void Test4()
 {
     PrimeFactors pf = new PrimeFactors(4, primes);
     int prime = pf[0][0];
     int multiplicity = pf[0][1];
     Assert.AreEqual(prime, 2);
     Assert.AreEqual(multiplicity, 2);
 }
Exemplo n.º 18
0
        static void Answer6()
        {
            long Largesta    = 600851475143;
            long PrimeResult = PrimeFactors.LargestPrimeFactor(Largesta);

            Console.Out.WriteLine("Largest Prime Factor = {0}", PrimeResult);
            Console.ReadLine();
        }
Exemplo n.º 19
0
        public void Test50()
        {
            int          number         = 50;
            string       expectedResult = "5 x 5 x 2";
            PrimeFactors pf             = new PrimeFactors();
            string       actualResult   = pf.GetPrimeFactors(number);

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 20
0
        public void PrimeFactorsReturns3WhenInputIs3()
        {
            PrimeFactors primeFactors = new PrimeFactors();
            List <int>   expectedList = new List <int>();
            var          expected     = 3;
            var          actual       = primeFactors.GeneratePrimeFactors(3)[0];

            Assert.AreEqual(actual, expected);
        }
        public void TestGenerateDoesNotReturn0ForNumberGreaterThan2()
        {
            var factors = PrimeFactors.Generate(6);

            Assert.AreEqual(2, factors.Count);
            CollectionAssert.AreEqual(new List <int> {
                2, 3
            }, factors);
        }
Exemplo n.º 22
0
        public void Test17()
        {
            int          number         = 17;
            string       expectedResult = "17";
            PrimeFactors pf             = new PrimeFactors();
            string       actualResult   = pf.GetPrimeFactors(number);

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 23
0
        public void Test1()
        {
            // arrange
            string expected = "Prime factors of 4 are: 2 x 2";
            // act
            PrimeFactors a = new PrimeFactors(4);

            // assert
            Assert.Equal(expected, a.Print());
        }
Exemplo n.º 24
0
        public void Test5()
        {
            // arrange
            string expected = "Prime factors of 50 are: 5 x 5 x 2";
            // act
            PrimeFactors a = new PrimeFactors(50);

            // assert
            Assert.Equal(expected, a.Print());
        }
Exemplo n.º 25
0
        public void Test2()
        {
            // arrange
            string expected = "Prime factors of 7 are: 7";                  // act
            // act
            PrimeFactors a = new PrimeFactors(7);

            // assert
            Assert.Equal(expected, a.Print());
        }
Exemplo n.º 26
0
        public void PrimeFactorsReturnsListOfIntegers()
        {
            PrimeFactors primeFactors = new PrimeFactors();
            List <int>   expectedList = new List <int>();

            expectedList.Add(5);
            var actual = primeFactors.GeneratePrimeFactors(11);

            Assert.IsTrue(actual.GetType() == expectedList.GetType(), "an integer is not returned");
        }
Exemplo n.º 27
0
        public void SolveReturns11and3WhenInputIs297()
        {
            PrimeFactors primeFactors = new PrimeFactors();
            var          expectedList = new List <int> {
                3, 11
            };

            var actual = primeFactors.GeneratePrimeFactors(297);

            Assert.IsTrue(expectedList.All(actual.Contains) && expectedList.Count == actual.Count);
        }
Exemplo n.º 28
0
        public void BeCorrect_WhenGettingPrimeFactorsOfNumber(int[] expected, int number)
        {
            // Arrange
            var sut = new PrimeFactors();

            // Act
            var result = sut.PrimeFactorsOf(number);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 29
0
        public void Get_Factorize_for_2()
        {
            // arrange
            int    number   = 2;
            string expected = "2";

            // act
            string result = PrimeFactors.Get(number);

            Assert.Equal(expected, result);
        }
Exemplo n.º 30
0
        public void GetAllFactorsReturns2and3and6and9WhenInputIs18()
        {
            PrimeFactors primeFactors = new PrimeFactors();
            var          expectedList = new List <int> {
                9, 6, 3, 2
            };

            var actual = primeFactors.GetAllFactors(18);

            Assert.IsTrue(expectedList.All(actual.Contains) && expectedList.Count == actual.Count);
        }
Exemplo n.º 31
0
        public void Get_Factorize_for_1()
        {
            // arrange
            int    number   = 1;
            string expected = "The number is too small!";

            // act
            string result = PrimeFactors.Get(number);

            Assert.Equal(expected, result);
        }
Exemplo n.º 32
0
        static void Main(string[] args)
        {
            WriteLine("Enter the number whose multiplier you need to get: ");
            int x = PrimeFactors.PrimeValue(Convert.ToInt32(ReadLine()));

            if (x < 2)
            {
                Write("Prime number cannot be less then 2");
            }
            Write(".");
        }
Exemplo n.º 33
0
 public void Test6()
 {
     PrimeFactors pf = new PrimeFactors(6, primes);
     int prime = pf[0][0];
     int multiplicity = pf[0][1];
     Assert.AreEqual(prime, 2);
     Assert.AreEqual(multiplicity, 1);
     prime = pf[1][0];
     multiplicity = pf[1][1];
     Assert.AreEqual(prime, 3);
     Assert.AreEqual(multiplicity, 1);
 }
Exemplo n.º 34
0
        public void SimpleNumberGeneratePrimeFactorsTest()
        {
            int number = 4;
            PrimeFactors target = new PrimeFactors(number);

            List<int> expected = new List<int>();
            expected.Add(1); expected.Add(2); expected.Add(3);

            List<int> actual= target.GeneratePrimeFactors();
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
        }
 public void SetUp()
 {
     primeFactors = new PrimeFactors();
 }
Exemplo n.º 36
0
 public void Clean()
 {
     this.primeFactors = null;
 }
Exemplo n.º 37
0
 public void Setup()
 {
     this.primeFactors = new PrimeFactors();
 }
Exemplo n.º 38
0
 public void Example()
 {
     int expected = 6 * 9;
     int actual = new PrimeFactors().Answer;
     Assert.AreEqual(expected, actual);
 }