commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1066176 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
Date Wed, 02 Feb 2011 01:07:28 GMT
On 2 February 2011 00:24, Gilles Sadowski <gilles@harfang.homelinux.org> wrote:
> Hi.
>
>> Tidy up test
>
> Hmm. Not convinced.
> Factorizing that way all the CM unit tests is a lot of work for a dubious
> (IMO) improvement in readability.

I'm not suggesting others do the work.
Nor am I suggesting that all CM tests must be refactored this way.

However, this particular test had a lot of unused variables.
Furthermore, it did not actually test that the exceptions were thrown,
because there were no fail() calls for the successful cases.
As such, the test was not very useful.

> I find it clearer to have a single "@Test" named "testPreconditions()" that
> groups all the preconditions.

But the test did not achieve anything...

I think it's clear from this exercise that the new style makes it
easier to write valid tests.

> Also, sometimes, setting up the data to be passed (here to the constructor)
> is not as easy to set up as in this case, so that you'd have to the setup in
> every method (or use instance variables).

I was not suggesting that.

However, a test that has multiple potential failure points is not in
general a good test, as the first failure hides any others.
Of course if the first failure means that the test cannot continue,
that's a different matter.

> Gilles
>
>>
>> Modified:
>>     commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
>>
>> Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
>> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java?rev=1066176&r1=1066175&r2=1066176&view=diff
>> ==============================================================================
>> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
(original)
>> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/StepFunctionTest.java
Tue Feb  1 19:52:05 2011
>> @@ -32,48 +32,34 @@ import org.junit.Test;
>>  public class StepFunctionTest {
>>      private final double EPS = Math.ulp(1d);
>>
>> -    @Test
>> -    public void testPreconditions() {
>> -        try {
>> -            final UnivariateRealFunction f = new StepFunction(null,
>> -                                                      
       new double[] {0, -1, -2});
>> -        } catch (NullArgumentException e) {
>> -            // Expected.
>> -        }
>> -        try {
>> -            final UnivariateRealFunction f = new StepFunction(new double[]
{0, 1},
>> -                                                      
       null);
>> -        } catch (NullArgumentException e) {
>> -            // Expected.
>> -        }
>> -
>> -        try {
>> -            final UnivariateRealFunction f = new StepFunction(new double[]
{0},
>> -                                                      
       new double[] {});
>> -        } catch (NoDataException e) {
>> -            // Expected.
>> -        }
>> -
>> -        try {
>> -            final UnivariateRealFunction f = new StepFunction(new double[]
{},
>> -                                                      
       new double[] {0});
>> -        } catch (NoDataException e) {
>> -            // Expected.
>> -        }
>> -
>> -        try {
>> -            final UnivariateRealFunction f = new StepFunction(new double[]
{0, 1},
>> -                                                      
       new double[] {0, -1, -2});
>> -        } catch (DimensionMismatchException e) {
>> -            // Expected.
>> -        }
>> -
>> -        try {
>> -            final UnivariateRealFunction f = new StepFunction(new double[]
{1, 0, 1},
>> -                                                      
       new double[] {0, -1, -2});
>> -        } catch (NonMonotonousSequenceException e) {
>> -            // Expected.
>> -        }
>> +    @Test(expected=NullArgumentException.class)
>> +    public void testPreconditions1() {
>> +        new StepFunction(null, new double[] {0, -1, -2});
>> +    }
>> +
>> +    @Test(expected=NullArgumentException.class)
>> +    public void testPreconditions2() {
>> +        new StepFunction(new double[] {0, 1}, null);
>> +    }
>> +
>> +    @Test(expected=NoDataException.class)
>> +    public void testPreconditions3() {
>> +        new StepFunction(new double[] {0}, new double[] {});
>> +    }
>> +
>> +    @Test(expected=NoDataException.class)
>> +    public void testPreconditions4() {
>> +        new StepFunction(new double[] {}, new double[] {0});
>> +    }
>> +
>> +    @Test(expected=DimensionMismatchException.class)
>> +    public void testPreconditions5() {
>> +        new StepFunction(new double[] {0, 1}, new double[] {0, -1, -2});
>> +    }
>> +
>> +    @Test(expected=NonMonotonousSequenceException.class)
>> +    public void testPreconditions6() {
>> +        new StepFunction(new double[] {1, 0, 1}, new double[] {0, -1, -2});
>>      }
>>
>>      @Test
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message