<commit_before>import { EmptyAction, PayloadAction, createEmptyAction, createPayloadAction } from '..';

// testing createAction

const APP_STARTED = 'app/APP_STARTED';
const SHOW_MESSAGE = 'app/SHOW_MESSAGE';
const HIDE_MESSAGE = 'app/HIDE_MESSAGE';

type AppActions =
  EmptyAction<typeof APP_STARTED> |
  PayloadAction<typeof SHOW_MESSAGE, string> |
  PayloadAction<typeof HIDE_MESSAGE, undefined>;

const appStarted = createEmptyAction<typeof APP_STARTED>(APP_STARTED);
const showMessage = createPayloadAction<typeof SHOW_MESSAGE, string>(SHOW_MESSAGE);
const hideMessage = createPayloadAction<typeof HIDE_MESSAGE, undefined>(HIDE_MESSAGE);

type AppState = {
  readonly isLoading: boolean;
  readonly message: string | undefined;
};
const initialState: AppState = {
  isLoading: true,
  message: undefined,
};

function appReducer(state = initialState, action: AppActions): AppState {
  switch (action.type) {
    case APP_STARTED: return {
      ...state, isLoading: !action,
    };
    case SHOW_MESSAGE: return {
      ...state, message: action.payload,
    };
    case HIDE_MESSAGE: return {
      ...state, message: action.payload,
    };

    default: return state;
  }
}

const state1 = appReducer(undefined, appStarted());
// assert true
if (state1.isLoading !== false) {
  console.log('state1', state1);
  process.exit(1);
}

const state2 = appReducer(undefined, showMessage('App Started!'));
// assert true
if (state2.message !== 'App Started!') {
  console.log('state2', state2);
  process.exit(1);
}

const state3 = appReducer(undefined, hideMessage(undefined));
// assert true
if (state3.message !== undefined) {
  console.log('state3', state3);
  process.exit(1);
}<commit_msg>added test coverage for ActionCreator class<commit_after>// Test Helpers
const passed = (describe: string) => {
  console.log(describe, true);
};
const failed = (describe: string, state: object) => {
  process.exitCode = 1; console.log(describe, false, state);
};

// Testing createEmptyAction, createPayloadAction
import {
  EmptyAction, PayloadAction, createEmptyAction, createPayloadAction,
} from '..';

export namespace TestHelpers1 {
  const APP_STARTED = 'app/APP_STARTED';
  const SHOW_MESSAGE = 'app/SHOW_MESSAGE';
  const HIDE_MESSAGE = 'app/HIDE_MESSAGE';

  type AppActions =
    EmptyAction<typeof APP_STARTED> |
    PayloadAction<typeof SHOW_MESSAGE, string> |
    PayloadAction<typeof HIDE_MESSAGE, undefined>;

  const appStarted = createEmptyAction<typeof APP_STARTED>(APP_STARTED);
  const showMessage = createPayloadAction<typeof SHOW_MESSAGE, string>(SHOW_MESSAGE);
  const hideMessage = createPayloadAction<typeof HIDE_MESSAGE, undefined>(HIDE_MESSAGE);

  type AppState = {
    readonly isLoading: boolean;
    readonly message: string | undefined;
  };
  const initialState: AppState = {
    isLoading: true,
    message: undefined,
  };

  function appReducer(state = initialState, action: AppActions): AppState {
    switch (action.type) {
      case APP_STARTED: return {
        ...state, isLoading: false,
      };
      case SHOW_MESSAGE: return {
        ...state, message: action.payload,
      };
      case HIDE_MESSAGE: return {
        ...state, message: action.payload,
      };

      default: return state;
    }
  }

  const state1 = appReducer(undefined, appStarted());
  // assert
  if (state1.isLoading === false) {
    passed('state1');
  } else {
    failed('state1', state1);
  }

  const state2 = appReducer(undefined, showMessage('App Started!'));
  // assert
  if (state2.message === 'App Started!') {
    passed('state2');
  } else {
    failed('state2', state2);
  }

  const state3 = appReducer(undefined, hideMessage(undefined));
  // assert
  if (state3.message === undefined) {
    passed('state3');
  } else {
    failed('state3', state3);
  }
}

// Testing ActionCreator
import {
  ActionCreator,
} from '..';

export namespace TestHelpers2 {
  export const ActionCreators = {
    IncreaseCounter: new ActionCreator<'IncreaseCounter', number>('IncreaseCounter'),
    ChangeBaseCurrency: new ActionCreator<'ChangeBaseCurrency', string>('ChangeBaseCurrency'),
  };

  // Action Types
  type Action = typeof ActionCreators[keyof typeof ActionCreators];

  type State = {
    readonly counter: number;
    readonly baseCurrency: string;
  };
  const initialState: State = {
    counter: 0,
    baseCurrency: 'EUR',
  };

  function reducer(state = initialState, action: Action): State {
    let partialState: Partial<State> | undefined;

    if (action.type === ActionCreators.IncreaseCounter.type) {
      partialState = { counter: action.payload }; // number
    }
    if (action.type === ActionCreators.ChangeBaseCurrency.type) {
      partialState = { baseCurrency: action.payload }; // string
    }

    return partialState != null ? { ...state, ...partialState } : state;
  }

  const action1 = ActionCreators.IncreaseCounter.create(4);
  const state1 = reducer(undefined, action1 as any);
  // assert
  if (state1.counter === 4) {
    passed('state1');
  } else {
    failed('state1', state1);
  }

  const action2 = ActionCreators.ChangeBaseCurrency.create('USD');
  const state2 = reducer(undefined, action2 as any);
  // assert
  if (state2.baseCurrency === 'USD') {
    passed('state2');
  } else {
    failed('state2', state2);
  }
}
{'fraction_non_alphanumeric': 0.12828263744568297, 'fraction_numerical': 0.009446438692612885, 'mean_word_length': 3.980244590780809, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, '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': '631984', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1607, 'n_words': 383}