commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang NumberUtilsTest.java
Date Sun, 15 Sep 2002 10:27:56 GMT
scolebourne    2002/09/15 03:27:56

  Modified:    lang/src/test/org/apache/commons/lang NumberUtilsTest.java
  Log:
  Add tests for new min, max and compare methods
  
  Revision  Changes    Path
  1.2       +205 -3    jakarta-commons/lang/src/test/org/apache/commons/lang/NumberUtilsTest.java
  
  Index: NumberUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/NumberUtilsTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NumberUtilsTest.java	19 Jul 2002 03:35:55 -0000	1.1
  +++ NumberUtilsTest.java	15 Sep 2002 10:27:56 -0000	1.2
  @@ -154,7 +154,16 @@
           assertEquals("createBigDecimal(String) failed", new BigDecimal("1234.5"), NumberUtils.createBigDecimal("1234.5"));
       }
   
  -    public void testMinimum() {
  +    public void testMinimumLong() {
  +        assertEquals("minimum(long,long,long) 1 failed", 12345L, NumberUtils.minimum(12345L,
12345L + 1L, 12345L + 2L));
  +        assertEquals("minimum(long,long,long) 2 failed", 12345L, NumberUtils.minimum(12345L
+ 1L, 12345L, 12345 + 2L));
  +        assertEquals("minimum(long,long,long) 3 failed", 12345L, NumberUtils.minimum(12345L
+ 1L, 12345L + 2L, 12345L));
  +        assertEquals("minimum(long,long,long) 4 failed", 12345L, NumberUtils.minimum(12345L
+ 1L, 12345L, 12345L));
  +        assertEquals("minimum(long,long,long) 5 failed", 12345L, NumberUtils.minimum(12345L,
12345L, 12345L));
  +
  +    }
  +
  +    public void testMinimumInt() {
           assertEquals("minimum(int,int,int) 1 failed", 12345, NumberUtils.minimum(12345,
12345 + 1, 12345 + 2));
           assertEquals("minimum(int,int,int) 2 failed", 12345, NumberUtils.minimum(12345
+ 1, 12345, 12345 + 2));
           assertEquals("minimum(int,int,int) 3 failed", 12345, NumberUtils.minimum(12345
+ 1, 12345 + 2, 12345));
  @@ -163,13 +172,206 @@
   
       }
   
  -    public void testMaximum() {
  +    public void testMaximumLong() {
  +        assertEquals("maximum(long,long,long) 1 failed", 12345L, NumberUtils.maximum(12345L,
12345L - 1L, 12345L - 2L));
  +        assertEquals("maximum(long,long,long) 2 failed", 12345L, NumberUtils.maximum(12345L
- 1L, 12345L, 12345L - 2L));
  +        assertEquals("maximum(long,long,long) 3 failed", 12345L, NumberUtils.maximum(12345L
- 1L, 12345L - 2L, 12345L));
  +        assertEquals("maximum(long,long,long) 4 failed", 12345L, NumberUtils.maximum(12345L
- 1L, 12345L, 12345L));
  +        assertEquals("maximum(long,long,long) 5 failed", 12345L, NumberUtils.maximum(12345L,
12345L, 12345L));
  +
  +    }
  +
  +    public void testMaximumInt() {
           assertEquals("maximum(int,int,int) 1 failed", 12345, NumberUtils.maximum(12345,
12345 - 1, 12345 - 2));
           assertEquals("maximum(int,int,int) 2 failed", 12345, NumberUtils.maximum(12345
- 1, 12345, 12345 - 2));
           assertEquals("maximum(int,int,int) 3 failed", 12345, NumberUtils.maximum(12345
- 1, 12345 - 2, 12345));
           assertEquals("maximum(int,int,int) 4 failed", 12345, NumberUtils.maximum(12345
- 1, 12345, 12345));
           assertEquals("maximum(int,int,int) 5 failed", 12345, NumberUtils.maximum(12345,
12345, 12345));
   
  +    }
  +
  +    public void testCompareDouble() {
  +        assertTrue(NumberUtils.compare(Double.NaN, Double.NaN) == 0);
  +        assertTrue(NumberUtils.compare(Double.NaN, Double.POSITIVE_INFINITY) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, 1.2d) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, 0.0d) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, -0.0d) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, -1.2d) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, -Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Double.NaN, Double.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)
