<commit_before>package com.annimon.stream;

import com.annimon.stream.function.*;
import java.math.BigInteger;
import java.util.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;

/**
 * Tests {@code Stream}.
 * 
 * @see com.annimon.stream.Stream
 */
public class StreamTest {
    
    @Test
    public void testStreamOfList() {
        final PrintConsumer consumer = new PrintConsumer();
        final List<String> list = new ArrayList<String>(4);
        list.add("This");
        list.add(" is ");
        list.add("a");
        list.add(" test");
        
        Stream.of(list)
                .forEach(consumer);
        assertEquals("This is a test", consumer.toString());
    }
    
    @Test
    public void testStreamOfMap() {
        final PrintConsumer consumer = new PrintConsumer();
        final Map<String, Integer> map = new HashMap<String, Integer>(4);
        map.put("This", 1);
        map.put(" is ", 2);
        map.put("a", 3);
        map.put(" test", 4);
        
        long count = Stream.of(map)
                .sortBy(Functions.<String, Integer>entryValue())
                .map(Functions.<String, Integer>entryKey())
                .peek(consumer)
                .count();
        assertEquals(4, count);
        assertEquals("This is a test", consumer.toString());
    }
    
    @Test
    public void testStreamOfIterator() {
        final PrintConsumer consumer = new PrintConsumer();
        long count = Stream.of(Functions.counterIterator())
                .limit(5)
                .peek(consumer)
                .count();
        assertEquals(5, count);
        assertEquals("01234", consumer.toString());
    }
    
    @Test
    public void testStreamOfIterable() {
        final PrintConsumer consumer = new PrintConsumer();
        Iterable<Integer> iterable = new Iterable<Integer>() {
            @Override
            public Iterator<Integer> iterator() {
                return Functions.counterIterator();
            }
        };
        
        long count = Stream.of(iterable)
                .limit(5)
                .peek(consumer)
                .count();
        assertEquals(5, count);
        assertEquals("01234", consumer.toString());
    }
    
    @Test
    public void testStreamRange() {
        final PrintConsumer consumer = new PrintConsumer();
        Stream.range(0, 5)
                .forEach(consumer);
        assertEquals("01234", consumer.toString());
    }
    
    @Test
    public void testStreamRangeOnMaxValues() {
        long count = Stream.range(Integer.MAX_VALUE - 10, Integer.MAX_VALUE).count();
        assertEquals(10L, count);
    }
    
    @Test
    public void testStreamRangeOnMaxLongValues() {
        long count = Stream.range(Long.MAX_VALUE - 10, Long.MAX_VALUE).count();
        assertEquals(10L, count);
    }
    
    @Test
    public void testStreamRangeClosed() {
        final PrintConsumer consumer = new PrintConsumer();
        Stream.rangeClosed(0, 5)
                .forEach(consumer);
        assertEquals("012345", consumer.toString());
    }
    
    @Test
    public void testStreamRangeClosedOnMaxValues() {
        long count = Stream.rangeClosed(Integer.MAX_VALUE - 10, Integer.MAX_VALUE).count();
        assertEquals(11L, count);
    }
    
    @Test
    public void testStreamRangeClosedOnMaxLongValues() {
        long count = Stream.rangeClosed(Long.MAX_VALUE - 10, Long.MAX_VALUE).count();
        assertEquals(11L, count);
    }
    
    @Test
    public void testGenerate() {
        List<Long> expected = Arrays.asList(0L, 1L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L);
        List<Long> data = Stream.generate(Functions.fibonacci())
                .limit(10)
                .collect(Collectors.<Long>toList());
        assertThat(data, is(expected));
    }
    
