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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import nl.mvdr.tinustris.engine.level.DummyLevelSystem;
import nl.mvdr.tinustris.engine.speedcurve.ConstantSpeedCurve;
import nl.mvdr.tinustris.engine.speedcurve.GameBoySpeedCurve;
import nl.mvdr.tinustris.input.DummyInputController;
import nl.mvdr.tinustris.input.Input;
import nl.mvdr.tinustris.input.InputState;
import nl.mvdr.tinustris.input.InputStateHistory;
import nl.mvdr.tinustris.model.GameState;
import nl.mvdr.tinustris.model.Orientation;
import nl.mvdr.tinustris.model.Point;
import nl.mvdr.tinustris.model.Tetromino;

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

/**
 * Test class for {@link TinustrisEngine}.
 * 
 * @author <NAME>
 */
@Slf4j
public class TinustrisEngineTest {
    /** Tests the constructor. */
    @Test
    public void testDefaultConstructor() {
        new TinustrisEngine();
    }
    
    /** Tests the constructor. */
    @Test
    public void testConstructor() {
        new TinustrisEngine(new DummyTetrominoGenerator(), new ConstantSpeedCurve(), new DummyLevelSystem());
    }
    
    /** Tests the constructor. */
    @Test(expected = NullPointerException.class)
    public void testConstructorNullGenerator() {
        new TinustrisEngine(null, new ConstantSpeedCurve(), new DummyLevelSystem());
    }
    
    /** Tests the constructor. */
    @Test(expected = NullPointerException.class)
    public void testConstructorNullCurve() {
        new TinustrisEngine(new DummyTetrominoGenerator(), null, new DummyLevelSystem());
    }
    
    /** Tests the constructor. */
    @Test(expected = NullPointerException.class)
    public void testConstructorNullLevelSystem() {
        new TinustrisEngine(new DummyTetrominoGenerator(), new ConstantSpeedCurve(), null);
    }
    
    /** Tests the {@link TinustrisEngine#initGameState()} method. */
    @Test
    public void testInitGameState() {
        TetrominoGenerator generator = new DummyTetrominoGenerator(Tetromino.I, Tetromino.T);
        TinustrisEngine engine = new TinustrisEngine(generator, new ConstantSpeedCurve(), new DummyLevelSystem());
        
        GameState state = engine.initGameState();
        
        log.info(state.toString());
        Assert.assertNotNull(state);
        Assert.assertFalse(state.isTopped());
        Assert.assertEquals(GameState.DEFAULT_WIDTH, state.getWidth());
        Assert.assertEquals(GameState.DEFAULT_HEIGHT, state.getHeight());
        Assert.assertEquals(Tetromino.I, state.getCurrentBlock());
        Assert.assertEquals(Tetromino.T, state.getNextBlock());
    }
    
    /** Tests the {@link TinustrisEngine#computeNextState(GameState, nl.mvdr.tinustris.input.InputState)} method. */
    @Test
    public void testNextState() {
        TetrominoGenerator generator = new DummyTetrominoGenerator();
        TinustrisEngine engine = new TinustrisEngine(generator, new ConstantSpeedCurve(), new DummyLevelSystem());
        GameState state = new GameState();
        InputState inputState = new DummyInputController().getInputState();
        
        state = engine.computeNextState(state, inputState);

        log.info(state.toString());
        Assert.assertNotNull(state);
    }
    
    /**
     * Tests the {@link TinustrisEngine#computeNextState(GameState, nl.mvdr.tinustris.input.InputState)} method with a
     * hard drop input.
     */
    @Test
    public void testNextStateHardDrop() {
        TetrominoGenerator generator = new DummyTetrominoGenerator();
        TinustrisEngine engine = new TinustrisEngine(generator, new ConstantSpeedCurve(), new DummyLevelSystem());
        GameState state = createGameStateForHardDropTest();
        log.info("Before: " + state);
        InputState inputState = new DummyInputController(Collections.singleton(Input.HARD_DROP)).getInputState();
        
        state = engine.computeNextState(state, inputState);

        log.info("After: " + state);
        Assert.assertNotNull(state);
    }
    
