From f22508be87c04bd78eaaf783525b5f104fee6474 Mon Sep 17 00:00:00 2001 From: lynklody Date: Thu, 13 Aug 2020 22:53:18 +0800 Subject: [PATCH] *: string input function modification --- .../InputAreaByDataTypes/StringInput.js | 43 ++++++++----------- src/Store/Actions/ActionTypes.js | 11 ++--- src/Store/Actions/StringActions.js | 43 +++++++++++++------ src/Store/Actions/index.js | 7 ++- 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/Components/InputAreaByDataTypes/StringInput.js b/src/Components/InputAreaByDataTypes/StringInput.js index 48ec1c4..bf8f8bc 100644 --- a/src/Components/InputAreaByDataTypes/StringInput.js +++ b/src/Components/InputAreaByDataTypes/StringInput.js @@ -181,31 +181,24 @@ const StringInput = () => { label="允许字符重复" /> - - { allowDuplicate - ? - - - 每测试用例字符数量: - - - updateNumChars(e.target.value)} - onChange={(e) => dispatch({ - type: UPDATE_NUM_CHARS, - payload: e.target.value - })} - variant='outlined' - /> - - - : - - } + + + 每测试用例字符数量: + + + dispatch({ + type: UPDATE_NUM_CHARS, + payload: e.target.value + })} + variant='outlined' + /> + + { - console.log("SRING GEN ACTIONS") +export const startStringGen = (state, dispatch) => { + console.log("STRING GEN ACTIONS") const { chars, numChars, delimiter, numCases, allowDuplicate, output } = state if (output !== '') { console.log('ERROR: output not empty, submit clicked more than once') @@ -8,11 +9,14 @@ export const startStringGen = (state) => { let result = '' let arr = chars.split('') if (allowDuplicate) { - console.log('ALLOW dup') + console.log('dup ALLOWED') if (delimiter === '') { console.log('WITHOUT delimiter') for (let i = 0; i < numCases; ++i) { - result += arr[Math.floor(Math.random() * arr.length)] + for (let j = 0; j < numChars; ++j) { + result += arr[Math.floor(Math.random() * arr.length)] + } + result += '\n' } } else { @@ -29,25 +33,38 @@ export const startStringGen = (state) => { } else { console.log('dup NOT ALLOWED') - let count = Math.min(arr.length, numCases) + let count = Math.min(arr.length, numCases*numChars) if (delimiter === '') { console.log('WITHOUT delimiter') while (count > 0 && arr.length > 0) { - let idx = Math.floor(Math.random() * count--) - result += arr[idx] - arr.splice(idx, 1) + for (let i = 0; i < numChars; ++i) { + if (count <= 0) + break + let idx = Math.floor(Math.random() * count--) + result += arr[idx] + arr.splice(idx, 1) + } + result += '\n' } } else { console.log('WITH delimiter') while (count > 0 && arr.length > 0) { - let idx = Math.floor(Math.random() * count--) - result += arr[idx] - arr.splice(idx, 1) - if (count !== 0) + for (let i = 0; i < numChars; ++i) { + if (count <= 0) + break + let idx = Math.floor(Math.random() * count--) + result += arr[idx] + arr.splice(idx, 1) + } + if (count > 0) result += delimiter } } } - console.log(result) + console.log('RESULT=',result) + dispatch({ + type: SET_OUTPUT, + payload: result + }) } \ No newline at end of file diff --git a/src/Store/Actions/index.js b/src/Store/Actions/index.js index 0a62973..96c9d9c 100644 --- a/src/Store/Actions/index.js +++ b/src/Store/Actions/index.js @@ -1,2 +1,7 @@ +import { ALTER_ALL } from './ActionTypes' export * from './StringActions' -export * from './VectorActions' \ No newline at end of file +export * from './VectorActions' + +export const clearAll = () => ({ + type: ALTER_ALL +})