mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-11-26 02:30:39 -06:00
fixed integrated tests for HashRange vs HashInterval, expanded constructions for Set
This commit is contained in:
parent
01da138364
commit
bb57a479d6
@ -1,5 +1,6 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
@ -8,15 +9,14 @@ import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import java.util.HashSet;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
|
||||
/**
|
||||
* Create a {@code Set} from a long input based on two functions,
|
||||
* the first to determine the set size, and the second to populate
|
||||
* the set with object values. The input fed to the second function
|
||||
* is incremented between elements.
|
||||
*
|
||||
* To create Sets of Strings from the String version of the same
|
||||
* mapping functions, simply use {@link StringSet} instead.
|
||||
* Create a {@code Set} from a long input based on two functions, the first to determine the set size, and the second to
|
||||
* populate the set with object values. The input fed to the second function is incremented between elements.
|
||||
* <p>
|
||||
* To create Sets of Strings from the String version of the same mapping functions, simply use {@link StringSet}
|
||||
* instead.
|
||||
*/
|
||||
@Categories({Category.collections})
|
||||
@ThreadSafeMapper
|
||||
@ -31,13 +31,61 @@ public class Set implements LongFunction<java.util.Set<Object>> {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFunc = valueFunc;
|
||||
}
|
||||
public Set(LongToIntFunction sizeFunc, LongUnaryOperator valueFunc) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFunc = valueFunc::applyAsLong;
|
||||
}
|
||||
public Set(LongToIntFunction sizeFunc, LongToIntFunction valueFunc) {
|
||||
this.sizeFunc = sizeFunc;
|
||||
this.valueFunc = valueFunc::applyAsInt;
|
||||
}
|
||||
|
||||
|
||||
public Set(LongFunction<Object> sizeFunc, LongFunction<Object> valueFunc) {
|
||||
this.sizeFunc = checkSizeFunc(sizeFunc);
|
||||
this.valueFunc = valueFunc;
|
||||
}
|
||||
public Set(LongFunction<Object> sizeFunc, LongUnaryOperator valueFunc) {
|
||||
this.sizeFunc = checkSizeFunc(sizeFunc);
|
||||
this.valueFunc = valueFunc::applyAsLong;
|
||||
}
|
||||
public Set(LongFunction<Object> sizeFunc, LongToIntFunction valueFunc) {
|
||||
this.sizeFunc = checkSizeFunc(sizeFunc);
|
||||
this.valueFunc = valueFunc::applyAsInt;
|
||||
}
|
||||
|
||||
public Set(LongUnaryOperator sizeFunc, LongFunction<Object> valueFunc) {
|
||||
this.sizeFunc = l -> (int) sizeFunc.applyAsLong(l);
|
||||
this.valueFunc = valueFunc;
|
||||
}
|
||||
public Set(LongUnaryOperator sizeFunc, LongUnaryOperator valueFunc) {
|
||||
this.sizeFunc = l -> (int) sizeFunc.applyAsLong(l);
|
||||
this.valueFunc = valueFunc::applyAsLong;
|
||||
}
|
||||
public Set(LongUnaryOperator sizeFunc, LongToIntFunction valueFunc) {
|
||||
this.sizeFunc = l -> (int) sizeFunc.applyAsLong(l);
|
||||
this.valueFunc = valueFunc::applyAsInt;
|
||||
}
|
||||
|
||||
|
||||
private static LongToIntFunction checkSizeFunc(LongFunction<?> sizeFunc) {
|
||||
Object sizeType = sizeFunc.apply(0);
|
||||
if (int.class.isAssignableFrom(sizeType.getClass())) {
|
||||
return value -> ((LongFunction<Integer>)sizeFunc).apply(value);
|
||||
} else if (long.class.isAssignableFrom(sizeType.getClass())) {
|
||||
return value -> ((LongFunction<Long>)sizeFunc).apply(value).intValue();
|
||||
} else {
|
||||
throw new BasicError("The size function produces " + sizeType.getClass().getCanonicalName() + ", which can't be used as an integer");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Set<Object> apply(long value) {
|
||||
int size = sizeFunc.applyAsInt(value);
|
||||
java.util.Set<Object> set = new HashSet<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
set.add(valueFunc.apply(value+i));
|
||||
set.add(valueFunc.apply(value + i));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.nosqlbench.virtdata.library.basics.shared.from_long.to_collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -10,7 +11,7 @@ public class SetTest {
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
Set set = new Set(s -> 3, e -> e);
|
||||
Set set = new Set((LongToIntFunction) s -> 3, (LongFunction) e -> e);
|
||||
java.util.Set<Object> s1 = set.apply(15L);
|
||||
assertThat(s1).containsOnly(15L,16L,17L);
|
||||
}
|
||||
|
@ -166,24 +166,24 @@ public class IntegratedComposerLibraryTest {
|
||||
@Test
|
||||
public void testChainedHashRanges() {
|
||||
final int initialCycle = 0;
|
||||
final int intermediateCycle = 39;
|
||||
final int intermediateCycle = 52;
|
||||
final int finalCycle = 81;
|
||||
|
||||
Object intermediateValue = assertMapper("compose HashRange(0,100) -> int", initialCycle);
|
||||
assertInteger(intermediateValue, intermediateCycle);
|
||||
Object intermediateValue = assertMapper("compose HashRange(0,100) -> int", 0);
|
||||
assertThat(intermediateValue).isEqualTo(52);
|
||||
|
||||
Object finalValue = assertMapper("compose HashRange(0,100) -> int", intermediateCycle);
|
||||
assertInteger(finalValue, finalCycle);
|
||||
assertThat(finalValue).isEqualTo(16);
|
||||
|
||||
Object finalChainedValue = assertMapper("compose HashRange(0,100); HashRange(0,100) -> int", initialCycle);
|
||||
assertInteger(finalChainedValue, finalCycle);
|
||||
assertThat(finalChainedValue).isEqualTo(16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeadingIdentityDoesNotImpactTypes()
|
||||
{
|
||||
final int initialCycle = 0;
|
||||
final int finalCycle = 167;
|
||||
final int finalCycle = 160;
|
||||
|
||||
Object o1 = assertMapper("compose HashRange(0,1000); HashRange(0,1000) -> int", initialCycle);
|
||||
assertInteger(o1, finalCycle);
|
||||
|
@ -102,7 +102,7 @@ public class IntegratedComposerLogicTest {
|
||||
DataMapper<Long> longDataMapper = mo.get();
|
||||
Long result = longDataMapper.get(5L);
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result).isEqualTo(1398623797L);
|
||||
assertThat(result).isEqualTo(359183748L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -35,7 +35,7 @@ public class IntegratedTemporalExamplesTest {
|
||||
);
|
||||
UUID uuid1 = uuidgen.get(1L);
|
||||
System.out.println(uuid1);
|
||||
assertThat(uuid1).isEqualTo(UUID.fromString("998ccf20-ee50-1398-8000-000000000000"));
|
||||
assertThat(uuid1).isEqualTo(UUID.fromString("826476e0-ee50-1398-8000-000000000000"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +87,7 @@ public class IntegratedTemporalExamplesTest {
|
||||
);
|
||||
Date date = dateMapper.get(3L);
|
||||
|
||||
assertThat(date).isEqualTo(new Date(2527683L));
|
||||
assertThat(date).isEqualTo(new Date(1539133L));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,10 +107,10 @@ public class IntegratedTemporalExamplesTest {
|
||||
1970,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
2,
|
||||
43,
|
||||
10,
|
||||
106,
|
||||
27,
|
||||
245,
|
||||
DateTimeZone.UTC)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user