mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
improve ToDate semantics and docs
This commit is contained in:
parent
0edbfb1f26
commit
9403f51f3a
@ -38,25 +38,30 @@ package io.nosqlbench.virtdata.library.basics.shared.from_long.to_time_types;
|
||||
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.Example;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.function.LongFunction;
|
||||
|
||||
/**
|
||||
* Convert the input value to a {@code Date}
|
||||
* Convert the input value to a {@code Date}, by multiplying and then dividing
|
||||
* the input by the provided parameters.
|
||||
*/
|
||||
@ThreadSafeMapper
|
||||
@Categories({Category.datetime})
|
||||
public class ToDate implements LongFunction<Date> {
|
||||
|
||||
private long spacing;
|
||||
private long repeat_count;
|
||||
private final long spacing;
|
||||
private final long repeat_count;
|
||||
|
||||
public ToDate(int spacing, int repeat_count){
|
||||
this.spacing = spacing;
|
||||
this.repeat_count = repeat_count;
|
||||
@Example({"ToDate(86400000,2)","produce two Date values per day"})
|
||||
public ToDate(int millis_multiplier, int millis_divisor){
|
||||
this.spacing = millis_multiplier;
|
||||
this.repeat_count = millis_divisor;
|
||||
}
|
||||
|
||||
@Example({"ToDate(86400000)","produce a single Date() per day"})
|
||||
public ToDate(int spacing){
|
||||
this(spacing, 1);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package io.nosqlbench.virtdata.library.basics.shared.from_long.to_time_types;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ToDateTest {
|
||||
|
||||
@Test
|
||||
public void testToDateSimple() {
|
||||
ToDate f = new ToDate(5);
|
||||
assertThat(f.apply(0)).isEqualTo(new Date(0));
|
||||
assertThat(f.apply(1)).isEqualTo(new Date(5));
|
||||
assertThat(f.apply(100)).isEqualTo(new Date(500));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToDateWithRepeats() {
|
||||
ToDate f = new ToDate(86400000,2);
|
||||
assertThat(f.apply(0)).isEqualTo(new Date(0));
|
||||
assertThat(f.apply(1)).isEqualTo(new Date((86400000/2)));
|
||||
assertThat(f.apply(2)).isEqualTo(new Date((2*86400000)/2));
|
||||
assertThat(f.apply(3)).isEqualTo(new Date((3*86400000)/2));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user