feat: rotate ui

This commit is contained in:
Ibrahima G. Coulibaly
2024-07-14 00:23:30 +01:00
parent 350061d79e
commit 46859592cf
30 changed files with 723 additions and 510 deletions

82
.idea/workspace.xml generated
View File

@@ -4,10 +4,37 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="feat: self host"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="chore: format number">
<change afterPath="$PROJECT_DIR$/src/utils/number.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/group/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/group/index.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/duplicate.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/duplicate.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/duplicate/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/duplicate/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/rotate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/rotate/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/create-palindrome.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/create-palindrome.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/create-palindrome/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/create-palindrome/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/extract-substring.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/extract-substring.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/extract-substring/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/extract-substring/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/palindrome.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/palindrome.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/palindrome/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/palindrome/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/randomize-case.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/randomize-case.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/randomize-case/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/randomize-case/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/reverse.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/reverse.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/reverse/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/reverse/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/string/uppercase/uppercase.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/string/uppercase/uppercase.service.test.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -29,6 +56,18 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RESET_MODE" value="HARD" /> <option name="RESET_MODE" value="HARD" />
</component> </component>
<component name="GitHubPullRequestSearchHistory">{
&quot;lastFilter&quot;: {
&quot;state&quot;: &quot;OPEN&quot;,
&quot;assignee&quot;: &quot;iib0011&quot;
}
}</component>
<component name="GithubPullRequestsUISettings">{
&quot;selectedUrlAndAccountId&quot;: {
&quot;url&quot;: &quot;https://github.com/iib0011/omni-tools&quot;,
&quot;accountId&quot;: &quot;59b4836a-7ded-49a0-a358-5e8d81d0d44b&quot;
}
}</component>
<component name="KubernetesApiProvider">{ <component name="KubernetesApiProvider">{
&quot;isMigrated&quot;: true &quot;isMigrated&quot;: true
}</component> }</component>
@@ -117,7 +156,6 @@
<settings> <settings>
<option name="imageTag" value="omnitools" /> <option name="imageTag" value="omnitools" />
<option name="buildCliOptions" value="--target build" /> <option name="buildCliOptions" value="--target build" />
<option name="buildKitEnabled" value="true" />
<option name="containerName" value="omni-tools" /> <option name="containerName" value="omni-tools" />
<option name="publishAllPorts" value="true" /> <option name="publishAllPorts" value="true" />
<option name="sourceFilePath" value="Dockerfile" /> <option name="sourceFilePath" value="Dockerfile" />
@@ -179,13 +217,21 @@
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="npm.dev" /> <item itemvalue="npm.dev" />
<item itemvalue="npm.lint" />
<item itemvalue="Docker.Dockerfile build" /> <item itemvalue="Docker.Dockerfile build" />
<item itemvalue="Docker.Dockerfile" /> <item itemvalue="Docker.Dockerfile" />
<item itemvalue="npm.lint" />
<item itemvalue="npm.test:e2e" /> <item itemvalue="npm.test:e2e" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="bundled-jdk-9f38398b9061-39b83d9b5494-intellij.indexing.shared.core-IU-241.18034.62" />
<option value="bundled-js-predefined-1d06a55b98c1-0b3e54e931b4-JavaScript-IU-241.18034.62" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">
@@ -224,15 +270,9 @@
<workItem from="1720613598176" duration="8000" /> <workItem from="1720613598176" duration="8000" />
<workItem from="1720655252208" duration="3975000" /> <workItem from="1720655252208" duration="3975000" />
<workItem from="1720661825389" duration="4305000" /> <workItem from="1720661825389" duration="4305000" />
<workItem from="1720729165596" duration="730000" /> <workItem from="1720729165596" duration="3258000" />
</task> <workItem from="1720911748039" duration="331000" />
<task id="LOCAL-00047" summary="feat: change colors in png"> <workItem from="1720912096050" duration="810000" />
<option name="closed" value="true" />
<created>1719197875189</created>
<option name="number" value="00047" />
<option name="presentableId" value="LOCAL-00047" />
<option name="project" value="LOCAL" />
<updated>1719197875189</updated>
</task> </task>
<task id="LOCAL-00048" summary="chore: ResultFooter"> <task id="LOCAL-00048" summary="chore: ResultFooter">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -618,7 +658,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1720665220408</updated> <updated>1720665220408</updated>
</task> </task>
<option name="localTasksCounter" value="96" /> <task id="LOCAL-00096" summary="chore: format number">
<option name="closed" value="true" />
<created>1720730102816</created>
<option name="number" value="00096" />
<option name="presentableId" value="LOCAL-00096" />
<option name="project" value="LOCAL" />
<updated>1720730102817</updated>
</task>
<option name="localTasksCounter" value="97" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -662,7 +710,6 @@
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" /> <option name="CHECK_NEW_TODO" value="false" />
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="chore: make tool examples responsive" />
<MESSAGE value="chore: loading screen" /> <MESSAGE value="chore: loading screen" />
<MESSAGE value="chore: shuffle tools search" /> <MESSAGE value="chore: shuffle tools search" />
<MESSAGE value="refactor: toolOptions" /> <MESSAGE value="refactor: toolOptions" />
@@ -687,7 +734,8 @@
<MESSAGE value="feat: group list ui" /> <MESSAGE value="feat: group list ui" />
<MESSAGE value="feat: reverse list ui" /> <MESSAGE value="feat: reverse list ui" />
<MESSAGE value="feat: self host" /> <MESSAGE value="feat: self host" />
<option name="LAST_COMMIT_MESSAGE" value="feat: self host" /> <MESSAGE value="chore: format number" />
<option name="LAST_COMMIT_MESSAGE" value="chore: format number" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -2,61 +2,65 @@ import { expect, describe, it } from 'vitest';
import { duplicateList } from './service'; import { duplicateList } from './service';
describe('duplicateList function', () => { describe('duplicateList function', () => {
it('should duplicate elements correctly with symbol split', () => { it('should duplicate elements correctly with symbol split', () => {
const input = "Hello World"; const input = 'Hello World';
const result = duplicateList('symbol', ' ', ' ', input, true, false, 2); const result = duplicateList('symbol', ' ', ' ', input, true, false, 2);
expect(result).toBe("Hello World Hello World"); expect(result).toBe('Hello World Hello World');
}); });
it('should duplicate elements correctly with regex split', () => { it('should duplicate elements correctly with regex split', () => {
const input = "Hello||World"; const input = 'Hello||World';
const result = duplicateList('regex', '\\|\\|', ' ', input, true, false, 2); const result = duplicateList('regex', '\\|\\|', ' ', input, true, false, 2);
expect(result).toBe("Hello World Hello World"); expect(result).toBe('Hello World Hello World');
}); });
it('should handle fractional duplication', () => { it('should handle fractional duplication', () => {
const input = "Hello World"; const input = 'Hello World';
const result = duplicateList('symbol', ' ', ' ', input, true, false, 1.5); const result = duplicateList('symbol', ' ', ' ', input, true, false, 1.5);
expect(result).toBe("Hello World Hello"); expect(result).toBe('Hello World Hello');
}); });
it('should handle reverse option correctly', () => { it('should handle reverse option correctly', () => {
const input = "Hello World"; const input = 'Hello World';
const result = duplicateList('symbol', ' ', ' ', input, true, true, 2); const result = duplicateList('symbol', ' ', ' ', input, true, true, 2);
expect(result).toBe("Hello World World Hello"); expect(result).toBe('Hello World World Hello');
}); });
it('should handle concatenate option correctly', () => { it('should handle concatenate option correctly', () => {
const input = "Hello World"; const input = 'Hello World';
const result = duplicateList('symbol', ' ', ' ', input, false, false, 2); const result = duplicateList('symbol', ' ', ' ', input, false, false, 2);
expect(result).toBe("Hello Hello World World"); expect(result).toBe('Hello Hello World World');
}); });
it('should handle interweaving option correctly', () => { it('should handle interweaving option correctly', () => {
const input = "Hello World"; const input = 'Hello World';
const result = duplicateList('symbol', ' ', ' ', input, false, false, 2); const result = duplicateList('symbol', ' ', ' ', input, false, false, 2);
expect(result).toBe("Hello Hello World World"); expect(result).toBe('Hello Hello World World');
}); });
it('should throw an error for negative copies', () => { it('should throw an error for negative copies', () => {
expect(() => duplicateList('symbol', ' ', ' ', "Hello World", true, false, -1)).toThrow("Number of copies cannot be negative"); expect(() =>
}); duplicateList('symbol', ' ', ' ', 'Hello World', true, false, -1)
).toThrow('Number of copies cannot be negative');
});
it('should handle interweaving option correctly 2', () => { it('should handle interweaving option correctly 2', () => {
const input = "je m'appelle king"; const input = "je m'appelle king";
const result = duplicateList('symbol', ' ', ', ', input, false, true, 2.1); const result = duplicateList('symbol', ' ', ', ', input, false, true, 2.1);
expect(result).toBe("je, king, m'appelle, m'appelle, king, je"); expect(result).toBe("je, king, m'appelle, m'appelle, king, je");
}); });
it('should handle interweaving option correctly 3', () => { it('should handle interweaving option correctly 3', () => {
const input = "je m'appelle king"; const input = "je m'appelle king";
const result = duplicateList('symbol', ' ', ', ', input, false, true, 1); const result = duplicateList('symbol', ' ', ', ', input, false, true, 1);
expect(result).toBe("je, m'appelle, king"); expect(result).toBe("je, m'appelle, king");
}); });
it('should handle interweaving option correctly 3', () => { it('should handle interweaving option correctly 3', () => {
const input = "je m'appelle king"; const input = "je m'appelle king";
const result = duplicateList('symbol', ' ', ', ', input, true, true, 2.7); const result = duplicateList('symbol', ' ', ', ', input, true, true, 2.7);
expect(result).toBe("je, m'appelle, king, king, m'appelle, je, king, m'appelle"); expect(result).toBe(
}); "je, m'appelle, king, king, m'appelle, je, king, m'appelle"
);
});
}); });

