Skip to content

Commit

Permalink
*: string input function modification
Browse files Browse the repository at this point in the history
  • Loading branch information
lynklody authored and billchenchina committed Aug 13, 2020
1 parent 6d4a0ff commit f22508b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 44 deletions.
43 changes: 18 additions & 25 deletions src/Components/InputAreaByDataTypes/StringInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,24 @@ const StringInput = () => {
label="允许字符重复"
/>
</Grid>

{ allowDuplicate
?
<Grid container>
<Grid item className={classes.line}>
<CardContent>每测试用例字符数量:</CardContent>
</Grid>
<Grid item className={classes.line}>
<TextField
className={classes.text}
label='Required'
fullWidth
name='delimiter'
// onChange={(e)=>updateNumChars(e.target.value)}
onChange={(e) => dispatch({
type: UPDATE_NUM_CHARS,
payload: e.target.value
})}
variant='outlined'
/>
</Grid>
</Grid>
:
<Box />
}
<Grid container>
<Grid item className={classes.line}>
<CardContent>每测试用例字符数量:</CardContent>
</Grid>
<Grid item className={classes.line}>
<TextField
className={classes.text}
label='Required'
fullWidth
name='delimiter'
onChange={(e) => dispatch({
type: UPDATE_NUM_CHARS,
payload: e.target.value
})}
variant='outlined'
/>
</Grid>
</Grid>
<Grid container
direction='column'
spacing={2}
Expand Down
11 changes: 6 additions & 5 deletions src/Store/Actions/ActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// inputs
export const TOGGLE_DRAWER = 'TOGGLE_DRAWER'
// General actions
export const OPEN_DRAWER = "OPEN_DRAWER"
export const CLOSE_DRAWER = "CLOSE_DRAWER"
export const SET_DATATYPE = 'SET_DATATYPE'
export const SET_OUTPUT = 'SET_OUTPUT'
export const ALTER_ALL = 'ALTER_ALL'

// String
export const UPDATE_CHARSET = 'UPDATE_CHARSET'
export const UPDATE_DELIMITER = 'UPDATE_DELIMITER'
export const UPDATE_NUM_CHARS = 'UPDATE_NUM_CHARS'
export const SET_DATATYPE = 'SET_DATATYPE'
export const UPDATE_NUM_CASES = 'UPDATE_NUM_CASES'
export const UPDATE_ALLOW_DUPLICATE = 'UPDATE_ALLOW_DUPLICATE'

// outputs
export const SET_OUTPUT = 'SET_OUTPUT'
43 changes: 30 additions & 13 deletions src/Store/Actions/StringActions.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { SET_OUTPUT } from './ActionTypes'

export const startStringGen = (state) => {
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')
}
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 {
Expand All @@ -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
})
}
7 changes: 6 additions & 1 deletion src/Store/Actions/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
import { ALTER_ALL } from './ActionTypes'
export * from './StringActions'
export * from './VectorActions'
export * from './VectorActions'

export const clearAll = () => ({
type: ALTER_ALL
})

0 comments on commit f22508b

Please sign in to comment.