Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Core/src/test/java/org/tribuo/util/MurmurHash3Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.tribuo.util;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for {@link MurmurHash3}.
*/
class MurmurHash3Test {

@Test
void testFmix32() {
assertEquals(1364076727, MurmurHash3.fmix32(1));
assertEquals(-2114883783, MurmurHash3.fmix32(-1));
assertEquals(-383449968, MurmurHash3.fmix32(10));
assertEquals(-36807446, MurmurHash3.fmix32(100));
assertEquals(-1434176238, MurmurHash3.fmix32(21323));
}

@Test
void testFmix64() {
assertEquals(-5451962507482445012L, MurmurHash3.fmix64(1));
assertEquals(7256831767414464289L, MurmurHash3.fmix64(-1));
assertEquals(7233188113542599437L, MurmurHash3.fmix64(10));
assertEquals(-1819968182471218078L, MurmurHash3.fmix64(100));
assertEquals(3402563454534931576L, MurmurHash3.fmix64(21323));
}

}
39 changes: 38 additions & 1 deletion Core/src/test/java/org/tribuo/util/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.junit.jupiter.api.Assertions.fail;

/**
*
* Unit Test for class {@link Util}.
*/
public class UtilTest {
private static final double DELTA = 1e-12;
Expand All @@ -50,6 +50,21 @@ public void testArgmax() {
assertEquals(3, argmax.getB());
}

@Test
public void testArgmin() {
assertThrows(IllegalArgumentException.class, () -> Util.argmin(new ArrayList<Double>()));

List<Integer> lst = Collections.singletonList(1);
Pair<Integer, Integer> argmin = Util.argmin(lst);
assertEquals(0, argmin.getA());
assertEquals(1, argmin.getB());

lst = Arrays.asList(3, 2, 1);
argmin = Util.argmin(lst);
assertEquals(2, argmin.getA());
assertEquals(1, argmin.getB());
}

@Test
public void testAUC() {
double output;
Expand Down Expand Up @@ -80,4 +95,26 @@ public void testAUC() {
assertEquals(0.5,output,DELTA);
}

@Test
public void testBinarySearch(){

List<String> stringList = Arrays.asList("apple", "banana", "cherry", "date", "fig", "grape");
List<Integer> intList = List.of(1, 3, 5, 7, 9);

assertEquals( -1, Util.binarySearch(stringList, "Cherry"));
assertEquals( 2, Util.binarySearch(stringList, "cherry"));

assertEquals(2, Util.binarySearch(intList, 5, x -> x));
assertEquals(-4, Util.binarySearch(intList, 6, x -> x));

}

@Test
public void testProduct(){
assertEquals(0, Util.product(new int[]{0, 0}));
assertEquals(0, Util.product(new int[]{1, 0}));
assertEquals(0, Util.product(new int[]{0, 1, 2, 3, 4, 5}));
assertEquals(120, Util.product(new int[]{1, 1, 2, 3, 4, 5}));
}

}