<commit_before>package com.googlecode.totallylazy;

import org.junit.Test;

import java.lang.*;

import static com.googlecode.totallylazy.Callables.*;
import static com.googlecode.totallylazy.Iterables.list;
import static com.googlecode.totallylazy.Predicates.even;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
import static org.junit.matchers.JUnitMatchers.hasItems;

public class IterableTest {
    @Test
    public void supportsForEach() throws Exception {
        final int[] sum = {0};
        list(1, 2).foreach(new Runnable1<Integer>() {
            public void run(Integer value){
                sum[0] += value;
            }
        });
        assertThat(sum[0], is(3));
    }

    @Test
    public void supportsMap() throws Exception {
        Iterable<String> strings = list(1,2).map(asString(Integer.class));
        assertThat(strings, hasItems("1", "2"));
    }

    @Test
    public void mapIsLazy() throws Exception {
        Iterable<Integer> result = list(returns(1), callThrows(new Exception(), Integer.class)).
                map(invokeCall(Integer.class));
        assertThat(result, hasItem(1));
    }

    @Test
    public void supportsFilter() throws Exception {
        Iterable<Integer> result = list(1,2,3,4).filter(even());
        assertThat(result, hasItems(2,4));
    }

       @Test
    public void filterIsLazy() throws Exception {
        Iterable<Integer> result = list(returns(1), returns(2), callThrows(new Exception(), Integer.class)).
                map(invokeCall(Integer.class)).
                filter(even());
        assertThat(result, hasItem(2));
    }

    @Test
    public void supportsFlatMap() throws Exception {
        Iterable<Integer> result = list(1,2,3).flatMap(new Callable1<Integer, Iterable<Integer>>() {
            public Iterable<Integer> call(Integer value) throws Exception {
                return list(value, value * 3);
            }
        });
        assertThat(result, hasItems(1,2,3,6,9));
    }
}<commit_msg>dan: readded missing tests<commit_after>package com.googlecode.totallylazy;

import org.junit.Test;

import java.lang.*;

import static com.googlecode.totallylazy.Callables.*;
import static com.googlecode.totallylazy.Iterables.list;
import static com.googlecode.totallylazy.Predicates.even;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
import static org.junit.matchers.JUnitMatchers.hasItems;

public class IterableTest {
    @Test
    public void supportsTail() throws Exception {
        assertThat(list(1, 2, 3).tail(), hasItems(2, 3));
    }

    @Test
    public void supportsHead() throws Exception {
        assertThat(list(1, 2).head(), is(1));
    }

    @Test
    public void supportsForEach() throws Exception {
        final int[] sum = {0};
        list(1, 2).foreach(new Runnable1<Integer>() {
            public void run(Integer value) {
                sum[0] += value;
            }
        });
        assertThat(sum[0], is(3));
    }

    @Test
    public void supportsMap() throws Exception {
        Iterable<String> strings = list(1, 2).map(asString(Integer.class));
        assertThat(strings, hasItems("1", "2"));
    }

    @Test
    public void mapIsLazy() throws Exception {
        Iterable<Integer> result = list(returns(1), callThrows(new Exception(), Integer.class)).
                map(invokeCall(Integer.class));
        assertThat(result, hasItem(1));
    }

    @Test
    public void supportsFilter() throws Exception {
        Iterable<Integer> result = list(1, 2, 3, 4).filter(even());
        assertThat(result, hasItems(2, 4));
    }

    @Test
    public void filterIsLazy() throws Exception {
        Iterable<Integer> result = list(returns(1), returns(2), callThrows(new Exception(), Integer.class)).
                map(invokeCall(Integer.class)).
                filter(even());
        assertThat(result, hasItem(2));
    }

    @Test
    public void supportsFlatMap() throws Exception {
        Iterable<Integer> result = list(1, 2, 3).flatMap(new Callable1<Integer, Iterable<Integer>>() {
            public Iterable<Integer> call(Integer value) throws Exception {
                return list(value, value * 3);
            }
        });
        assertThat(result, hasItems(1, 2, 3, 6, 9));
    }
}
{'fraction_non_alphanumeric': 0.12714543812104787, 'fraction_numerical': 0.016260162601626018, 'mean_word_length': 2.8613775065387967, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '3220006', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1291, 'n_words': 292}