Add some basic Comparator tests
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@882960 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
229f41046f
commit
38ac11d0b7
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.apache.commons.lang;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
|
@ -64,6 +66,43 @@ public class RangeTest extends TestCase {
|
|||
Range.between(c, c);
|
||||
}
|
||||
|
||||
public void testIsWithCompare(){
|
||||
Comparator<Integer> c = new Comparator<Integer>(){
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return 0; // all integers are equal
|
||||
}
|
||||
};
|
||||
Range<Integer> ri = Range.is(10);
|
||||
assertFalse("should not contain null",ri.contains(null));
|
||||
assertTrue("should contain 10",ri.contains(10));
|
||||
assertFalse("should not contain 11",ri.contains(11));
|
||||
ri = Range.is(10,c);
|
||||
assertFalse("should not contain null",ri.contains(null));
|
||||
assertTrue("should contain 10",ri.contains(10));
|
||||
assertTrue("should contain 11",ri.contains(11));
|
||||
}
|
||||
|
||||
public void testBetweenWithCompare(){
|
||||
// TODO add tests with a better comparator
|
||||
Comparator<Integer> c = new Comparator<Integer>(){
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return 0; // all integers are equal
|
||||
}
|
||||
};
|
||||
Range<Integer> rb = Range.between(-10,20);
|
||||
assertFalse("should not contain null",rb.contains(null));
|
||||
assertTrue("should contain 10",rb.contains(10));
|
||||
assertTrue("should contain -10",rb.contains(-10));
|
||||
assertFalse("should not contain 21",rb.contains(21));
|
||||
assertFalse("should not contain -11",rb.contains(-11));
|
||||
rb = Range.between(-10,20,c);
|
||||
assertFalse("should not contain null",rb.contains(null));
|
||||
assertTrue("should contain 10",rb.contains(10));
|
||||
assertTrue("should contain -10",rb.contains(-10));
|
||||
assertTrue("should contain 21",rb.contains(21));
|
||||
assertTrue("should contain -11",rb.contains(-11));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
public void testRangeOfChars() {
|
||||
|
|
Loading…
Reference in New Issue