MathUtilsTest.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:MFIBlocking 作者:
@Test
public void testNormilize() throws Exception {
    int[] rangeNumbersPrimitive = Ints.toArray(ContiguousSet.create(Range.closed(1, 10), DiscreteDomain.integers()));
    HashMap<Integer, Float> idToValue = new HashMap<>();
    for (int index = 0; index < rangeNumbersPrimitive.length; index++) {
        idToValue.put(index, (float) rangeNumbersPrimitive[index]);
    }
    HashMap<Integer, Float> copyMap = new HashMap<>(idToValue);
    MathUtils.normilize(idToValue);

    //assert range
    for (Float normValue : idToValue.values()) {
        assertThat((double) normValue, allOf(lessThanOrEqualTo(1.0), greaterThanOrEqualTo(0.0)));
    }
    //assert values
    for (Map.Entry<Integer, Float> entry : idToValue.entrySet()) {
        Integer key = entry.getKey();
        assertThat((double) entry.getValue(), closeTo((copyMap.get(key) - 1.0) / (9), 0.0001));
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号