== 0);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, 1.2d) == +1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, 0.0d) == +1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, -0.0d) == +1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, -1.2d) == +1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, -Double.MAX_VALUE) ==
+1);
  +        assertTrue(NumberUtils.compare(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)
== +1);
  +        
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, Double.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, Double.MAX_VALUE) == 0);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, 1.2d) == +1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, 0.0d) == +1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, -0.0d) == +1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, -1.2d) == +1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, -Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Double.MAX_VALUE, Double.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(1.2d, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(1.2d, Double.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(1.2d, Double.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(1.2d, 1.2d) == 0);
  +        assertTrue(NumberUtils.compare(1.2d, 0.0d) == +1);
  +        assertTrue(NumberUtils.compare(1.2d, -0.0d) == +1);
  +        assertTrue(NumberUtils.compare(1.2d, -1.2d) == +1);
  +        assertTrue(NumberUtils.compare(1.2d, -Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(1.2d, Double.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(0.0d, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(0.0d, Double.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(0.0d, Double.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(0.0d, 1.2d) == -1);
  +        assertTrue(NumberUtils.compare(0.0d, 0.0d) == 0);
  +        assertTrue(NumberUtils.compare(0.0d, -0.0d) == +1);
  +        assertTrue(NumberUtils.compare(0.0d, -1.2d) == +1);
  +        assertTrue(NumberUtils.compare(0.0d, -Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(0.0d, Double.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(-0.0d, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(-0.0d, Double.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(-0.0d, Double.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(-0.0d, 1.2d) == -1);
  +        assertTrue(NumberUtils.compare(-0.0d, 0.0d) == -1);
  +        assertTrue(NumberUtils.compare(-0.0d, -0.0d) == 0);
  +        assertTrue(NumberUtils.compare(-0.0d, -1.2d) == +1);
  +        assertTrue(NumberUtils.compare(-0.0d, -Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(-0.0d, Double.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(-1.2d, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(-1.2d, Double.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(-1.2d, Double.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(-1.2d, 1.2d) == -1);
  +        assertTrue(NumberUtils.compare(-1.2d, 0.0d) == -1);
  +        assertTrue(NumberUtils.compare(-1.2d, -0.0d) == -1);
  +        assertTrue(NumberUtils.compare(-1.2d, -1.2d) == 0);
  +        assertTrue(NumberUtils.compare(-1.2d, -Double.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(-1.2d, Double.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, Double.POSITIVE_INFINITY) ==
-1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, Double.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, 1.2d) == -1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, 0.0d) == -1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, -0.0d) == -1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, -1.2d) == -1);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, -Double.MAX_VALUE) == 0);
  +        assertTrue(NumberUtils.compare(-Double.MAX_VALUE, Double.NEGATIVE_INFINITY) ==
+1);
  +        
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, Double.NaN) == -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)
== -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, Double.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, 1.2d) == -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, 0.0d) == -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, -0.0d) == -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, -1.2d) == -1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE) ==
-1);
  +        assertTrue(NumberUtils.compare(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)
== 0);
  +    }
  +
  +    public void testCompareFloat() {
  +        assertTrue(NumberUtils.compare(Float.NaN, Float.NaN) == 0);
  +        assertTrue(NumberUtils.compare(Float.NaN, Float.POSITIVE_INFINITY) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, 1.2f) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, 0.0f) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, -0.0f) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, -1.2f) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Float.NaN, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)
== 0);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, 1.2f) == +1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, 0.0f) == +1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, -0.0f) == +1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, -1.2f) == +1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY)
== +1);
  +        
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, Float.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, Float.MAX_VALUE) == 0);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, 1.2f) == +1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, 0.0f) == +1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, -0.0f) == +1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, -1.2f) == +1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(Float.MAX_VALUE, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(1.2f, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(1.2f, Float.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(1.2f, Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(1.2f, 1.2f) == 0);
  +        assertTrue(NumberUtils.compare(1.2f, 0.0f) == +1);
  +        assertTrue(NumberUtils.compare(1.2f, -0.0f) == +1);
  +        assertTrue(NumberUtils.compare(1.2f, -1.2f) == +1);
  +        assertTrue(NumberUtils.compare(1.2f, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(1.2f, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(0.0f, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(0.0f, Float.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(0.0f, Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(0.0f, 1.2f) == -1);
  +        assertTrue(NumberUtils.compare(0.0f, 0.0f) == 0);
  +        assertTrue(NumberUtils.compare(0.0f, -0.0f) == +1);
  +        assertTrue(NumberUtils.compare(0.0f, -1.2f) == +1);
  +        assertTrue(NumberUtils.compare(0.0f, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(0.0f, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(-0.0f, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(-0.0f, Float.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(-0.0f, Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(-0.0f, 1.2f) == -1);
  +        assertTrue(NumberUtils.compare(-0.0f, 0.0f) == -1);
  +        assertTrue(NumberUtils.compare(-0.0f, -0.0f) == 0);
  +        assertTrue(NumberUtils.compare(-0.0f, -1.2f) == +1);
  +        assertTrue(NumberUtils.compare(-0.0f, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(-0.0f, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(-1.2f, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(-1.2f, Float.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(-1.2f, Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(-1.2f, 1.2f) == -1);
  +        assertTrue(NumberUtils.compare(-1.2f, 0.0f) == -1);
  +        assertTrue(NumberUtils.compare(-1.2f, -0.0f) == -1);
  +        assertTrue(NumberUtils.compare(-1.2f, -1.2f) == 0);
  +        assertTrue(NumberUtils.compare(-1.2f, -Float.MAX_VALUE) == +1);
  +        assertTrue(NumberUtils.compare(-1.2f, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, Float.POSITIVE_INFINITY) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, 1.2f) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, 0.0f) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, -0.0f) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, -1.2f) == -1);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, -Float.MAX_VALUE) == 0);
  +        assertTrue(NumberUtils.compare(-Float.MAX_VALUE, Float.NEGATIVE_INFINITY) == +1);
  +        
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, Float.NaN) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY)
== -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, 1.2f) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, 0.0f) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, -0.0f) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, -1.2f) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, -Float.MAX_VALUE) == -1);
  +        assertTrue(NumberUtils.compare(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY)
== 0);
       }
   
       public void testIsDigits() {
  
  
  

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


Mime
View raw message