<commit_before>package au.gov.amsa.streams;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

import org.junit.Test;

import rx.Observable;
import rx.Subscriber;

public class StringSplitOperatorTest {

	@Test
	public void test() {
		List<String> list = Observable.just("boo:an", "d:you")
				.lift(new StringSplitOperator(Pattern.compile(":"))).toList()
				.toBlocking().single();
		assertEquals(asList("boo", "and", "you"), list);
	}

	@Test
	public void testWithBackpressure() throws InterruptedException {
		final CountDownLatch latch = new CountDownLatch(1);
		final List<String> list = new ArrayList<String>();
		Observable.just("boo:an", "d:you")
				.lift(new StringSplitOperator(Pattern.compile(":")))
				.subscribe(new Subscriber<String>() {

					@Override
					public void onStart() {
						request(1);
					}

					@Override
					public void onCompleted() {
						latch.countDown();
					}

					@Override
					public void onError(Throwable e) {
						e.printStackTrace();
						throw new RuntimeException(e);
					}

					@Override
					public void onNext(String s) {
						list.add(s);
						request(1);
					}
				});
		assertTrue(latch.await(5, TimeUnit.SECONDS));
		assertEquals(asList("boo", "and", "you"), list);
	}
}<commit_msg>add test<commit_after>package au.gov.amsa.streams;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.regex.Pattern;

import org.junit.Test;

import rx.Observable;
import rx.Subscriber;

public class StringSplitOperatorTest {

	@Test
	public void test() {
		Observable<String> o = Observable.just("boo:an", "d:you");
		List<String> expected = asList("boo", "and", "you");
		check(o, expected);
	}

	@Test
	public void testEmptyItemsEmitted() {
		Observable<String> o = Observable.just("::boo:an", "d:::you::");
		List<String> expected = asList("", "", "boo", "and", "", "", "you", "");
		check(o, expected);
	}

	@Test
	public void testWithBackpressure() throws InterruptedException {
		Observable<String> o = Observable.just("boo:an", "d:you");
		List<String> expected = asList("boo", "and", "you");
		checkWithBackpressure(o, expected);
	}

	private static void checkWithBackpressure(Observable<String> o,
			List<String> expected) {
		final List<String> list = new ArrayList<String>();
		o.lift(new StringSplitOperator(Pattern.compile(":"))).subscribe(
				createBackpressureSubscriber(list));
		assertEquals(expected, list);
	}

	private static void check(Observable<String> o, List<String> expected) {
		List<String> list = o
				.lift(new StringSplitOperator(Pattern.compile(":"))).toList()
				.toBlocking().single();
		assertEquals(expected, list);
	}

	private static Subscriber<String> createBackpressureSubscriber(
			final List<String> list) {
		final CountDownLatch latch = new CountDownLatch(1);
		return new Subscriber<String>() {

			@Override
			public void onStart() {
				request(1);
			}

			@Override
			public void onCompleted() {
				latch.countDown();
			}

			@Override
			public void onError(Throwable e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}

			@Override
			public void onNext(String s) {
				list.add(s);
				request(1);
			}
		};
	}
}
{'fraction_non_alphanumeric': 0.1456447963800905, 'fraction_numerical': 0.0019796380090497737, 'mean_word_length': 4.27123695976155, 'pattern_counts': {'":': 5, '<': 23, '<?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': '6203953', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1128, 'n_words': 246}