org.hamcrest.number.IsCloseTo.closeTo()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.hamcrest.number.IsCloseTo.closeTo()方法的一些代码示例,展示了IsCloseTo.closeTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IsCloseTo.closeTo()方法的具体详情如下:
包路径:org.hamcrest.number.IsCloseTo
类名称:IsCloseTo
方法名:closeTo

IsCloseTo.closeTo介绍

[英]Creates a matcher of Doubles that matches when an examined double is equal to the specified operand, within a range of +/- error. For example:

assertThat(1.03, is(closeTo(1.0, 0.03)))

[中]创建一个双精度匹配器,当检查的双精度等于指定的operand,且在+/-error范围内时匹配。例如:

assertThat(1.03, is(closeTo(1.0, 0.03)))

代码示例

代码示例来源: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 org.hamcrest.Matcher<java.lang.Double> closeTo(double operand, double error) {
 return org.hamcrest.number.IsCloseTo.closeTo(operand, error);
}

代码示例来源:origin: hamcrest/JavaHamcrest

@Override
 protected Matcher<?> createMatcher() {
   final double irrelevant = 0.1;
   return closeTo(irrelevant, irrelevant);
 }

代码示例来源: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: 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: 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: iSoron/uhabits

@Test
public void test_getTodayValue()
{
  toggleRepetitions(0, 20);
  double actual = habit.getScores().getTodayValue();
  assertThat(actual, closeTo(0.655747, E));
}

代码示例来源:origin: iSoron/uhabits

@Test
public void test_invalidateNewerThan()
{
  assertThat(habit.getScores().getTodayValue(), closeTo(0.0, E));
  toggleRepetitions(0, 2);
  assertThat(habit.getScores().getTodayValue(), closeTo(0.101149, E));
  habit.setFrequency(new Frequency(1, 2));
  habit.getScores().invalidateNewerThan(new Timestamp(0));
  assertThat(habit.getScores().getTodayValue(), closeTo(0.051922, E));
}

代码示例来源:origin: iSoron/uhabits

@Test
public void test_getValues()
{
  toggleRepetitions(0, 20);
  Timestamp today = DateUtils.getToday();
  Timestamp from = today.minus(4);
  Timestamp to = today.minus(2);
  double[] expected = {
    0.617008, 0.596033, 0.573909,
  };
  double[] actual = habit.getScores().getValues(from, to);
  assertThat(actual.length, equalTo(expected.length));
  for (int i = 0; i < actual.length; i++)
    assertThat(actual[i], closeTo(expected[i], E));
}

代码示例来源:origin: iSoron/uhabits

@Test
public void test_getAll()
{
  toggleRepetitions(0, 20);
  double expectedValues[] = {
    0.655747,
    0.636894,
    0.617008,
    0.596033,
    0.573910,
    0.550574,
    0.525961,
    0.500000,
    0.472617,
    0.443734,
    0.413270,
    0.381137,
    0.347244,
    0.311495,
    0.273788,
    0.234017,
    0.192067,
    0.147820,
    0.101149,
    0.051922,
  };
  int i = 0;
  for (Score s : habit.getScores())
    assertThat(s.getValue(), closeTo(expectedValues[i++], E));
}

代码示例来源: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 org.hamcrest.Matcher<java.lang.Double> closeTo(double operand, double error) {
 return org.hamcrest.number.IsCloseTo.closeTo(operand, error);
}

代码示例来源:origin: iSoron/uhabits

for (double expectedValue : expectedValues)
  assertThat(scores.getValue(current), closeTo(expectedValue, E));
  current = current.minus(1);

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testSameStringsHaveHighestScore() {
 double score = SorensenDiceCoefficient.compute("hello", "hello", "en");
 assertThat(score, closeTo(1.0, 0.00001));
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testStringsWithOnlyDifferentSpacesHaveHighestScore() {
 double score = SorensenDiceCoefficient.compute("hello   world", " hello world", "en");
 assertThat(score, closeTo(1.0, 0.00001));
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testStringsWithOnlyDifferentCaseHaveHighestScore() {
 double score = SorensenDiceCoefficient.compute("HELLo", "heLlO", "en");
 assertThat(score, closeTo(1.0, 0.00001));
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testScoreIsProperlyComputedWithCustomLanguageTag() {
 double score = SorensenDiceCoefficient.compute("çok ağrıyor", "az bilmiyor", "tr-TR");
 int text1PairCount  = countOf("ço","ok")  + countOf("ağ","ğr","rı","ıy",     "yo","or");
 int text2PairCount  = countOf("az")       + countOf("bi","il","lm","mi","iy","yo","or");
 int commonPairs     =                       countOf("yo","or");
 double expectedScore = 2.0 * commonPairs / (text1PairCount + text2PairCount);
 assertThat(score, closeTo((expectedScore), 0.00001));
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testScoreIsProperlyComputed() {
 double score = SorensenDiceCoefficient.compute("quite similar", "quiet similaire", "en");
 int text1PairCount  = countOf("qu","ui","it","te")  + countOf("si","im","mi","il","la","ar");
 int text2PairCount  = countOf("qu","ui","ie","et")  + countOf("si","im","mi","il","la","ai","ir","re");
 int commonPairs     = countOf("qu","ui")            + countOf("si","im","mi","il","la");
 double expectedScore = 2.0 * commonPairs / (text1PairCount + text2PairCount);
 assertThat(score, closeTo((expectedScore), 0.00001));
}

代码示例来源:origin: org.mule.services/mule-service-scheduler

protected void assertTerminationIsNotDelayed(final ScheduledExecutorService executor) throws InterruptedException {
 long startTime = nanoTime();
 executor.shutdown();
 executor.awaitTermination(1, SECONDS);
 assertThat((double) NANOSECONDS.toMillis(nanoTime() - startTime), closeTo(0, DELTA_MILLIS));
}

代码示例来源:origin: cdk/cdk

@Test
public void testNewUnitVector() throws Exception {
  Vector2d unit = VecmathUtil.newUnitVector(new Point2d(4, 2), new Point2d(6, 7));
  assertThat(unit.x, closeTo(0.371d, 0.01));
  assertThat(unit.y, closeTo(0.928d, 0.01));
  assertThat(unit.length(), closeTo(1d, 0.01));
}

代码示例来源:origin: cdk/cdk

@Test public void noNullPointerExceptionForMassOfRGroups() throws Exception {
  IMolecularFormula formula = new MolecularFormula();
  formula.addIsotope(new Isotope("C"));
  formula.addIsotope(new Isotope("H"), 3);
  formula.addIsotope(new Isotope("R"));
  assertThat(MolecularFormulaManipulator.getTotalMassNumber(formula),
        closeTo(15.0, 0.01));
}

相关文章

微信公众号

最新文章

更多