View File

@@ -1,69 +1,81 @@
export type SplitOperatorType = 'symbol' | 'regex'; export type SplitOperatorType = 'symbol' | 'regex';
function interweave( function interweave(array1: string[], array2: string[]) {
array1: string[], const result: string[] = [];
array2: string[]) { const maxLength = Math.max(array1.length, array2.length);
const result: string[] = [];
const maxLength = Math.max(array1.length, array2.length);
for (let i = 0; i < maxLength; i++) { for (let i = 0; i < maxLength; i++) {
if (i < array1.length) result.push(array1[i]); if (i < array1.length) result.push(array1[i]);
if (i < array2.length) result.push(array2[i]); if (i < array2.length) result.push(array2[i]);
} }
return result; return result;
} }
function duplicate( function duplicate(
input: string[], input: string[],
concatenate: boolean, concatenate: boolean,
reverse: boolean, reverse: boolean,
copy?: number copy?: number
) { ) {
if (copy) { if (copy) {
if (copy > 0) { if (copy > 0) {
let result: string[] = []; let result: string[] = [];
let toAdd: string[] = []; let toAdd: string[] = [];
let WholePart: string[] = []; let WholePart: string[] = [];
let fractionalPart: string[] = []; let fractionalPart: string[] = [];
const whole = Math.floor(copy); const whole = Math.floor(copy);
const fractional = copy - whole; const fractional = copy - whole;
if (!reverse) { if (!reverse) {
WholePart = concatenate ? Array(whole).fill(input).flat() : Array(whole - 1).fill(input).flat(); WholePart = concatenate
fractionalPart = input.slice(0, Math.floor(input.length * fractional)); ? Array(whole).fill(input).flat()
toAdd = WholePart.concat(fractionalPart); : Array(whole - 1)
result = concatenate ? WholePart.concat(fractionalPart) : interweave(input, toAdd); .fill(input)
} else { .flat();
WholePart = Array(whole - 1).fill(input).flat().reverse() fractionalPart = input.slice(0, Math.floor(input.length * fractional));
fractionalPart = input.slice().reverse().slice(0, Math.floor(input.length * fractional)); toAdd = WholePart.concat(fractionalPart);
toAdd = WholePart.concat(fractionalPart); result = concatenate
result = concatenate ? input.concat(toAdd) : interweave(input, toAdd); ? WholePart.concat(fractionalPart)
} : interweave(input, toAdd);
} else {
WholePart = Array(whole - 1)
.fill(input)
.flat()
.reverse();
fractionalPart = input
.slice()
.reverse()
.slice(0, Math.floor(input.length * fractional));
toAdd = WholePart.concat(fractionalPart);
result = concatenate ? input.concat(toAdd) : interweave(input, toAdd);
}
return result; return result;
}
throw new Error("Number of copies cannot be negative");
} }
throw new Error("Number of copies must be a valid number"); throw new Error('Number of copies cannot be negative');
}
throw new Error('Number of copies must be a valid number');
} }
export function duplicateList( export function duplicateList(
splitOperatorType: SplitOperatorType, splitOperatorType: SplitOperatorType,
splitSeparator: string, splitSeparator: string,
joinSeparator: string, joinSeparator: string,
input: string, input: string,
concatenate: boolean, concatenate: boolean,
reverse: boolean, reverse: boolean,
copy?: number copy?: number
): string { ): string {
let array: string[]; let array: string[];
let result: string[]; let result: string[];
switch (splitOperatorType) { switch (splitOperatorType) {
case 'symbol': case 'symbol':
array = input.split(splitSeparator); array = input.split(splitSeparator);
break; break;
case 'regex': case 'regex':
array = input.split(new RegExp(splitSeparator)).filter(item => item !== ''); array = input
break; .split(new RegExp(splitSeparator))
} .filter((item) => item !== '');
result = duplicate(array, concatenate, reverse, copy); break;
return result.join(joinSeparator); }
result = duplicate(array, concatenate, reverse, copy);
return result.join(joinSeparator);
} }

