1 16 package org.apache.commons.lang.math; 17 18 import junit.framework.Test; 19 import junit.framework.TestSuite; 20 21 29 public final class NumberRangeTest extends AbstractRangeTest { 30 31 public NumberRangeTest(String name) { 32 super(name); 33 } 34 35 public static Test suite() { 36 TestSuite suite = new TestSuite(NumberRangeTest.class); 37 suite.setName("NumberRange Tests"); 38 return suite; 39 } 40 41 public void setUp() { 42 super.setUp(); 43 tenToTwenty = new NumberRange(ten, twenty); 44 otherRange = new IntRange(ten, twenty); 45 } 46 47 protected Range createRange(Integer integer1, Integer integer2) { 48 return new NumberRange(integer1, integer2); 49 } 50 protected Range createRange(Integer integer) { 51 return new NumberRange(integer); 52 } 53 54 56 public void testConstructor1() { 57 NumberRange nr = new NumberRange(five); 58 assertSame(five, nr.getMinimumNumber()); 59 assertSame(five, nr.getMaximumNumber()); 60 61 try { 62 new NumberRange(null); 63 fail(); 64 } catch (IllegalArgumentException ex) {} 65 try { 66 new NumberRange(nonComparable); 67 fail(); 68 } catch (IllegalArgumentException ex) {} 69 } 70 71 public void testConstructor2() { 72 NumberRange nr = new NumberRange(five, ten); 73 assertSame(five, nr.getMinimumNumber()); 74 assertSame(ten, nr.getMaximumNumber()); 75 76 nr = new NumberRange(ten, five); 77 assertSame(five, nr.getMinimumNumber()); 78 assertSame(ten, nr.getMaximumNumber()); 79 80 try { 82 new NumberRange(five, null); 83 fail(); 84 } catch (IllegalArgumentException ex) {} 85 try { 86 new NumberRange(null, five); 87 fail(); 88 } catch (IllegalArgumentException ex) {} 89 try { 90 new NumberRange(null, null); 91 fail(); 92 } catch (IllegalArgumentException ex) {} 93 94 try { 96 new NumberRange(five, long21); 97 fail(); 98 } catch (IllegalArgumentException ex) {} 99 100 try { 102 new NumberRange(nonComparable, nonComparable); 103 fail(); 104 } catch (IllegalArgumentException ex) {} 105 106 try { 108 new NumberRange(new Double (0), new Double (Double.NaN)); 109 fail(); 110 } catch (IllegalArgumentException ex) {} 111 112 try { 113 new NumberRange(new Double (Double.NaN), new Double (0)); 114 fail(); 115 } catch (IllegalArgumentException ex) {} 116 117 try { 119 new NumberRange(new Float (0), new Float (Float.NaN)); 120 fail(); 121 } catch (IllegalArgumentException ex) {} 122 123 try { 124 new NumberRange(new Float (Float.NaN), new Float (0)); 125 fail(); 126 } catch (IllegalArgumentException ex) {} 127 } 128 129 131 public void testContainsNumber() { 132 assertEquals(false, tenToTwenty.containsNumber(null)); 133 assertEquals(false, tenToTwenty.containsNumber(five)); 134 assertEquals(true, tenToTwenty.containsNumber(ten)); 135 assertEquals(true, tenToTwenty.containsNumber(fifteen)); 136 assertEquals(true, tenToTwenty.containsNumber(twenty)); 137 assertEquals(false, tenToTwenty.containsNumber(twentyFive)); 138 139 try { 140 tenToTwenty.containsNumber(long21); 141 fail(); 142 } catch (IllegalArgumentException ex) {} 143 } 144 145 public void testContainsLongBig() { 146 NumberRange big = new NumberRange(new Long (Long.MAX_VALUE), new Long (Long.MAX_VALUE- 2)); 148 assertEquals(true, big.containsLong(Long.MAX_VALUE - 1)); 149 assertEquals(false, big.containsLong(Long.MAX_VALUE - 3)); 150 } 151 152 154 } 155 | Popular Tags |