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:
Sebastian Bazley 2009-11-21 18:30:09 +00:00
parent 229f41046f
commit 38ac11d0b7
1 changed files with 39 additions and 0 deletions

View File

@ -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() {