    /**
     * Tests the {@link TinustrisEngine#computeNextState(GameState, nl.mvdr.tinustris.input.InputState)} method with a
     * hard drop input and a Game Boy speed curve.
     */
    @Test
    public void testNextStateHardDropGameBoyCurve() {
        TetrominoGenerator generator = new DummyTetrominoGenerator();
        TinustrisEngine engine = new TinustrisEngine(generator, new GameBoySpeedCurve(), new DummyLevelSystem());
        GameState state = createGameStateForHardDropTest();
        log.info("Before: " + state);
        InputState inputState = new DummyInputController(Collections.singleton(Input.HARD_DROP)).getInputState();
        
        state = engine.computeNextState(state, inputState);

        log.info("After: " + state);
        Assert.assertNotNull(state);
    }

    /**
     * Creates the game state for the hard drop test cases.
     * 
     * @return newly created game state
     */
    private GameState createGameStateForHardDropTest() {
        List<Tetromino> grid = new ArrayList<>();
        for (int i = 0; i != 220; i++) {
            grid.add(null);
        }
        grid.set(1, Tetromino.O);
        grid.set(2, Tetromino.O);
        grid.set(3, Tetromino.S);
        grid.set(4, Tetromino.Z);
        grid.set(5, Tetromino.O);
        grid.set(6, Tetromino.O);
        grid.set(7, Tetromino.J);
        grid.set(8, Tetromino.J);
        grid.set(9, Tetromino.L);
        grid.set(12, Tetromino.S);
        grid.set(13, Tetromino.S);
        grid.set(18, Tetromino.J);
        grid.set(22, Tetromino.S);
        grid.set(28, Tetromino.J);
        GameState state = new GameState(grid, 10, Tetromino.O, new Point(5, 13), Orientation.FLAT_DOWN, Tetromino.I,
                11, 0, 11, new InputStateHistory(), 236, 93, 0);
        return state;
    }
}
<commit_msg>Simplification.<commit_after>package nl.mvdr.tinustris.engine;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import nl.mvdr.tinustris.engine.level.DummyLevelSystem;
import nl.mvdr.tinustris.engine.speedcurve.ConstantSpeedCurve;
import nl.mvdr.tinustris.engine.speedcurve.GameBoySpeedCurve;
import nl.mvdr.tinustris.input.DummyInputController;
import nl.mvdr.tinustris.input.Input;
import nl.mvdr.tinustris.input.InputState;
import nl.mvdr.tinustris.input.InputStateHistory;
import nl.mvdr.tinustris.model.GameState;
import nl.mvdr.tinustris.model.Orientation;
import nl.mvdr.tinustris.model.Point;
import nl.mvdr.tinustris.model.Tetromino;

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

/**
 * Test class for {@link TinustrisEngine}.
 * 
 * @author <NAME>
 */
@Slf4j
public class TinustrisEngineTest {
    /** Tests the constructor. */
    @Test
    public void testDefaultConstructor() {
        new TinustrisEngine();
    }
    
    /** Tests the constructor. */
    @Test
    public void testConstructor() {
        new TinustrisEngine(new DummyTetrominoGenerator(), new ConstantSpeedCurve(), new DummyLevelSystem());
    }
    
    /** Tests the constructor. */
    @Test(expected = NullPointerException.class)
    public void testConstructorNullGenerator() {
        new TinustrisEngine(null, new ConstantSpeedCurve(), new DummyLevelSystem());
    }
    
    /** Tests the constructor. */
    @Test(expected = NullPointerException.class)
    public void testConstructorNullCurve() {
        new TinustrisEngine(new DummyTetrominoGenerator(), null, new DummyLevelSystem());
    }
    
    /** Tests the constructor. */
    @Test(expected = NullPointerException.class)
    public void testConstructorNullLevelSystem() {
        new TinustrisEngine(new DummyTetrominoGenerator(), new ConstantSpeedCurve(), null);
    }
    
