<commit_before>import { List } from 'immutable';
import { expect } from 'chai';

import brick from './index.js';
import testAiVsAi from '../../../test/helpers/testAiVsAi';

describe('Reducer: brick', () => {
  describe('case "PICK_SPOT_PLAYER"', () => {
    let initialState;

    beforeEach(() => (initialState = List().setSize(9)));

    it('should occupy a spot on the brick', () => {
      const stateAfter = initialState.set(1, 'x');

      const action = { type: 'PICK_SPOT_PLAYER', player: 'x', spot: 1 };

      expect(brick(initialState, action))
        .to.equal(stateAfter);
    });

    it('should return unchanged if spot is already occupied', () => {
      const stateBefore = initialState.set(5, 'x');
      const stateAfter = initialState.set(5, 'x');
      const action = { type: 'PICK_SPOT_PLAYER', player: 'o', spot: 5 };

      expect(brick(stateBefore, action))
        .to.equal(stateAfter);
    });

    it('should not apply changes if player or spot is not defined, or faulty', () => {
      const stateBefore = initialState.set(5, 'x');

      expect(brick(stateBefore, { type: 'PICK_SPOT_PLAYER', player: 'o' }))
        .to.equal(stateBefore);
      expect(brick(stateBefore, { type: 'PICK_SPOT_PLAYER', spot: 10, player: 'o' }))
        .to.equal(stateBefore);
    });
  });

  describe('case "PICK_SPOT_COMPUTER"', () => {
    it('should return a randomly picked spot on level 0', () => {
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 0 };

      expect(brick(undefined, action))
        .to.include('o');
    });

    it('should return a semi-randomly picked spot on level 1', () => {
      const stateBefore = List(['x']).setSize(9);
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 1 };

      expect(brick(stateBefore, action))
        .to.include('o');
    });

    it('should pick the optimal spot on level 2', () => {
      const stateBefore = List(
        ['x', 'o', 'x', undefined, 'o', undefined, 'o', 'x', 'x']
      ).setSize(9);
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 2 };
      const nextState = brick(stateBefore, action);

      expect(nextState.get(5)).to.equal('o');
    });

    it('should pick the winning move if presented with one on level 2', () => {
      const stateBefore = List(['x', 'x', 'o', 'x', 'o']).setSize(9);
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 2 };
      const nextState = brick(stateBefore, action);

      expect(nextState.get(6)).to.equal('o');
    });

    it.skip('should always end in draw if two master AI\'s meet', function (done) {
      this.timeout(10000);
      const result = testAiVsAi(2, 2);
      expect(result.winner).to.equal('draw');
      done();
    });

    it('should not apply changes if player or level is not defined or faulty', () => {
      const stateBefore = List(['x', 'x', 'o', 'x', 'o']).setSize(9);

      expect(brick(stateBefore, { type: 'PICK_SPOT_COMPUTER', level: 2 }))
        .to.equal(stateBefore);
      expect(brick(stateBefore, { type: 'PICK_SPOT_COMPUTER', level: 2, player: 'y' }))
        .to.equal(stateBefore);
    });
  });

  describe('case RESET_GAME', () => {
    it('should reset brick to 9 empty fields', () => {
      const stateBefore = List(['x', 'o', 'x', 'o', 'x', 'o', 'x', 'o', 'x']);
      const stateAfter = List().setSize(9);
      const action = { type: 'RESET_GAME' };
<commit_msg>Updated test<commit_after>import { List } from 'immutable';
import { expect } from 'chai';

import brick from './index.js';
import testAiVsAi from '../../../test/helpers/testAiVsAi';

describe('Reducer: brick', () => {
  describe('case "PICK_SPOT_PLAYER"', () => {
    let initialState;

    beforeEach(() => (initialState = List().setSize(9)));

    it('should occupy a spot on the brick', () => {
      const stateAfter = initialState.set(1, 'x');

      const action = { type: 'PICK_SPOT_PLAYER', player: 'x', spot: 1 };

      expect(brick(initialState, action))
        .to.equal(stateAfter);
    });

    it('should return unchanged if spot is already occupied', () => {
      const stateBefore = initialState.set(5, 'x');
      const stateAfter = initialState.set(5, 'x');
      const action = { type: 'PICK_SPOT_PLAYER', player: 'o', spot: 5 };

      expect(brick(stateBefore, action))
        .to.equal(stateAfter);
    });

    it('should not apply changes if player or spot is not defined, or faulty', () => {
      const stateBefore = initialState.set(5, 'x');

      expect(brick(stateBefore, { type: 'PICK_SPOT_PLAYER', player: 'o' }))
        .to.equal(stateBefore);
      expect(brick(stateBefore, { type: 'PICK_SPOT_PLAYER', spot: 10, player: 'o' }))
        .to.equal(stateBefore);
    });
  });

  describe('case "PICK_SPOT_COMPUTER"', () => {
    it('should return a randomly picked spot on level 0', () => {
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 0 };

      expect(brick(undefined, action))
        .to.include('o');
    });

    it('should return a semi-randomly picked spot on level 1', () => {
      const stateBefore = List(['x']).setSize(9);
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 1 };

      expect(brick(stateBefore, action))
        .to.include('o');
    });

    it('should pick the optimal spot on level 2', () => {
      const stateBefore = List(
        ['x', 'o', 'x', undefined, 'o', undefined, 'o', 'x', 'x']
      ).setSize(9);
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 2 };
      const nextState = brick(stateBefore, action);

      expect(nextState.get(5)).to.equal('o');
    });

    it('should pick the winning move if presented with one on level 2', () => {
      const stateBefore = List(['x', 'x', 'o', 'x', 'o']).setSize(9);
      const action = { type: 'PICK_SPOT_COMPUTER', player: 'o', level: 2 };
      const nextState = brick(stateBefore, action);

      expect(nextState.get(6)).to.equal('o');
    });

    it.skip('should always end in draw if two master AI\'s meet (passes)', function (done) {
      this.timeout(10000);
      const result = testAiVsAi(2, 2);
      expect(result.winner).to.equal('draw');
      done();
    });

    it('should not apply changes if player or level is not defined or faulty', () => {
      const stateBefore = List(['x', 'x', 'o', 'x', 'o']).setSize(9);

      expect(brick(stateBefore, { type: 'PICK_SPOT_COMPUTER', level: 2 }))
        .to.equal(stateBefore);
      expect(brick(stateBefore, { type: 'PICK_SPOT_COMPUTER', level: 2, player: 'y' }))
        .to.equal(stateBefore);
    });
  });

  describe('case RESET_GAME', () => {
    it('should reset brick to 9 empty fields', () => {
      const stateBefore = List(['x', 'o', 'x', 'o', 'x', 'o', 'x', 'o', 'x']);
      const stateAfter = List().setSize(9);
      const action = { type: 'RESET_GAME' };

{'fraction_non_alphanumeric': 0.18608037274315667, 'fraction_numerical': 0.009900990099009901, 'mean_word_length': 3.081402257872846, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2115026', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2270, 'n_words': 594}