<commit_before>package nl.mvdr.tinustris.engine;

import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nl.mvdr.tinustris.model.Tetromino;

import org.junit.Assert;
import org.junit.Test;

/**
 * Test class for {@link RandomTetrominoGenerator}.
 * 
 * @author <NAME>
 */
public class RandomTetrominoGeneratorTest {
    /** Random seed. */
    private static final long SEED = 693741264L;
    /** The number of threads in the executor service used for concurrency tests. */
    int NUM_THREADS = 5;
    
    /** Invokes the get method a few times and checks that it returns non-null values. */
    @Test
    public void testGet() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        for (int i = 0; i != 10; i++) {
            Assert.assertNotNull("failed on i = " + i, generator.get(i));
        }
    }
    
    /** Tests that the get method returns the same value when invoked with the same index multiple times. */
    @Test
    public void testGetMultipleCalls() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Tetromino first = generator.get(0);
        
        Assert.assertEquals(first, generator.get(0));
    }
    
    /**
     * Tests that the get method returns the same value when invoked with the same index multiple times, even when other
     * indices have been used as well.
     */
    @Test
    public void testGetMultipleCallsLater() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Tetromino first = generator.get(0);
        generator.get(1);
        generator.get(2);
        
        Assert.assertEquals(first, generator.get(0));
    }
    
    /**
     * Tests that the get method works correctly when skipping a tetromino index (even though this should never happen
     * in practice).
     */
    @Test
    public void testGetSkipValue() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Assert.assertNotNull(generator.get(1));
    }
    
    /**
     * Tests that the get method works correctly when skipping a tetromino index (even though this should never happen
     * in practice).
     */
    @Test
    public void testGetSkipValueMultipleTimes() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Tetromino first = generator.get(1);
        
        Assert.assertEquals(first, generator.get(1));
    }
    
    /** Test case with a negative index. */
    @Test(expected = IndexOutOfBoundsException.class)
    public void testNegativeValue() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        generator.get(-1);
    }
    
    /** Tests that reusing the same random seed produces the same results. */
    @Test
    public void testRandomSeed() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator(0L);
        Tetromino first = generator.get(0);
        generator = new RandomTetrominoGenerator(0L);
        
        Assert.assertEquals(first, generator.get(0));
    }
    
    /** Tests that reusing the same random seed in a new JVM instance still produces the same result. */
    @Test
    public void testRandomSeedFixed() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator(0L);
        
        Assert.assertEquals(Tetromino.S, generator.get(0));
        Assert.assertEquals(Tetromino.T, generator.get(1));
        Assert.assertEquals(Tetromino.L, generator.get(2));
        Assert.assertEquals(Tetromino.T, generator.get(3));
        Assert.assertEquals(Tetromino.L, generator.get(4));
        Assert.assertEquals(Tetromino.I, generator.get(5));
        Assert.assertEquals(Tetromino.T, generator.get(6));
        Assert.assertEquals(Tetromino.O, generator.get(7));
        Assert.assertEquals(Tetromino.Z, generator.get(8));
        Assert.assertEquals(Tetromino.T, generator.get(9));
    }
    
    /** Tests whether generators with the same random seed also result in the same value. */
    @Test
    public void testRepeatable() {
        RandomTetrominoGenerator generator0 = new RandomTetrominoGenerator(SEED);
        RandomTetrominoGenerator generator1 = new RandomTetrominoGenerator(SEED);
        
        Tetromino tetromino0 = generator0.get(10_000);
        Tetromino tetromino1 = generator1.get(10_000);
        
        Assert.assertEquals(tetromino0, tetromino1);
    }

    /**
     * Test case where {@link RandomTetrominoGenerator#get(int)} is called from several different threads. We expect
     * each call to return the same tetromino.
     * 
     * @throws ExecutionException
     *             unexpected exception
     * @throws InterruptedException
     *             unexpected exception
     */
    @Test
    public void testGetMultiThreaded() throws ExecutionException, InterruptedException {
        // repeat the test a few times, to increase the likelyhood of failure in case of synchronisation bugs
        for (int i = 0; i != 100; i++) {<commit_msg>Reduced the number of times tetrominoes are generated in these tests, in order to reduce command line build times.<commit_after>package nl.mvdr.tinustris.engine;

import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nl.mvdr.tinustris.model.Tetromino;

import org.junit.Assert;
import org.junit.Test;

/**
 * Test class for {@link RandomTetrominoGenerator}.
 * 
 * @author <NAME>
 */
public class RandomTetrominoGeneratorTest {
    /** Random seed. */
    private static final long SEED = 693741264L;
    /** The number of threads in the executor service used for concurrency tests. */
    int NUM_THREADS = 5;
    
    /** Invokes the get method a few times and checks that it returns non-null values. */
    @Test
    public void testGet() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        for (int i = 0; i != 10; i++) {
            Assert.assertNotNull("failed on i = " + i, generator.get(i));
        }
    }
    
    /** Tests that the get method returns the same value when invoked with the same index multiple times. */
    @Test
    public void testGetMultipleCalls() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Tetromino first = generator.get(0);
        
        Assert.assertEquals(first, generator.get(0));
    }
    
    /**
     * Tests that the get method returns the same value when invoked with the same index multiple times, even when other
     * indices have been used as well.
     */
    @Test
    public void testGetMultipleCallsLater() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Tetromino first = generator.get(0);
        generator.get(1);
        generator.get(2);
        
        Assert.assertEquals(first, generator.get(0));
    }
    
    /**
     * Tests that the get method works correctly when skipping a tetromino index (even though this should never happen
     * in practice).
     */
    @Test
    public void testGetSkipValue() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Assert.assertNotNull(generator.get(1));
    }
    
    /**
     * Tests that the get method works correctly when skipping a tetromino index (even though this should never happen
     * in practice).
     */
    @Test
    public void testGetSkipValueMultipleTimes() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        Tetromino first = generator.get(1);
        
        Assert.assertEquals(first, generator.get(1));
    }
    
    /** Test case with a negative index. */
    @Test(expected = IndexOutOfBoundsException.class)
    public void testNegativeValue() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator();
        generator.get(-1);
    }
    
    /** Tests that reusing the same random seed produces the same results. */
    @Test
    public void testRandomSeed() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator(0L);
        Tetromino first = generator.get(0);
        generator = new RandomTetrominoGenerator(0L);
        
        Assert.assertEquals(first, generator.get(0));
    }
    
    /** Tests that reusing the same random seed in a new JVM instance still produces the same result. */
    @Test
    public void testRandomSeedFixed() {
        RandomTetrominoGenerator generator = new RandomTetrominoGenerator(0L);
        
        Assert.assertEquals(Tetromino.S, generator.get(0));
        Assert.assertEquals(Tetromino.T, generator.get(1));
        Assert.assertEquals(Tetromino.L, generator.get(2));
        Assert.assertEquals(Tetromino.T, generator.get(3));
        Assert.assertEquals(Tetromino.L, generator.get(4));
        Assert.assertEquals(Tetromino.I, generator.get(5));
        Assert.assertEquals(Tetromino.T, generator.get(6));
        Assert.assertEquals(Tetromino.O, generator.get(7));
        Assert.assertEquals(Tetromino.Z, generator.get(8));
        Assert.assertEquals(Tetromino.T, generator.get(9));
    }
    
    /** Tests whether generators with the same random seed also result in the same value. */
    @Test
    public void testRepeatable() {
        RandomTetrominoGenerator generator0 = new RandomTetrominoGenerator(SEED);
        RandomTetrominoGenerator generator1 = new RandomTetrominoGenerator(SEED);
        
        Tetromino tetromino0 = generator0.get(100);
        Tetromino tetromino1 = generator1.get(100);
        
        Assert.assertEquals(tetromino0, tetromino1);
    }

    /**
     * Test case where {@link RandomTetrominoGenerator#get(int)} is called from several different threads. We expect
     * each call to return the same tetromino.
     * 
     * @throws ExecutionException
     *             unexpected exception
     * @throws InterruptedException
     *             unexpected exception
     */
    @Test
    public void testGetMultiThreaded() throws ExecutionException, InterruptedException {
        // repeat the test a few times, to increase the likelyhood of failure in case of synchronisation bugs
        for (int i = 0; i != 100; i++) {
{'fraction_non_alphanumeric': 0.0909005186232909, 'fraction_numerical': 0.010938236680810938, 'mean_word_length': 2.8651603498542273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1922532', 'n_tokens_mistral': 2985, 'n_tokens_neox': 2917, 'n_words': 832}