View File

@@ -1,11 +1,158 @@
import { Box } from '@mui/material'; import { Box } from '@mui/material';
import React from 'react'; import React, { useState } from 'react';
import ToolTextInput from '../../../components/input/ToolTextInput';
import ToolTextResult from '../../../components/result/ToolTextResult';
import * as Yup from 'yup'; import * as Yup from 'yup';
import ToolOptions from '../../../components/options/ToolOptions';
import { rotateList, SplitOperatorType } from './service';
import ToolInputAndResult from '../../../components/ToolInputAndResult';
import SimpleRadio from '../../../components/options/SimpleRadio';
import TextFieldWithDesc from '../../../components/options/TextFieldWithDesc';
import { formatNumber } from '../../../utils/number';
const initialValues = {
splitOperatorType: 'symbol' as SplitOperatorType,
input: '',
splitSeparator: ',',
joinSeparator: ',',
right: true,
step: 1
};
const splitOperators: {
title: string;
description: string;
type: SplitOperatorType;
}[] = [
{
title: 'Use a Symbol for Splitting',
description: 'Delimit input list items with a character.',
type: 'symbol'
},
{
title: 'Use a Regex for Splitting',
type: 'regex',
description: 'Delimit input list items with a regular expression.'
}
];
const rotationDirections: {
title: string;
description: string;
value: boolean;
}[] = [
{
title: 'Rotate forward',
description:
'Rotate list items to the right. (Down if a vertical column list.)',
value: true
},
{
title: 'Rotate backward',
description:
'Rotate list items to the left. (Up if a vertical column list.)',
value: false
}
];
const initialValues = {};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
export default function Rotate() { export default function Rotate() {
return <Box>Lorem ipsum</Box>; const [input, setInput] = useState<string>('');
const [result, setResult] = useState<string>('');
const compute = (optionsValues: typeof initialValues, input: any) => {
const { splitOperatorType, splitSeparator, joinSeparator, right, step } =
optionsValues;
setResult(
rotateList(
splitOperatorType,
input,
splitSeparator,
joinSeparator,
right,
step
)
);
};
const validationSchema = Yup.object({
// splitSeparator: Yup.string().required('The separator is required')
});
return (
<Box>
<ToolInputAndResult
input={
<ToolTextInput
title={'Input list'}
value={input}
onChange={setInput}
/>
}
result={<ToolTextResult title={'Rotated list'} value={result} />}
/>
<ToolOptions
compute={compute}
getGroups={({ values, updateField }) => [
{
title: 'Item split mode',
component: (
<Box>
{splitOperators.map(({ title, description, type }) => (
<SimpleRadio
key={type}
onClick={() => updateField('splitOperatorType', type)}
title={title}
description={description}
checked={values.splitOperatorType === type}
/>
))}
<TextFieldWithDesc
description={'Set a delimiting symbol or regular expression.'}
value={values.splitSeparator}
onOwnChange={(val) => updateField('splitSeparator', val)}
/>
</Box>
)
},
{
title: 'Rotation Direction and Count',
component: (
<Box>
{rotationDirections.map(({ title, description, value }) => (
<SimpleRadio
key={`${value}`}
onClick={() => updateField('right', Boolean(value))}
title={title}
description={description}
checked={values.right === value}
/>
))}
<TextFieldWithDesc
description={'Number of items to rotate'}
value={values.step}
onOwnChange={(val) =>
updateField('step', formatNumber(val, 1))
}
/>
</Box>
)
},
{
title: 'Rotated List Joining Symbol',
component: (
<Box>
<TextFieldWithDesc
value={values.joinSeparator}
onOwnChange={(value) => updateField('joinSeparator', value)}
description={
'Enter the character that goes between items in the rotated list.'
}
/>
</Box>
)
}
]}
initialValues={initialValues}
input={input}
validationSchema={validationSchema}
/>
</Box>
);
} }

