| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package func.lib; |
| 15 |
|
| 16 |
import org.hamcrest.BaseMatcher; |
| 17 |
import org.hamcrest.Description; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class RangeMatcher extends BaseMatcher<Integer> { |
| 27 |
private final int minVal; |
| 28 |
private final int maxVal; |
| 29 |
|
| 30 |
public RangeMatcher(int size) { |
| 31 |
this(size, size/20+1); |
| 32 |
} |
| 33 |
|
| 34 |
public RangeMatcher(int size, int range) { |
| 35 |
this.minVal = size - range; |
| 36 |
this.maxVal = size + range; |
| 37 |
} |
| 38 |
|
| 39 |
public boolean matches(Object o) { |
| 40 |
int other = (Integer) o; |
| 41 |
if (other > minVal && other < maxVal) |
| 42 |
return true; |
| 43 |
else return false; |
| 44 |
} |
| 45 |
|
| 46 |
public void describeTo(Description description) { |
| 47 |
description.appendValueList("between ", " and ", "", minVal, maxVal); |
| 48 |
} |
| 49 |
} |