    @Test
    public void testIterate() {
        final BigInteger two = BigInteger.valueOf(2);
        BigInteger sum = Stream
                .iterate(BigInteger.ONE, new UnaryOperator<BigInteger>() {
                    @Override
                    public BigInteger apply(BigInteger value) {
                        return value.multiply(two);
                    }
                })
                .limit(100)
                .reduce(BigInteger.ZERO, new BinaryOperator<BigInteger>() {
                    @Override
                    public BigInteger apply(BigInteger value1, BigInteger value2) {
                        return value1.add(value2);
                    }
                });
        assertEquals(new BigInteger("1267650600228229401496703205375"), sum);<commit_msg>Add tests for deprecated Stream.ofRange<commit_after>package com.annimon.stream;

import com.annimon.stream.function.*;
import java.math.BigInteger;
import java.util.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;

/**
 * Tests {@code Stream}.
 * 
 * @see com.annimon.stream.Stream
 */
public class StreamTest {
    
    @Test
    public void testStreamOfList() {
        final PrintConsumer consumer = new PrintConsumer();
        final List<String> list = new ArrayList<String>(4);
        list.add("This");
        list.add(" is ");
        list.add("a");
        list.add(" test");
        
        Stream.of(list)
                .forEach(consumer);
        assertEquals("This is a test", consumer.toString());
    }
    
    @Test
    public void testStreamOfMap() {
        final PrintConsumer consumer = new PrintConsumer();
        final Map<String, Integer> map = new HashMap<String, Integer>(4);
        map.put("This", 1);
        map.put(" is ", 2);
        map.put("a", 3);
        map.put(" test", 4);
        
        long count = Stream.of(map)
                .sortBy(Functions.<String, Integer>entryValue())
                .map(Functions.<String, Integer>entryKey())
                .peek(consumer)
                .count();
        assertEquals(4, count);
        assertEquals("This is a test", consumer.toString());
    }
    
    @Test
    public void testStreamOfIterator() {
        final PrintConsumer consumer = new PrintConsumer();
        long count = Stream.of(Functions.counterIterator())
                .limit(5)
                .peek(consumer)
                .count();
        assertEquals(5, count);
        assertEquals("01234", consumer.toString());
    }
    
    @Test
    public void testStreamOfIterable() {
        final PrintConsumer consumer = new PrintConsumer();
        Iterable<Integer> iterable = new Iterable<Integer>() {
            @Override
            public Iterator<Integer> iterator() {
                return Functions.counterIterator();
            }
        };
        
        long count = Stream.of(iterable)
                .limit(5)
                .peek(consumer)
                .count();
        assertEquals(5, count);
        assertEquals("01234", consumer.toString());
    }
    
    @Test
    public void testStreamRange() {
        final PrintConsumer consumer = new PrintConsumer();
        Stream.range(0, 5)
                .forEach(consumer);
        assertEquals("01234", consumer.toString());
    }
    
    @Test
    public void testStreamRangeOnMaxValues() {
        long count = Stream.range(Integer.MAX_VALUE - 10, Integer.MAX_VALUE).count();
        assertEquals(10L, count);
    }
    
    @Test
    public void testStreamRangeOnMaxLongValues() {
        long count = Stream.range(Long.MAX_VALUE - 10, Long.MAX_VALUE).count();
        assertEquals(10L, count);
    }
    
    @Test
    public void testStreamRangeClosed() {
        final PrintConsumer consumer = new PrintConsumer();
        Stream.rangeClosed(0, 5)
                .forEach(consumer);
        assertEquals("012345", consumer.toString());
    }
    
    @Test
    public void testStreamRangeClosedOnMaxValues() {
        long count = Stream.rangeClosed(Integer.MAX_VALUE - 10, Integer.MAX_VALUE).count();
        assertEquals(11L, count);
    }
    
    @Test
    public void testStreamRangeClosedOnMaxLongValues() {
        long count = Stream.rangeClosed(Long.MAX_VALUE - 10, Long.MAX_VALUE).count();
        assertEquals(11L, count);
    }
    
    @Test
    public void testStreamOfRange() {
        long count = Stream.ofRange(0, 5).count();
        assertEquals(5, count);
    }
    
    @Test
    public void testStreamOfRangeLong() {
        long count = Stream.ofRange(Long.MAX_VALUE - 10, Long.MAX_VALUE).count();
        assertEquals(10L, count);
    }
    
    @Test
    public void testStreamOfRangeClosed() {
        long count = Stream.ofRangeClosed(0, 5).count();
        assertEquals(6, count);
    }
    
    @Test
    public void testStreamOfRangeClosedLong() {
        long count = Stream.ofRangeClosed(Long.MAX_VALUE - 10, Long.MAX_VALUE).count();
        assertEquals(11L, count);
    }
    
    @Test
    public void testGenerate() {
        List<Long> expected = Arrays.asList(0L, 1L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L);
        List<Long> data = Stream.generate(Functions.fibonacci())
                .limit(10)
                .collect(Collectors.<Long>toList());
        assertThat(data, is(expected));
    }
    
    @Test
    public void testIterate() {
        final BigInteger two = BigInteger.valueOf(2);
        BigInteger sum = Stream
                .iterate(BigInteger.ONE, new UnaryOperator<BigInteger>() {
                    @Override
                    public BigInteger apply(BigInteger value) {
                        return value.multiply(two);
                    }
                })
                .limit(100)
                .reduce(BigInteger.ZERO, new BinaryOperator<BigInteger>() {
                    @Override
                    public BigInteger apply(BigInteger value1, BigInteger value2) {
                        return value1.add(value2);
                    }
                });
        assertEquals(new BigInteger("1267650600228229401496703205375"), sum);
{'fraction_non_alphanumeric': 0.11596385542168675, 'fraction_numerical': 0.022690763052208834, 'mean_word_length': 1.9505331753554502, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1453887', 'n_tokens_mistral': 2883, 'n_tokens_neox': 2645, 'n_words': 591}