View File

@@ -1,66 +1,66 @@
import { expect, describe, it } from 'vitest'; import { expect, describe, it } from 'vitest';
import { createPalindromeList, createPalindrome } from './service'; import { createPalindromeList, createPalindrome } from './service';
describe('createPalindrome', () => { describe('createPalindrome', () => {
test('should create palindrome by reversing the entire string', () => { test('should create palindrome by reversing the entire string', () => {
const input = 'hello'; const input = 'hello';
const result = createPalindrome(input, true); const result = createPalindrome(input, true);
expect(result).toBe('helloolleh'); expect(result).toBe('helloolleh');
}); });
test('should create palindrome by reversing the string excluding the last character', () => { test('should create palindrome by reversing the string excluding the last character', () => {
const input = 'hello'; const input = 'hello';
const result = createPalindrome(input, false); const result = createPalindrome(input, false);
expect(result).toBe('hellolleh'); expect(result).toBe('hellolleh');
}); });
test('should return an empty string if input is empty', () => { test('should return an empty string if input is empty', () => {
const input = ''; const input = '';
const result = createPalindrome(input, true); const result = createPalindrome(input, true);
expect(result).toBe(''); expect(result).toBe('');
}); });
}); });
describe('createPalindromeList', () => { describe('createPalindromeList', () => {
test('should create palindrome for single-line input', () => { test('should create palindrome for single-line input', () => {
const input = 'hello'; const input = 'hello';
const result = createPalindromeList(input, true, false); const result = createPalindromeList(input, true, false);
expect(result).toBe('helloolleh'); expect(result).toBe('helloolleh');
}); });
test('should create palindrome for single-line input considering trailing spaces', () => { test('should create palindrome for single-line input considering trailing spaces', () => {
const input = 'hello '; const input = 'hello ';
const result = createPalindromeList(input, true, false); const result = createPalindromeList(input, true, false);
expect(result).toBe('hello olleh'); expect(result).toBe('hello olleh');
}); });
test('should create palindrome for single-line input ignoring trailing spaces if lastChar is set to false', () => { test('should create palindrome for single-line input ignoring trailing spaces if lastChar is set to false', () => {
const input = 'hello '; const input = 'hello ';
const result = createPalindromeList(input, true, false); const result = createPalindromeList(input, true, false);
expect(result).toBe('hello olleh'); expect(result).toBe('hello olleh');
}); });
test('should create palindrome for multi-line input', () => { test('should create palindrome for multi-line input', () => {
const input = 'hello\nworld'; const input = 'hello\nworld';
const result = createPalindromeList(input, true, true); const result = createPalindromeList(input, true, true);
expect(result).toBe('helloolleh\nworlddlrow'); expect(result).toBe('helloolleh\nworlddlrow');
}); });
test('should create palindrome for no multi-line input', () => { test('should create palindrome for no multi-line input', () => {
const input = 'hello\nworld\n'; const input = 'hello\nworld\n';
const result = createPalindromeList(input, true, false); const result = createPalindromeList(input, true, false);
expect(result).toBe('hello\nworld\n\ndlrow\nolleh'); expect(result).toBe('hello\nworld\n\ndlrow\nolleh');
}); });
test('should handle multi-line input with lastChar set to false', () => { test('should handle multi-line input with lastChar set to false', () => {
const input = 'hello\nworld'; const input = 'hello\nworld';
const result = createPalindromeList(input, false, true); const result = createPalindromeList(input, false, true);
expect(result).toBe('hellolleh\nworldlrow'); expect(result).toBe('hellolleh\nworldlrow');
}); });
test('should return an empty string if input is empty', () => { test('should return an empty string if input is empty', () => {
const input = ''; const input = '';
const result = createPalindromeList(input, true, false); const result = createPalindromeList(input, true, false);
expect(result).toBe(''); expect(result).toBe('');
}); });
}); });

