本文整理了Java中org.hamcrest.number.IsCloseTo
类的一些代码示例,展示了IsCloseTo
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IsCloseTo
类的具体详情如下:
包路径:org.hamcrest.number.IsCloseTo
类名称:IsCloseTo
[英]Is the value a number equal to a value within some range of acceptable error?
[中]该值是否为一个数字,等于某个可接受误差范围内的值?
代码示例来源:origin: org.hamcrest/hamcrest-all
/**
* Creates a matcher of {@link Double}s that matches when an examined double is equal
* to the specified <code>operand</code>, within a range of +/- <code>error</code>.
* <p/>
* For example:
* <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre>
*
* @param operand
* the expected value of matching doubles
* @param error
* the delta (+/-) within which matches will be allowed
*/
public static org.hamcrest.Matcher<java.lang.Double> closeTo(double operand, double error) {
return org.hamcrest.number.IsCloseTo.closeTo(operand, error);
}
代码示例来源:origin: hamcrest/JavaHamcrest
/**
* Creates a matcher of {@link Double}s that matches when an examined double is equal
* to the specified <code>operand</code>, within a range of +/- <code>error</code>.
* For example:
* <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre>
*
* @param operand
* the expected value of matching doubles
* @param error
* the delta (+/-) within which matches will be allowed
*/
public static Matcher<Double> closeTo(double operand, double error) {
return new IsCloseTo(operand, error);
}
}
代码示例来源:origin: org.hamcrest/hamcrest-all
@Override
public boolean matchesSafely(Double item) {
return actualDelta(item) <= 0.0;
}
代码示例来源:origin: hamcrest/JavaHamcrest
/**
* Creates a matcher of {@link Double}s that matches when an examined double is equal
* to the specified <code>operand</code>, within a range of +/- <code>error</code>.
* For example:
* <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre>
*
* @param operand
* the expected value of matching doubles
* @param error
* the delta (+/-) within which matches will be allowed
*/
public static org.hamcrest.Matcher<java.lang.Double> closeTo(double operand, double error) {
return org.hamcrest.number.IsCloseTo.closeTo(operand, error);
}
代码示例来源:origin: org.hamcrest/hamcrest-all
/**
* Creates a matcher of {@link Double}s that matches when an examined double is equal
* to the specified <code>operand</code>, within a range of +/- <code>error</code>.
* <p/>
* For example:
* <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre>
*
* @param operand
* the expected value of matching doubles
* @param error
* the delta (+/-) within which matches will be allowed
*/
@Factory
public static Matcher<Double> closeTo(double operand, double error) {
return new IsCloseTo(operand, error);
}
}
代码示例来源:origin: hamcrest/JavaHamcrest
@Override
public boolean matchesSafely(Double item) {
return actualDelta(item) <= 0.0;
}
代码示例来源:origin: hamcrest/JavaHamcrest
@Override
protected Matcher<?> createMatcher() {
final double irrelevant = 0.1;
return closeTo(irrelevant, irrelevant);
}
代码示例来源:origin: org.hamcrest/java-hamcrest
/**
* Creates a matcher of {@link Double}s that matches when an examined double is equal
* to the specified <code>operand</code>, within a range of +/- <code>error</code>.
* For example:
* <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre>
*
* @param operand
* the expected value of matching doubles
* @param error
* the delta (+/-) within which matches will be allowed
*/
public static Matcher<Double> closeTo(double operand, double error) {
return new IsCloseTo(operand, error);
}
}
代码示例来源:origin: org.hamcrest/hamcrest-all
@Override
public void describeMismatchSafely(Double item, Description mismatchDescription) {
mismatchDescription.appendValue(item)
.appendText(" differed by ")
.appendValue(actualDelta(item));
}
代码示例来源:origin: iSoron/uhabits
@Test
public void test_compute_withDailyHabit()
{
int check = 1;
double freq = 1.0;
assertThat(compute(freq, 0, check), closeTo(0.051922, E));
assertThat(compute(freq, 0.5, check), closeTo(0.525961, E));
assertThat(compute(freq, 0.75, check), closeTo(0.762981, E));
check = 0;
assertThat(compute(freq, 0, check), closeTo(0, E));
assertThat(compute(freq, 0.5, check), closeTo(0.474039, E));
assertThat(compute(freq, 0.75, check), closeTo(0.711058, E));
}
代码示例来源:origin: org.hamcrest/hamcrest
/**
* Creates a matcher of {@link Double}s that matches when an examined double is equal
* to the specified <code>operand</code>, within a range of +/- <code>error</code>.
* For example:
* <pre>assertThat(1.03, is(closeTo(1.0, 0.03)))</pre>
*
* @param operand
* the expected value of matching doubles
* @param error
* the delta (+/-) within which matches will be allowed
*/
public static Matcher<Double> closeTo(double operand, double error) {
return new IsCloseTo(operand, error);
}
}
代码示例来源:origin: hamcrest/JavaHamcrest
@Override
public void describeMismatchSafely(Double item, Description mismatchDescription) {
mismatchDescription.appendValue(item)
.appendText(" differed by ")
.appendValue(actualDelta(item))
.appendText(" more than delta ")
.appendValue(delta);
}
代码示例来源:origin: iSoron/uhabits
@Test
public void test_compute_withNonDailyHabit()
{
int check = 1;
double freq = 1 / 3.0;
assertThat(compute(freq, 0, check), closeTo(0.017616, E));
assertThat(compute(freq, 0.5, check), closeTo(0.508808, E));
assertThat(compute(freq, 0.75, check), closeTo(0.754404, E));
check = 0;
assertThat(compute(freq, 0, check), closeTo(0.0, E));
assertThat(compute(freq, 0.5, check), closeTo(0.491192, E));
assertThat(compute(freq, 0.75, check), closeTo(0.736788, E));
}
代码示例来源:origin: org.hamcrest/com.springsource.org.hamcrest
@Factory
public static Matcher<Double> closeTo(double operand, double error) {
return new IsCloseTo(operand, error);
}
代码示例来源:origin: org.hamcrest/java-hamcrest
@Override
public boolean matchesSafely(Double item) {
return actualDelta(item) <= 0.0;
}
代码示例来源:origin: iSoron/uhabits
@Test
public void test_groupBy()
{
Habit habit = fixtures.createLongHabit();
List<Score> list =
habit.getScores().groupBy(DateUtils.TruncateField.MONTH);
assertThat(list.size(), equalTo(5));
assertThat(list.get(0).getValue(), closeTo(0.653659, E));
assertThat(list.get(1).getValue(), closeTo(0.622715, E));
assertThat(list.get(2).getValue(), closeTo(0.520997, E));
}
代码示例来源:origin: stackoverflow.com
@SuppressWarnings({"rawtypes", "unchecked"})
public static Matcher<double[]> isArrayCloseTo(double[] expected) {
final double DELTA = 1e-10;
List<Matcher<Double>> matchers = new ArrayList<>();
for (double d : expected)
matchers.add(new IsCloseTo(d, DELTA));
return new CustomTypeSafeMatcher<double[]>("array that is close to" + Arrays.toString(expected)) {
@Override
protected boolean matchesSafely(double[] actual) {
return new IsArray<Double>(matchers.toArray(new Matcher[matchers.size()]))
.matchesSafely(Arrays.stream(actual).boxed().toArray(Double[]::new));
}
};
}
代码示例来源:origin: org.hamcrest/java-hamcrest
@Override
public void describeMismatchSafely(Double item, Description mismatchDescription) {
mismatchDescription.appendValue(item)
.appendText(" differed by ")
.appendValue(actualDelta(item))
.appendText(" more than delta ")
.appendValue(delta);
}
代码示例来源:origin: iSoron/uhabits
@Test
public void test_getTodayValue()
{
toggleRepetitions(0, 20);
double actual = habit.getScores().getTodayValue();
assertThat(actual, closeTo(0.655747, E));
}
代码示例来源:origin: org.hamcrest/hamcrest
@Override
public boolean matchesSafely(Double item) {
return actualDelta(item) <= 0.0;
}
内容来源于网络,如有侵权,请联系作者删除!