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