View File

@@ -1,35 +1,36 @@
import { reverseString } from 'utils/string' import { reverseString } from 'utils/string';
export function createPalindrome( export function createPalindrome(
input: string, input: string,
lastChar: boolean // only checkbox is need here to handle it [instead of two combo boxes] lastChar: boolean // only checkbox is need here to handle it [instead of two combo boxes]
) { ) {
if (!input) return ''; if (!input) return '';
let result: string; let result: string;
let reversedString: string; let reversedString: string;
// reverse the whole input if lastChar enabled // reverse the whole input if lastChar enabled
reversedString = lastChar ? reverseString(input) : reverseString(input.slice(0, -1)); reversedString = lastChar
result = input.concat(reversedString); ? reverseString(input)
return result; : reverseString(input.slice(0, -1));
result = input.concat(reversedString);
return result;
} }
export function createPalindromeList( export function createPalindromeList(
input: string, input: string,
lastChar: boolean, lastChar: boolean,
multiLine: boolean multiLine: boolean
): string { ): string {
if (!input) return ''; if (!input) return '';
let array: string[]; let array: string[];
let result: string[] = []; const result: string[] = [];
if (!multiLine) return createPalindrome(input, lastChar); if (!multiLine) return createPalindrome(input, lastChar);
else { else {
array = input.split('\n'); array = input.split('\n');
for (const word of array) { for (const word of array) {
result.push(createPalindrome(word, lastChar)); result.push(createPalindrome(word, lastChar));
}
} }
return result.join('\n'); }
return result.join('\n');
} }

View File

@@ -2,56 +2,60 @@ import { expect, describe, it } from 'vitest';
import { extractSubstring } from './service'; import { extractSubstring } from './service';
describe('extractSubstring', () => { describe('extractSubstring', () => {
it('should extract a substring from single-line input', () => { it('should extract a substring from single-line input', () => {
const input = 'hello world'; const input = 'hello world';
const result = extractSubstring(input, 1, 4, false, false); const result = extractSubstring(input, 1, 4, false, false);
expect(result).toBe('hell'); expect(result).toBe('hell');
}); });
it('should extract and reverse a substring from single-line input', () => { it('should extract and reverse a substring from single-line input', () => {
const input = 'hello world'; const input = 'hello world';
const result = extractSubstring(input, 1, 5, false, true); const result = extractSubstring(input, 1, 5, false, true);
expect(result).toBe('olleh'); expect(result).toBe('olleh');
}); });
it('should extract substrings from multi-line input', () => { it('should extract substrings from multi-line input', () => {
const input = 'hello\nworld'; const input = 'hello\nworld';
const result = extractSubstring(input, 1, 5, true, false); const result = extractSubstring(input, 1, 5, true, false);
expect(result).toBe('hello\nworld'); expect(result).toBe('hello\nworld');
}); });
it('should extract and reverse substrings from multi-line input', () => { it('should extract and reverse substrings from multi-line input', () => {
const input = 'hello\nworld'; const input = 'hello\nworld';
const result = extractSubstring(input, 1, 4, true, true); const result = extractSubstring(input, 1, 4, true, true);
expect(result).toBe('lleh\nlrow'); expect(result).toBe('lleh\nlrow');
}); });
it('should handle empty input', () => { it('should handle empty input', () => {
const input = ''; const input = '';
const result = extractSubstring(input, 1, 5, false, false); const result = extractSubstring(input, 1, 5, false, false);
expect(result).toBe(''); expect(result).toBe('');
}); });
it('should handle start and length out of bounds', () => { it('should handle start and length out of bounds', () => {
const input = 'hello'; const input = 'hello';
const result = extractSubstring(input, 10, 5, false, false); const result = extractSubstring(input, 10, 5, false, false);
expect(result).toBe(''); expect(result).toBe('');
}); });
it('should handle negative start and length', () => { it('should handle negative start and length', () => {
expect(() => extractSubstring('hello', -1, 5, false, false)).toThrow("Start index must be greater than zero."); expect(() => extractSubstring('hello', -1, 5, false, false)).toThrow(
expect(() => extractSubstring('hello', 1, -5, false, false)).toThrow("Length value must be greater than or equal to zero."); 'Start index must be greater than zero.'
}); );
expect(() => extractSubstring('hello', 1, -5, false, false)).toThrow(
'Length value must be greater than or equal to zero.'
);
});
it('should handle zero length', () => { it('should handle zero length', () => {
const input = 'hello'; const input = 'hello';
const result = extractSubstring(input, 1, 0, false, false); const result = extractSubstring(input, 1, 0, false, false);
expect(result).toBe(''); expect(result).toBe('');
}); });
it('should work', () => { it('should work', () => {
const input = 'je me nomme king\n22 est mon chiffre'; const input = 'je me nomme king\n22 est mon chiffre';
const result = extractSubstring(input, 12, 7, true, false); const result = extractSubstring(input, 12, 7, true, false);
expect(result).toBe(' king\nchiffre'); expect(result).toBe(' king\nchiffre');
}); });
}); });

