Skip to main content
typo fix
Source Link
palacsint
  • 29.9k
  • 9
  • 81
  • 156

Some notes about the tests:

  1. The first the method has a smell: Conditional Test Logic. I'd extract out the do-while loop to an enumeratePrimesBelow(ulong upperLimit) method. It would improve readability a lot.

  2.   Assert.IsFalse(Primes.IsPrime(1));
    

I'd create a custom assertion method for that:

    public void AssertIsNotPrime(ulong value) {
        Assert.IsFalse(Primes.IsPrime(value));
    }

It would make the tests easier to read.

  1. _1IsNotPrimeTest, _2IsPrimeTest, _3IsPrimeTest, _42IsNotPrimeTest etc. should be a parametrizedparameterized test. I don't know whether C# unit testing frameworks supports it or not.

Some notes about the tests:

  1. The first the method has a smell: Conditional Test Logic. I'd extract out the do-while loop to an enumeratePrimesBelow(ulong upperLimit) method. It would improve readability a lot.

  2.   Assert.IsFalse(Primes.IsPrime(1));
    

I'd create a custom assertion method for that:

    public void AssertIsNotPrime(ulong value) {
        Assert.IsFalse(Primes.IsPrime(value));
    }

It would make the tests easier to read.

  1. _1IsNotPrimeTest, _2IsPrimeTest, _3IsPrimeTest, _42IsNotPrimeTest etc. should be a parametrized test. I don't know whether C# unit testing frameworks supports it or not.

Some notes about the tests:

  1. The first the method has a smell: Conditional Test Logic. I'd extract out the do-while loop to an enumeratePrimesBelow(ulong upperLimit) method. It would improve readability a lot.

  2.   Assert.IsFalse(Primes.IsPrime(1));
    

I'd create a custom assertion method for that:

    public void AssertIsNotPrime(ulong value) {
        Assert.IsFalse(Primes.IsPrime(value));
    }

It would make the tests easier to read.

  1. _1IsNotPrimeTest, _2IsPrimeTest, _3IsPrimeTest, _42IsNotPrimeTest etc. should be a parameterized test. I don't know whether C# unit testing frameworks supports it or not.
Source Link
palacsint
  • 29.9k
  • 9
  • 81
  • 156

Some notes about the tests:

  1. The first the method has a smell: Conditional Test Logic. I'd extract out the do-while loop to an enumeratePrimesBelow(ulong upperLimit) method. It would improve readability a lot.

  2.   Assert.IsFalse(Primes.IsPrime(1));
    

I'd create a custom assertion method for that:

    public void AssertIsNotPrime(ulong value) {
        Assert.IsFalse(Primes.IsPrime(value));
    }

It would make the tests easier to read.

  1. _1IsNotPrimeTest, _2IsPrimeTest, _3IsPrimeTest, _42IsNotPrimeTest etc. should be a parametrized test. I don't know whether C# unit testing frameworks supports it or not.