    /** Tests the {@link TinustrisEngine#initGameState()} method. */
    @Test
    public void testInitGameState() {
        TetrominoGenerator generator = new DummyTetrominoGenerator(Tetromino.I, Tetromino.T);
        TinustrisEngine engine = new TinustrisEngine(generator, new ConstantSpeedCurve(), new DummyLevelSystem());
        
        GameState state = engine.initGameState();
        
        log.info(state.toString());
        Assert.assertNotNull(state);
        Assert.assertFalse(state.isTopped());
        Assert.assertEquals(GameState.DEFAULT_WIDTH, state.getWidth());
        Assert.assertEquals(GameState.DEFAULT_HEIGHT, state.getHeight());
        Assert.assertEquals(Tetromino.I, state.getCurrentBlock());
        Assert.assertEquals(Tetromino.T, state.getNextBlock());
    }
    
    /** Tests the {@link TinustrisEngine#computeNextState(GameState, nl.mvdr.tinustris.input.InputState)} method. */
    @Test
    public void testNextState() {
        TetrominoGenerator generator = new DummyTetrominoGenerator();
        TinustrisEngine engine = new TinustrisEngine(generator, new ConstantSpeedCurve(), new DummyLevelSystem());
        GameState state = new GameState();
        InputState inputState = new DummyInputController().getInputState();
        
        state = engine.computeNextState(state, inputState);

        log.info(state.toString());
        Assert.assertNotNull(state);
    }
    
    /**
     * Tests the {@link TinustrisEngine#computeNextState(GameState, nl.mvdr.tinustris.input.InputState)} method with a
     * hard drop input.
     */
    @Test
    public void testNextStateHardDrop() {
        TetrominoGenerator generator = new DummyTetrominoGenerator();
        TinustrisEngine engine = new TinustrisEngine(generator, new ConstantSpeedCurve(), new DummyLevelSystem());
        GameState state = createGameStateForHardDropTest();
        log.info("Before: " + state);
        InputState inputState = new DummyInputController(Collections.singleton(Input.HARD_DROP)).getInputState();
        
        state = engine.computeNextState(state, inputState);

        log.info("After: " + state);
        Assert.assertNotNull(state);
    }
    
    /**
     * Tests the {@link TinustrisEngine#computeNextState(GameState, nl.mvdr.tinustris.input.InputState)} method with a
     * hard drop input and a Game Boy speed curve.
     */
    @Test
    public void testNextStateHardDropGameBoyCurve() {
        TetrominoGenerator generator = new DummyTetrominoGenerator();
        TinustrisEngine engine = new TinustrisEngine(generator, new GameBoySpeedCurve(), new DummyLevelSystem());
        GameState state = createGameStateForHardDropTest();
        log.info("Before: " + state);
        InputState inputState = new DummyInputController(Collections.singleton(Input.HARD_DROP)).getInputState();
        
        state = engine.computeNextState(state, inputState);

        log.info("After: " + state);
        Assert.assertNotNull(state);
    }

    /**
     * Creates the game state for the hard drop test cases.
     * 
     * @return newly created game state
     */
    private GameState createGameStateForHardDropTest() {
        List<Tetromino> grid = new ArrayList<>(220);
        while (grid.size() != 220) {
            grid.add(null);
        }
        grid.set(1, Tetromino.O);
        grid.set(2, Tetromino.O);
        grid.set(3, Tetromino.S);
        grid.set(4, Tetromino.Z);
        grid.set(5, Tetromino.O);
        grid.set(6, Tetromino.O);
        grid.set(7, Tetromino.J);
        grid.set(8, Tetromino.J);
        grid.set(9, Tetromino.L);
        grid.set(12, Tetromino.S);
        grid.set(13, Tetromino.S);
        grid.set(18, Tetromino.J);
        grid.set(22, Tetromino.S);
        grid.set(28, Tetromino.J);
        GameState state = new GameState(grid, 10, Tetromino.O, new Point(5, 13), Orientation.FLAT_DOWN, Tetromino.I,
                11, 0, 11, new InputStateHistory(), 236, 93, 0);
        return state;
    }
}

{'fraction_non_alphanumeric': 0.11400153022188217, 'fraction_numerical': 0.007311060103715039, 'mean_word_length': 3.1686746987951806, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5400604', 'n_tokens_mistral': 3652, 'n_tokens_neox': 3539, 'n_words': 700}