View File

@@ -1,36 +1,36 @@
import { reverseString } from 'utils/string' import { reverseString } from 'utils/string';
export function extractSubstring( export function extractSubstring(
input: string, input: string,
start: number, start: number,
length: number, length: number,
multiLine: boolean, multiLine: boolean,
reverse: boolean reverse: boolean
): string { ): string {
if (!input) return ''; if (!input) return '';
// edge Cases // edge Cases
if (start <= 0) throw new Error("Start index must be greater than zero."); if (start <= 0) throw new Error('Start index must be greater than zero.');
if (length < 0) throw new Error("Length value must be greater than or equal to zero."); if (length < 0)
if (length === 0) return ''; throw new Error('Length value must be greater than or equal to zero.');
if (length === 0) return '';
let array: string[]; let array: string[];
let result: string[] = []; let result: string[] = [];
const extract = (str: string, start: number, length: number): string => { const extract = (str: string, start: number, length: number): string => {
const end = start - 1 + length; const end = start - 1 + length;
if (start - 1 >= str.length) return ''; if (start - 1 >= str.length) return '';
return str.substring(start - 1, Math.min(end, str.length)); return str.substring(start - 1, Math.min(end, str.length));
}; };
if (!multiLine) { if (!multiLine) {
result.push(extract(input, start, length)); result.push(extract(input, start, length));
} else {
array = input.split('\n');
for (const word of array) {
result.push(extract(word, start, length));
} }
else { }
array = input.split('\n'); result = reverse ? result.map((word) => reverseString(word)) : result;
for (const word of array) { return result.join('\n');
result.push(extract(word, start, length));
}
}
result = reverse ? result.map(word => reverseString(word)) : result;
return result.join('\n');
} }

View File

@@ -2,59 +2,59 @@ import { expect, describe, it } from 'vitest';
import { palindromeList } from './service'; import { palindromeList } from './service';
describe('palindromeList', () => { describe('palindromeList', () => {
test('should return true for single character words', () => { test('should return true for single character words', () => {
const input = 'a|b|c'; const input = 'a|b|c';
const separator = '|'; const separator = '|';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe('true|true|true'); expect(result).toBe('true|true|true');
}); });
test('should return false for non-palindromes', () => { test('should return false for non-palindromes', () => {
const input = 'hello|world'; const input = 'hello|world';
const separator = '|'; const separator = '|';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe('false|false'); expect(result).toBe('false|false');
}); });
test('should split using regex', () => { test('should split using regex', () => {
const input = 'racecar,abba,hello'; const input = 'racecar,abba,hello';
const separator = ','; const separator = ',';
const result = palindromeList('regex', input, separator); const result = palindromeList('regex', input, separator);
expect(result).toBe('true,true,false'); expect(result).toBe('true,true,false');
}); });
test('should return empty string for empty input', () => { test('should return empty string for empty input', () => {
const input = ''; const input = '';
const separator = '|'; const separator = '|';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe(''); expect(result).toBe('');
}); });
test('should split using custom separator', () => { test('should split using custom separator', () => {
const input = 'racecar;abba;hello'; const input = 'racecar;abba;hello';
const separator = ';'; const separator = ';';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe('true;true;false'); expect(result).toBe('true;true;false');
}); });
test('should handle leading and trailing spaces', () => { test('should handle leading and trailing spaces', () => {
const input = ' racecar | abba | hello '; const input = ' racecar | abba | hello ';
const separator = '|'; const separator = '|';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe('true|true|false'); expect(result).toBe('true|true|false');
}); });
test('should handle multilines checking with trimming', () => { test('should handle multilines checking with trimming', () => {
const input = ' racecar \n abba \n hello '; const input = ' racecar \n abba \n hello ';
const separator = '\n'; const separator = '\n';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe('true\ntrue\nfalse'); expect(result).toBe('true\ntrue\nfalse');
}); });
test('should handle empty strings in input', () => { test('should handle empty strings in input', () => {
const input = 'racecar||hello'; const input = 'racecar||hello';
const separator = '|'; const separator = '|';
const result = palindromeList('symbol', input, separator); const result = palindromeList('symbol', input, separator);
expect(result).toBe('true|true|false'); expect(result).toBe('true|true|false');
}); });
}); });

View File

