<commit_before>package com.github.davidmoten.rx.operators;

import static org.junit.Assert.assertEquals;
import static rx.Observable.from;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.junit.Test;

import rx.Observable;
import rx.functions.Func2;

import com.github.davidmoten.rx.Transformers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

public class OperatorOrderedMergeTest {

    private static final Func2<Integer, Integer, Integer> comparator = new Func2<Integer, Integer, Integer>() {
        @Override
        public Integer call(Integer a, Integer b) {
            return a.compareTo(b);
        }
    };

    @Test
    public void testMerge() {
        // hang on to one stand-alone test like this so we can customize for
        // failure cases arriving out of testWithAllCombinationsFromPowerSet
        Observable<Integer> o1 = Observable.just(1, 2, 4, 10);
        Observable<Integer> o2 = Observable.just(3, 5, 11);
        check(o1, o2, 1, 2, 3, 4, 5, 10, 11);
    }

    @Test
    public void testWithAllCombinationsFromPowerSet() {
        // this test covers everything!
        for (int n = 0; n <= 10; n++) {
            Set<Integer> numbers = Sets.newTreeSet();
            for (int i = 1; i <= n; i++) {
                numbers.add(i);
            }
            for (Set<Integer> a : Sets.powerSet(numbers)) {
                TreeSet<Integer> x = Sets.newTreeSet(a);
                TreeSet<Integer> y = Sets.newTreeSet(Sets.difference(numbers, x));
                Observable<Integer> o1 = from(x);
                Observable<Integer> o2 = from(y);<commit_msg>add async test for ordered merge<commit_after>package com.github.davidmoten.rx.operators;

import static org.junit.Assert.assertEquals;
import static rx.Observable.from;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

import rx.Observable;
import rx.Scheduler;
import rx.functions.Func2;
import rx.schedulers.Schedulers;

import com.github.davidmoten.rx.Transformers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

public class OperatorOrderedMergeTest {

    private static final Func2<Integer, Integer, Integer> comparator = new Func2<Integer, Integer, Integer>() {
        @Override
        public Integer call(Integer a, Integer b) {
            return a.compareTo(b);
        }
    };

    @Test
    public void testMerge() {
        // hang on to one stand-alone test like this so we can customize for
        // failure cases arriving out of testWithAllCombinationsFromPowerSet
        Observable<Integer> o1 = Observable.just(1, 2, 4, 10);
        Observable<Integer> o2 = Observable.just(3, 5, 11);
        check(o1, o2, 1, 2, 3, 4, 5, 10, 11);
    }

    @Test
    public void testWithAllCombinationsFromPowerSet() {
        checkAllCombinationsFromPowerSet(Schedulers.immediate());
    }

    @Test
    public void testWithAllCombinationsFromPowerSetAsync() {
        long t = System.currentTimeMillis();
        while (System.currentTimeMillis() - t <= TimeUnit.SECONDS.toMillis(5)) {
            checkAllCombinationsFromPowerSet(Schedulers.computation());
        }
    }

    private void checkAllCombinationsFromPowerSet(Scheduler scheduler) {
        // this test covers everything!
        for (int n = 0; n <= 10; n++) {
            Set<Integer> numbers = Sets.newTreeSet();
            for (int i = 1; i <= n; i++) {
                numbers.add(i);
            }
            for (Set<Integer> a : Sets.powerSet(numbers)) {
                TreeSet<Integer> x = Sets.newTreeSet(a);
                TreeSet<Integer> y = Sets.newTreeSet(Sets.difference(numbers, x));
                Observable<Integer> o1 = from(x).subscribeOn(scheduler);
                Observable<Integer> o2 = from(y).subscribeOn(scheduler);
{'fraction_non_alphanumeric': 0.11150442477876106, 'fraction_numerical': 0.01592920353982301, 'mean_word_length': 2.7285579641847315, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '378985', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1181, 'n_words': 301}