0

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;
            else
                return false;
        }

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

[TestMethod]
        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.

Regards!

Edited by bisiii: /

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by bisiii
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.