Hello mates!

I have one problem with Math Utility Test for PrimeNumber case.

The code is:

public bool IsPrimeNumber(int n)
            int i = 0, num = 0;
            while (i <= n)
                if ((n % i) == 0) num = num + 1;
                i = i + 1;

            if (num == 0)
                return true;
                return false;

But I'm not sure if its the correct code for prime numbers.
The test method should be what?:

        public void Test_IsPrimeNumber()
            bool result = this.IsPrimeNumber(?);
            Assert.AreEqual(?, result);

It needs to be Passed when you run Test in Solution.

Suggestions are welcome.


Edited 5 Years Ago by bisiii: /

Instead of a question mark, put a number.

1) Make a list of known primes and loop them through the test
2) Make a list of known NON-primes and loop them through the test
3) Take a list of random numbers and loop them through the test AND compare them to the known and unknown primes list.

This question has already been answered. Start a new discussion instead.