Search in sources :

Example 1 with SequenceProvider

use of com.milaboratory.core.sequence.provider.SequenceProvider in project repseqio by repseqio.

the class ConcatenatedLazySequenceTest method testRandom0.

public <S extends Sequence<S>> void testRandom0(Alphabet<S> alphabet) throws Exception {
    Well44497b w = new Well44497b();
    S sequence = alphabet.getEmptySequence();
    SequenceProvider<S>[] providers = new SequenceProvider[100];
    for (int i = 0; i < 100; i++) {
        final S seq = TestUtil.randomSequence(alphabet, 0, 200);
        sequence = sequence.concatenate(seq);
        providers[i] = SequenceProviderUtils.fromSequence(seq);
        ConcatenatedLazySequence<S> sProvider = new ConcatenatedLazySequence<>(Arrays.copyOf(providers, i + 1));
        if (sequence.size() == 0)
            continue;
        for (int j = 0; j < 10; j++) {
            int from = sequence.size() == 1 ? 0 : w.nextInt(sequence.size() - 1);
            int to = (sequence.size() - from) == 0 ? from : from + w.nextInt(sequence.size() - from);
            Range r = new Range(from, to);
            if (r.isEmpty())
                continue;
            assertEquals(sequence.getRange(r), sProvider.getRegion(r));
        }
    }
}
Also used : CachedSequenceProvider(com.milaboratory.core.sequence.provider.CachedSequenceProvider) SequenceProvider(com.milaboratory.core.sequence.provider.SequenceProvider) Well44497b(org.apache.commons.math3.random.Well44497b) Range(com.milaboratory.core.Range)

Aggregations

Range (com.milaboratory.core.Range)1 CachedSequenceProvider (com.milaboratory.core.sequence.provider.CachedSequenceProvider)1 SequenceProvider (com.milaboratory.core.sequence.provider.SequenceProvider)1 Well44497b (org.apache.commons.math3.random.Well44497b)1