Search in sources :

Example 11 with Pair

use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.

the class ATimeSeriesDBWithCacheTest method testRandomizedPreviousValues.

@Test
public void testRandomizedPreviousValues() {
    final List<Pair<Integer, Integer>> reproduce = new ArrayList<Pair<Integer, Integer>>();
    try {
        for (int i = 0; i < 100000; i++) {
            final int keyIndex = RandomUtils.nextInt(0, entities.size());
            final int shiftBackUnits = RandomUtils.nextInt(1, Math.max(1, keyIndex));
            reproduce.add(Pair.of(keyIndex, shiftBackUnits));
            final FDate key = entities.get(keyIndex);
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
            if (i % 100 == 0) {
                cache.clear();
                reproduce.clear();
            }
        }
    } catch (final Throwable t) {
        // CHECKSTYLE:OFF
        System.out.println(reproduce.size() + ". step: " + t.toString());
        // CHECKSTYLE:ON
        cache.clear();
        for (int step = 1; step <= reproduce.size(); step++) {
            final Pair<Integer, Integer> keyIndex_shiftBackUnits = reproduce.get(step - 1);
            final int keyIndex = keyIndex_shiftBackUnits.getFirst();
            final int shiftBackUnits = keyIndex_shiftBackUnits.getSecond();
            final FDate key = entities.get(keyIndex);
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            if (step == reproduce.size()) {
                // CHECKSTYLE:OFF
                System.out.println("now");
            // CHECKSTYLE:ON
            }
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) FDate(de.invesdwin.util.time.date.FDate) Pair(de.invesdwin.util.bean.tuple.Pair) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 12 with Pair

use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.

the class ALiveSegmentedTimeSeriesDBWithUnlimitedCacheTest method testRandomizedPreviousValues.

@Test
public void testRandomizedPreviousValues() {
    final List<Pair<Integer, Integer>> reproduce = new ArrayList<Pair<Integer, Integer>>();
    try {
        for (int i = 0; i < 100000; i++) {
            final int keyIndex = RandomUtils.nextInt(0, entities.size());
            final int shiftBackUnits = RandomUtils.nextInt(1, Math.max(1, keyIndex));
            reproduce.add(Pair.of(keyIndex, shiftBackUnits));
            final FDate key = entities.get(keyIndex);
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
            if (i % 100 == 0) {
                cache.clear();
                reproduce.clear();
            }
        }
    } catch (final Throwable t) {
        // CHECKSTYLE:OFF
        System.out.println(reproduce.size() + ". step: " + t.toString());
        // CHECKSTYLE:ON
        cache.clear();
        for (int step = 1; step <= reproduce.size(); step++) {
            final Pair<Integer, Integer> keyIndex_shiftBackUnits = reproduce.get(step - 1);
            final int keyIndex = keyIndex_shiftBackUnits.getFirst();
            final int shiftBackUnits = keyIndex_shiftBackUnits.getSecond();
            final FDate key = entities.get(keyIndex);
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            if (step == reproduce.size()) {
                // CHECKSTYLE:OFF
                System.out.println("now");
            // CHECKSTYLE:ON
            }
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) FDate(de.invesdwin.util.time.date.FDate) Pair(de.invesdwin.util.bean.tuple.Pair) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 13 with Pair

use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.

the class ATimeSeriesDBWithLimitedCacheTest method testRandomizedPreviousValues.

@Test
public void testRandomizedPreviousValues() {
    final List<Pair<Integer, Integer>> reproduce = new ArrayList<Pair<Integer, Integer>>();
    try {
        for (int i = 0; i < 100000; i++) {
            final int keyIndex = RandomUtils.nextInt(0, entities.size());
            final int shiftBackUnits = RandomUtils.nextInt(1, Math.max(1, keyIndex));
            reproduce.add(Pair.of(keyIndex, shiftBackUnits));
            final FDate key = entities.get(keyIndex);
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
            if (i % 100 == 0) {
                cache.clear();
                reproduce.clear();
            }
        }
    } catch (final Throwable t) {
        // CHECKSTYLE:OFF
        System.out.println(reproduce.size() + ". step: " + t.toString());
        // CHECKSTYLE:ON
        cache.clear();
        for (int step = 1; step <= reproduce.size(); step++) {
            final Pair<Integer, Integer> keyIndex_shiftBackUnits = reproduce.get(step - 1);
            final int keyIndex = keyIndex_shiftBackUnits.getFirst();
            final int shiftBackUnits = keyIndex_shiftBackUnits.getSecond();
            final FDate key = entities.get(keyIndex);
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            if (step == reproduce.size()) {
                // CHECKSTYLE:OFF
                System.out.println("now");
            // CHECKSTYLE:ON
            }
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) FDate(de.invesdwin.util.time.date.FDate) Pair(de.invesdwin.util.bean.tuple.Pair) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 14 with Pair

use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.

the class ATimeSeriesDBWithUnlimitedCacheTest method testRandomizedPreviousValues.

@Test
public void testRandomizedPreviousValues() {
    final List<Pair<Integer, Integer>> reproduce = new ArrayList<Pair<Integer, Integer>>();
    try {
        for (int i = 0; i < 100000; i++) {
            final int keyIndex = RandomUtils.nextInt(0, entities.size());
            final int shiftBackUnits = RandomUtils.nextInt(1, Math.max(1, keyIndex));
            reproduce.add(Pair.of(keyIndex, shiftBackUnits));
            final FDate key = entities.get(keyIndex);
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
            if (i % 100 == 0) {
                cache.clear();
                reproduce.clear();
            }
        }
    } catch (final Throwable t) {
        // CHECKSTYLE:OFF
        System.out.println(reproduce.size() + ". step: " + t.toString());
        // CHECKSTYLE:ON
        cache.clear();
        for (int step = 1; step <= reproduce.size(); step++) {
            final Pair<Integer, Integer> keyIndex_shiftBackUnits = reproduce.get(step - 1);
            final int keyIndex = keyIndex_shiftBackUnits.getFirst();
            final int shiftBackUnits = keyIndex_shiftBackUnits.getSecond();
            final FDate key = entities.get(keyIndex);
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            if (step == reproduce.size()) {
                // CHECKSTYLE:OFF
                System.out.println("now");
            // CHECKSTYLE:ON
            }
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) FDate(de.invesdwin.util.time.date.FDate) Pair(de.invesdwin.util.bean.tuple.Pair) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Example 15 with Pair

use of de.invesdwin.util.bean.tuple.Pair in project invesdwin-context-persistence by subes.

the class ALiveSegmentedTimeSeriesDBWithCacheTest method testRandomizedPreviousValues.

@Test
public void testRandomizedPreviousValues() {
    final List<Pair<Integer, Integer>> reproduce = new ArrayList<Pair<Integer, Integer>>();
    try {
        for (int i = 0; i < 100000; i++) {
            final int keyIndex = RandomUtils.nextInt(0, entities.size());
            final int shiftBackUnits = RandomUtils.nextInt(1, Math.max(1, keyIndex));
            reproduce.add(Pair.of(keyIndex, shiftBackUnits));
            final FDate key = entities.get(keyIndex);
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
            if (i % 100 == 0) {
                cache.clear();
                reproduce.clear();
            }
        }
    } catch (final Throwable t) {
        // CHECKSTYLE:OFF
        System.out.println(reproduce.size() + ". step: " + t.toString());
        // CHECKSTYLE:ON
        cache.clear();
        for (int step = 1; step <= reproduce.size(); step++) {
            final Pair<Integer, Integer> keyIndex_shiftBackUnits = reproduce.get(step - 1);
            final int keyIndex = keyIndex_shiftBackUnits.getFirst();
            final int shiftBackUnits = keyIndex_shiftBackUnits.getSecond();
            final FDate key = entities.get(keyIndex);
            final List<FDate> expectedValues = entities.subList(keyIndex - shiftBackUnits + 1, keyIndex + 1);
            if (step == reproduce.size()) {
                // CHECKSTYLE:OFF
                System.out.println("now");
            // CHECKSTYLE:ON
            }
            final Collection<FDate> previousValues = asList(cache.query().getPreviousValues(key, shiftBackUnits));
            Assertions.assertThat(previousValues).isEqualTo(expectedValues);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) FDate(de.invesdwin.util.time.date.FDate) Pair(de.invesdwin.util.bean.tuple.Pair) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

Aggregations

ATest (de.invesdwin.context.test.ATest)18 Pair (de.invesdwin.util.bean.tuple.Pair)18 FDate (de.invesdwin.util.time.date.FDate)18 ArrayList (java.util.ArrayList)18 Collection (java.util.Collection)18 List (java.util.List)18 Test (org.junit.jupiter.api.Test)18 IEvaluateGenericFDate (de.invesdwin.util.math.expression.lambda.IEvaluateGenericFDate)2