@@ -1,47 +1,41 @@
export type SplitOperatorType = 'symbol' | 'regex'; export type SplitOperatorType = 'symbol' | 'regex';
function isPalindrome( function isPalindrome(word: string, left: number, right: number): boolean {
word: string, if (left >= right) return true;
left: number, if (word[left] !== word[right]) return false;
right: number
): boolean {
if (left >= right) return true;
if (word[left] !== word[right]) return false;
return isPalindrome(word, left + 1, right - 1); return isPalindrome(word, left + 1, right - 1);
} }
// check each word of the input and add the palindrome status in an array // check each word of the input and add the palindrome status in an array
function checkPalindromes(array: string[]): boolean[] { function checkPalindromes(array: string[]): boolean[] {
let status: boolean[] = []; const status: boolean[] = [];
for (const word of array) { for (const word of array) {
const palindromeStatus = isPalindrome(word, 0, word.length - 1); const palindromeStatus = isPalindrome(word, 0, word.length - 1);
status.push(palindromeStatus); status.push(palindromeStatus);
} }
return status; return status;
} }
export function palindromeList( export function palindromeList(
splitOperatorType: SplitOperatorType, splitOperatorType: SplitOperatorType,
input: string, input: string,
separator: string, // the splitting separator will be the joining separator for visual satisfaction separator: string // the splitting separator will be the joining separator for visual satisfaction
): string { ): string {
if (!input) return ''; if (!input) return '';
let array: string[]; let array: string[];
switch (splitOperatorType) { switch (splitOperatorType) {
case 'symbol': case 'symbol':
array = input.split(separator); array = input.split(separator);
break; break;
case 'regex': case 'regex':
array = input.split(new RegExp(separator)); array = input.split(new RegExp(separator));
break; break;
} }
// trim all items to focus on the word and not biasing the result due to spaces (leading and trailing) // trim all items to focus on the word and not biasing the result due to spaces (leading and trailing)
array = array.map((item) => item.trim()); array = array.map((item) => item.trim());
const statusArray = checkPalindromes(array); const statusArray = checkPalindromes(array);
return statusArray.map(status => status.toString()).join(separator);
return statusArray.map((status) => status.toString()).join(separator);
} }

View File

@@ -2,47 +2,49 @@ import { expect, describe, it } from 'vitest';
import { randomizeCase } from './service'; import { randomizeCase } from './service';
describe('randomizeCase', () => { describe('randomizeCase', () => {
it('should randomize the case of each character in the string', () => { it('should randomize the case of each character in the string', () => {
const input = 'hello world'; const input = 'hello world';
const result = randomizeCase(input); const result = randomizeCase(input);
// Ensure the output length is the same // Ensure the output length is the same
expect(result).toHaveLength(input.length); expect(result).toHaveLength(input.length);
// Ensure each character in the input string appears in the result // Ensure each character in the input string appears in the result
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
const inputChar = input[i]; const inputChar = input[i];
const resultChar = result[i]; const resultChar = result[i];
if (/[a-zA-Z]/.test(inputChar)) { if (/[a-zA-Z]/.test(inputChar)) {
expect([inputChar.toLowerCase(), inputChar.toUpperCase()]).toContain(resultChar); expect([inputChar.toLowerCase(), inputChar.toUpperCase()]).toContain(
} else { resultChar
expect(inputChar).toBe(resultChar); );
} } else {
} expect(inputChar).toBe(resultChar);
}); }
}
});
it('should handle an empty string', () => { it('should handle an empty string', () => {
const input = ''; const input = '';
const result = randomizeCase(input); const result = randomizeCase(input);
expect(result).toBe(''); expect(result).toBe('');
}); });
it('should handle a string with numbers and symbols', () => { it('should handle a string with numbers and symbols', () => {
const input = '123 hello! @world'; const input = '123 hello! @world';
const result = randomizeCase(input); const result = randomizeCase(input);
// Ensure the output length is the same // Ensure the output length is the same
expect(result).toHaveLength(input.length); expect(result).toHaveLength(input.length);
// Ensure numbers and symbols remain unchanged // Ensure numbers and symbols remain unchanged
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
const inputChar = input[i]; const inputChar = input[i];
const resultChar = result[i]; const resultChar = result[i];
if (!/[a-zA-Z]/.test(inputChar)) { if (!/[a-zA-Z]/.test(inputChar)) {
expect(inputChar).toBe(resultChar); expect(inputChar).toBe(resultChar);
} }
} }
}); });
}); });

View File

@@ -1,6 +1,8 @@
export function randomizeCase(input: string): string { export function randomizeCase(input: string): string {
return input return input
.split('') .split('')
.map(char => (Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase())) .map((char) =>
.join(''); Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase()
)
.join('');
} }

View File

