<commit_before>import {Map, fromJS} from 'immutable';
import {expect} from 'chai';

import reducer from '../src/reducer';

describe('reducer', () => {
    it('handles SET_ENTRIES', () => {
        const initialState = Map();
        const action = {type: 'SET_ENTRIES', entries: ['<NAME>']};
        const nextState = reducer(initialState, action);

        expect(nextState).to.equal(fromJS({
            entries: ['<NAME>']
        }));
    });

    it('handles NEXT', () => {
        const initialState = fromJS({
            entries: ['<NAME>', 'First Contact']
        });
        const action = {type: 'NEXT'};
        const nextState = reducer(initialState, action);

        expect(nextState).to.equal(fromJS({
            vote: {
                pair: ['<NAME>', 'First Contact']
            },
            entries: []
        }));
    });

    it('handles VOTE', () => {
        const initialState = fromJS({
            vote: {
                pair: ['<NAME>', 'First Contact']
            },
            entries: []
        });
        const action = {type: 'VOTE', entry: 'Mr. Nobody'};
        const nextState = reducer(initialState, action);

        expect(nextState).to.equal(fromJS({
            vote: {
                pair: ['<NAME>', 'First Contact'],
                tally: {'Mr. Nobody': 1}
            },
            entries: []
        }));
    });

    it('has an initial state', () => {
        const action = {type: 'SET_ENTRIES', entries: ['<NAME>']};
        const nextState = reducer(undefined, action);
        expect(nextState).to.equal(fromJS({
            entries: ['<NAME>']
        }));
    });
});<commit_msg>Add spec for replying actions on a state<commit_after>import {Map, fromJS} from 'immutable';
import {expect} from 'chai';

import reducer from '../src/reducer';

describe('reducer', () => {
    it('handles SET_ENTRIES', () => {
        const initialState = Map();
        const action = {type: 'SET_ENTRIES', entries: ['<NAME>']};
        const nextState = reducer(initialState, action);

        expect(nextState).to.equal(fromJS({
            entries: ['<NAME>']
        }));
    });

    it('handles NEXT', () => {
        const initialState = fromJS({
            entries: ['<NAME>', 'First Contact']
        });
        const action = {type: 'NEXT'};
        const nextState = reducer(initialState, action);

        expect(nextState).to.equal(fromJS({
            vote: {
                pair: ['<NAME>', 'First Contact']
            },
            entries: []
        }));
    });

    it('handles VOTE', () => {
        const initialState = fromJS({
            vote: {
                pair: ['<NAME>', 'First Contact']
            },
            entries: []
        });
        const action = {type: 'VOTE', entry: '<NAME>'};
        const nextState = reducer(initialState, action);

        expect(nextState).to.equal(fromJS({
            vote: {
                pair: ['<NAME>', 'First Contact'],
                tally: {'<NAME>': 1}
            },
            entries: []
        }));
    });

    it('has an initial state', () => {
        const action = {type: 'SET_ENTRIES', entries: ['<NAME>']};
        const nextState = reducer(undefined, action);
        expect(nextState).to.equal(fromJS({
            entries: ['<NAME>']
        }));
    });

    it('can be used with reduce', () => {
        const actions = [
            {type: 'SET_ENTRIES', entries: ['<NAME>', 'First Contact']},
            {type: 'NEXT'},
            {type: 'VOTE', entry: '<NAME>'},
            {type: 'VOTE', entry: 'First Contact'},
            {type: 'VOTE', entry: '<NAME>'},
            {type: 'NEXT'}
        ];
        const finalState = actions.reduce(reducer, Map());

        expect(finalState).to.equal(fromJS({
            winner: '<NAME>'
        }));
    });
});
{'fraction_non_alphanumeric': 0.18072289156626506, 'fraction_numerical': 0.0005238344683080147, 'mean_word_length': 1.8309859154929577, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 36, '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': '4313724', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1109, 'n_words': 254}