@@ -2,51 +2,51 @@ import { expect, describe, it } from 'vitest';
import { stringReverser } from './service'; import { stringReverser } from './service';
describe('stringReverser', () => { describe('stringReverser', () => {
it('should reverse a single-line string', () => { it('should reverse a single-line string', () => {
const input = 'hello world'; const input = 'hello world';
const result = stringReverser(input, false, false, false); const result = stringReverser(input, false, false, false);
expect(result).toBe('dlrow olleh'); expect(result).toBe('dlrow olleh');
}); });
it('should reverse each line in a multi-line string', () => { it('should reverse each line in a multi-line string', () => {
const input = 'hello\nworld'; const input = 'hello\nworld';
const result = stringReverser(input, true, false, false); const result = stringReverser(input, true, false, false);
expect(result).toBe('olleh\ndlrow'); expect(result).toBe('olleh\ndlrow');
}); });
it('should remove empty items if emptyItems is true', () => { it('should remove empty items if emptyItems is true', () => {
const input = 'hello\n\nworld'; const input = 'hello\n\nworld';
const result = stringReverser(input, true, true, false); const result = stringReverser(input, true, true, false);
expect(result).toBe('olleh\ndlrow'); expect(result).toBe('olleh\ndlrow');
}); });
it('should trim each line if trim is true', () => { it('should trim each line if trim is true', () => {
const input = ' hello \n world '; const input = ' hello \n world ';
const result = stringReverser(input, true, false, true); const result = stringReverser(input, true, false, true);
expect(result).toBe('olleh\ndlrow'); expect(result).toBe('olleh\ndlrow');
}); });
it('should handle empty input', () => { it('should handle empty input', () => {
const input = ''; const input = '';
const result = stringReverser(input, false, false, false); const result = stringReverser(input, false, false, false);
expect(result).toBe(''); expect(result).toBe('');
}); });
it('should handle a single line with emptyItems and trim', () => { it('should handle a single line with emptyItems and trim', () => {
const input = ' hello world '; const input = ' hello world ';
const result = stringReverser(input, false, true, true); const result = stringReverser(input, false, true, true);
expect(result).toBe('dlrow olleh'); expect(result).toBe('dlrow olleh');
}); });
it('should handle a single line with emptyItems and non trim', () => { it('should handle a single line with emptyItems and non trim', () => {
const input = ' hello world '; const input = ' hello world ';
const result = stringReverser(input, false, true, false); const result = stringReverser(input, false, true, false);
expect(result).toBe(' dlrow olleh '); expect(result).toBe(' dlrow olleh ');
}); });
it('should handle a multi line with emptyItems and non trim', () => { it('should handle a multi line with emptyItems and non trim', () => {
const input = ' hello\n\n\n\nworld '; const input = ' hello\n\n\n\nworld ';
const result = stringReverser(input, true, true, false); const result = stringReverser(input, true, true, false);
expect(result).toBe('olleh \n dlrow'); expect(result).toBe('olleh \n dlrow');
}); });
}); });

View File

@@ -1,31 +1,30 @@
import { reverseString } from 'utils/string'; import { reverseString } from 'utils/string';
export function stringReverser( export function stringReverser(
input: string, input: string,
multiLine: boolean, multiLine: boolean,
emptyItems: boolean, emptyItems: boolean,
trim: boolean trim: boolean
) { ) {
let array: string[] = []; let array: string[] = [];
let result: string[] = []; let result: string[] = [];
// split the input in multiLine mode // split the input in multiLine mode
if (multiLine) { if (multiLine) {
array = input.split('\n'); array = input.split('\n');
} } else {
else { array.push(input);
array.push(input); }
}
// handle empty items // handle empty items
if (emptyItems){ if (emptyItems) {
array = array.filter(Boolean); array = array.filter(Boolean);
} }
// Handle trim // Handle trim
if (trim) { if (trim) {
array = array.map(line => line.trim()); array = array.map((line) => line.trim());
} }
result = array.map(element => reverseString(element)); result = array.map((element) => reverseString(element));
return result.join('\n'); return result.join('\n');
} }

View File

@@ -1,3 +1,3 @@
export function UppercaseInput(input: string): string { export function UppercaseInput(input: string): string {
return input.toUpperCase(); return input.toUpperCase();
} }

View File

@@ -2,33 +2,33 @@ import { expect, describe, it } from 'vitest';
import { UppercaseInput } from './service'; import { UppercaseInput } from './service';
describe('UppercaseInput', () => { describe('UppercaseInput', () => {
it('should convert a lowercase string to uppercase', () => { it('should convert a lowercase string to uppercase', () => {
const input = 'hello'; const input = 'hello';
const result = UppercaseInput(input); const result = UppercaseInput(input);
expect(result).toBe('HELLO'); expect(result).toBe('HELLO');
}); });
it('should convert a mixed case string to uppercase', () => { it('should convert a mixed case string to uppercase', () => {
const input = 'HeLLo WoRLd'; const input = 'HeLLo WoRLd';
const result = UppercaseInput(input); const result = UppercaseInput(input);
expect(result).toBe('HELLO WORLD'); expect(result).toBe('HELLO WORLD');
}); });
it('should convert an already uppercase string to uppercase', () => { it('should convert an already uppercase string to uppercase', () => {
const input = 'HELLO'; const input = 'HELLO';
const result = UppercaseInput(input); const result = UppercaseInput(input);
expect(result).toBe('HELLO'); expect(result).toBe('HELLO');
}); });
it('should handle an empty string', () => { it('should handle an empty string', () => {
const input = ''; const input = '';
const result = UppercaseInput(input); const result = UppercaseInput(input);
expect(result).toBe(''); expect(result).toBe('');
}); });
it('should handle a string with numbers and symbols', () => { it('should handle a string with numbers and symbols', () => {
const input = '123 hello! @world'; const input = '123 hello! @world';
const result = UppercaseInput(input); const result = UppercaseInput(input);
expect(result).toBe('123 HELLO! @WORLD'); expect(result).toBe('123 HELLO! @WORLD');
}); });
}); });