fix: misc

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-27 18:55:20 +01:00
parent 1903d316e0
commit dcac733acf
7 changed files with 383 additions and 349 deletions

124
.idea/workspace.xml generated
View File

@@ -6,10 +6,12 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="style: lint"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="style: lint">
<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/components/ToolInputAndResult.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/ToolInputAndResult.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/options/ToolOptions.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/options/ToolOptions.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/number/generate/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/generate/index.tsx" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/sort/meta.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/meta.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/number/generate/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/number/generate/service.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/list/sort/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/list/sort/sort.service.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/list/sort/sort.service.test.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/utils/string.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/utils/string.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" />
@@ -25,7 +27,7 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$" value="chesterking" /> <entry key="$PROJECT_DIR$" value="main" />
</map> </map>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@@ -46,43 +48,43 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;, "ASKED_ADD_EXTERNAL_FILES": "true",
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;Playwright.JoinText Component.executor&quot;: &quot;Run&quot;, "Playwright.JoinText Component.executor": "Run",
&quot;Playwright.JoinText Component.should merge text pieces with specified join character.executor&quot;: &quot;Run&quot;, "Playwright.JoinText Component.should merge text pieces with specified join character.executor": "Run",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;Vitest.compute function (1).executor&quot;: &quot;Run&quot;, "Vitest.compute function (1).executor": "Run",
&quot;Vitest.compute function.executor&quot;: &quot;Run&quot;, "Vitest.compute function.executor": "Run",
&quot;Vitest.mergeText.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.executor": "Run",
&quot;Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.should merge lines and preserve blank lines when deleteBlankLines is false.executor": "Run",
&quot;Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor&quot;: &quot;Run&quot;, "Vitest.mergeText.should merge lines, preserve blank lines and trailing spaces when both deleteBlankLines and deleteTrailingSpaces are false.executor": "Run",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "chesterkxng",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;, "kotlin-language-version-configured": "true",
&quot;last_opened_file_path&quot;: &quot;C:/Users/HP/IdeaProjects/omni-tools/src/assets&quot;, "last_opened_file_path": "C:/Users/HP/IdeaProjects/omni-tools/src/assets",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;npm.dev.executor&quot;: &quot;Run&quot;, "npm.dev.executor": "Run",
&quot;npm.lint.executor&quot;: &quot;Run&quot;, "npm.lint.executor": "Run",
&quot;npm.prebuild.executor&quot;: &quot;Run&quot;, "npm.prebuild.executor": "Run",
&quot;npm.script:create:tool.executor&quot;: &quot;Run&quot;, "npm.script:create:tool.executor": "Run",
&quot;npm.test.executor&quot;: &quot;Run&quot;, "npm.test.executor": "Run",
&quot;npm.test:e2e.executor&quot;: &quot;Run&quot;, "npm.test:e2e.executor": "Run",
&quot;prettierjs.PrettierConfiguration.Package&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier&quot;, "prettierjs.PrettierConfiguration.Package": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\prettier",
&quot;project.structure.last.edited&quot;: &quot;Problems&quot;, "project.structure.last.edited": "Problems",
&quot;project.structure.proportion&quot;: &quot;0.0&quot;, "project.structure.proportion": "0.0",
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;, "project.structure.side.proportion": "0.2",
&quot;settings.editor.selected.configurable&quot;: &quot;settings.typescriptcompiler&quot;, "settings.editor.selected.configurable": "settings.typescriptcompiler",
&quot;ts.external.directory.path&quot;: &quot;C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib&quot;, "ts.external.directory.path": "C:\\Users\\HP\\IdeaProjects\\omni-tools\\node_modules\\typescript\\lib",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="ReactDesignerToolWindowState"> <component name="ReactDesignerToolWindowState">
<option name="myId2Visible"> <option name="myId2Visible">
<map> <map>
@@ -107,19 +109,7 @@
<recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" /> <recent name="C:\Users\HP\IdeaProjects\omni-tools\src\tools" />
</key> </key>
</component> </component>
<component name="RunManager" selected="npm.dev"> <component name="RunManager" selected="npm.test">
<configuration name="JoinText Component" type="JavaScriptTestRunnerPlaywright" temporary="true" nameIsGenerated="true">
<node-interpreter value="project" />
<playwright-package value="$PROJECT_DIR$/node_modules/@playwright/test" />
<working-dir value="$PROJECT_DIR$" />
<envs />
<scope-kind value="SUITE" />
<test-file value="$PROJECT_DIR$/src/pages/string/join/string-join.e2e.spec.ts" />
<test-names>
<test-name value="JoinText Component" />
</test-names>
<method v="2" />
</configuration>
<configuration name="JoinText Component.should merge text pieces with specified join character" type="JavaScriptTestRunnerPlaywright" temporary="true" nameIsGenerated="true"> <configuration name="JoinText Component.should merge text pieces with specified join character" type="JavaScriptTestRunnerPlaywright" temporary="true" nameIsGenerated="true">
<node-interpreter value="project" /> <node-interpreter value="project" />
<playwright-package value="$PROJECT_DIR$/node_modules/@playwright/test" /> <playwright-package value="$PROJECT_DIR$/node_modules/@playwright/test" />
@@ -153,6 +143,16 @@
<envs /> <envs />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="test" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" />
<command value="run" />
<scripts>
<script value="test" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
<configuration name="test:e2e" type="js.build_tools.npm" temporary="true" nameIsGenerated="true"> <configuration name="test:e2e" type="js.build_tools.npm" temporary="true" nameIsGenerated="true">
<package-json value="$PROJECT_DIR$/package.json" /> <package-json value="$PROJECT_DIR$/package.json" />
<command value="run" /> <command value="run" />
@@ -165,11 +165,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="npm.test" />
<item itemvalue="npm.dev" /> <item itemvalue="npm.dev" />
<item itemvalue="npm.lint" /> <item itemvalue="npm.lint" />
<item itemvalue="npm.test:e2e" /> <item itemvalue="npm.test:e2e" />
<item itemvalue="Playwright.JoinText Component.should merge text pieces with specified join character" /> <item itemvalue="Playwright.JoinText Component.should merge text pieces with specified join character" />
<item itemvalue="Playwright.JoinText Component" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@@ -609,7 +609,19 @@
<map> <map>
<entry key="MAIN"> <entry key="MAIN">
<value> <value>
<State /> <State>
<option name="FILTERS">
<map>
<entry key="branch">
<value>
<list>
<option value="origin/chesterkxng" />
</list>
</value>
</entry>
</map>
</option>
</State>
</value> </value>
</entry> </entry>
</map> </map>

View File

@@ -21,7 +21,7 @@
"test:e2e:run": "playwright test", "test:e2e:run": "playwright test",
"test:ui": "vitest --ui", "test:ui": "vitest --ui",
"script:create:tool": "node scripts/create-tool.mjs", "script:create:tool": "node scripts/create-tool.mjs",
"lint": "eslint src --max-warnings=0", "lint": "eslint src --max-warnings=0 --fix",
"typecheck": "tsc --project tsconfig.json --noEmit", "typecheck": "tsc --project tsconfig.json --noEmit",
"prepare": "husky install" "prepare": "husky install"
}, },

View File

@@ -8,4 +8,4 @@ const validationSchema = Yup.object({
}); });
export default function Sort() { export default function Sort() {
return <Box>Lorem ipsum</Box>; return <Box>Lorem ipsum</Box>;
} }

View File

@@ -10,4 +10,4 @@ export const tool = defineTool('list', {
shortDescription: '', shortDescription: '',
keywords: ['sort'], keywords: ['sort'],
component: lazy(() => import('./index')) component: lazy(() => import('./index'))
}); });

View File

@@ -1,117 +1,123 @@
import { isNumber } from "utils/string"; import { isNumber } from 'utils/string';
export type SortingMethod = 'numeric' | 'alphabetic' | 'length'; export type SortingMethod = 'numeric' | 'alphabetic' | 'length';
export type SplitOperatorType = 'symbol' | 'regex'; export type SplitOperatorType = 'symbol' | 'regex';
// utils function that choose the way of numeric sorting mixed types of array // utils function that choose the way of numeric sorting mixed types of array
function customNumericSort(a: string, b: string, increasing: boolean): number { function customNumericSort(a: string, b: string, increasing: boolean): number {
const formattedA = isNumber(a) ? Number(a) : a;
const formattedA = isNumber(a) ? Number(a) : a; const formattedB = isNumber(b) ? Number(b) : b;
const formattedB = isNumber(b) ? Number(b) : b; if (typeof formattedA === 'number' && typeof formattedB === 'number') {
if (typeof formattedA === 'number' && typeof formattedB === 'number') { return increasing ? formattedA - formattedB : formattedB - formattedA;
let result: number = increasing ? (formattedA - formattedB) : (formattedB - formattedA); } else if (typeof formattedA === 'string' && typeof formattedB === 'string') {
return result; return formattedA.localeCompare(formattedB); // Lexicographical comparison for strings
} else if (typeof formattedA === 'string' && typeof formattedB === 'string') { } else if (typeof formattedA === 'number' && typeof formattedB === 'string') {
return formattedA.localeCompare(formattedB); // Lexicographical comparison for strings return -1; // Numbers before strings
} else if (typeof formattedA === 'number' && typeof formattedB === 'string') { } else {
return -1; // Numbers before strings return 1; // Strings after numbers
} else { }
return 1; // Strings after numbers
}
} }
export function numericSort( export function numericSort(
array: string[], // array we build after parsing the input array: string[], // array we build after parsing the input
increasing: boolean, increasing: boolean,
joinSeparator: string, joinSeparator: string,
removeDuplicated: boolean // the value if the checkbox has been selected 1 else 0 removeDuplicated: boolean // the value if the checkbox has been selected 1 else 0
) { ) {
array.sort((a, b) => customNumericSort(a, b, increasing)); array.sort((a, b) => customNumericSort(a, b, increasing));
if (removeDuplicated) { if (removeDuplicated) {
array = array.filter((item, index) => array.indexOf(item) === index); array = array.filter((item, index) => array.indexOf(item) === index);
} }
return array.join(joinSeparator); return array.join(joinSeparator);
} }
// utils function that choose the way of numeric sorting mixed types of array // utils function that choose the way of numeric sorting mixed types of array
function customLengthSort(a: string, b: string, increasing: boolean): number { function customLengthSort(a: string, b: string, increasing: boolean): number {
let result: number = increasing ? (a.length - b.length) : (b.length - a.length); return increasing ? a.length - b.length : b.length - a.length;
return result;
} }
export function lengthSort( export function lengthSort(
array: string[], // array we build after parsing the input array: string[], // array we build after parsing the input
increasing: boolean, // select value has to be increasing for increasing order and decreasing for decreasing order increasing: boolean, // select value has to be increasing for increasing order and decreasing for decreasing order
joinSeparator: string, joinSeparator: string,
removeDuplicated: boolean // the value if the checkbox has been selected 1 else 0 removeDuplicated: boolean // the value if the checkbox has been selected 1 else 0
) { ) {
array.sort((a, b) => customLengthSort(a, b, increasing)); array.sort((a, b) => customLengthSort(a, b, increasing));
if (removeDuplicated) { if (removeDuplicated) {
array = array.filter((item, index) => array.indexOf(item) === index); array = array.filter((item, index) => array.indexOf(item) === index);
} }
return array.join(joinSeparator); return array.join(joinSeparator);
} }
// Utils function that chooses the way of alphabetic sorting mixed types of array // Utils function that chooses the way of alphabetic sorting mixed types of array
function customAlphabeticSort(a: string, b: string, caseSensitive: boolean): number { function customAlphabeticSort(
if (!caseSensitive) { a: string,
// Case-insensitive comparison b: string,
return a.toLowerCase().localeCompare(b.toLowerCase()); caseSensitive: boolean
} else { ): number {
// Case-sensitive comparison if (!caseSensitive) {
return a.charCodeAt(0) - b.charCodeAt(0); // Case-insensitive comparison
} return a.toLowerCase().localeCompare(b.toLowerCase());
} else {
// Case-sensitive comparison
return a.charCodeAt(0) - b.charCodeAt(0);
}
} }
export function alphabeticSort( export function alphabeticSort(
array: string[], // array we build after parsing the input array: string[], // array we build after parsing the input
increasing: boolean, // select value has to be "increasing" for increasing order and "decreasing" for decreasing order increasing: boolean, // select value has to be "increasing" for increasing order and "decreasing" for decreasing order
joinSeparator: string, joinSeparator: string,
removeDuplicated: boolean, // the value if the checkbox has been selected 1 else 0 removeDuplicated: boolean, // the value if the checkbox has been selected 1 else 0
caseSensitive: boolean // the value if the checkbox has been selected 1 else 0 caseSensitive: boolean // the value if the checkbox has been selected 1 else 0
)
{
array.sort((a, b) => customAlphabeticSort(a, b, caseSensitive));
if (!increasing){
array.reverse();
}
if (removeDuplicated) {
array = array.filter((item, index) => array.indexOf(item) === index);
}
return array.join(joinSeparator);
}
// main function
export function Sort(
sortingMethod: SortingMethod,
splitOperatorType: SplitOperatorType,
input: string,
increasing: boolean,
splitSeparator: string,
joinSeparator: string,
removeDuplicated: boolean,
caseSensitive: boolean
) { ) {
let array: string[]; array.sort((a, b) => customAlphabeticSort(a, b, caseSensitive));
switch(splitOperatorType) { if (!increasing) {
case 'symbol': array.reverse();
array = input.split(splitSeparator); }
break; if (removeDuplicated) {
case 'regex': array = array.filter((item, index) => array.indexOf(item) === index);
array = input.split(new RegExp(splitSeparator)); }
break; return array.join(joinSeparator);
}
let result : string;
switch(sortingMethod) {
case 'numeric':
result = numericSort(array, increasing, joinSeparator, removeDuplicated);
break;
case 'length':
result = lengthSort(array, increasing, joinSeparator, removeDuplicated);
break;
case 'alphabetic':
result = alphabeticSort(array, increasing, joinSeparator, removeDuplicated, caseSensitive);
break;
}
return result;
} }
// main function
export function Sort(
sortingMethod: SortingMethod,
splitOperatorType: SplitOperatorType,
input: string,
increasing: boolean,
splitSeparator: string,
joinSeparator: string,
removeDuplicated: boolean,
caseSensitive: boolean
) {
let array: string[];
switch (splitOperatorType) {
case 'symbol':
array = input.split(splitSeparator);
break;
case 'regex':
array = input.split(new RegExp(splitSeparator));
break;
}
let result: string;
switch (sortingMethod) {
case 'numeric':
result = numericSort(array, increasing, joinSeparator, removeDuplicated);
break;
case 'length':
result = lengthSort(array, increasing, joinSeparator, removeDuplicated);
break;
case 'alphabetic':
result = alphabeticSort(
array,
increasing,
joinSeparator,
removeDuplicated,
caseSensitive
);
break;
}
return result;
}

View File

@@ -1,39 +1,92 @@
// Import necessary modules and functions // Import necessary modules and functions
import { describe, it, expect } from 'vitest'; import { describe, it, expect } from 'vitest';
import { import {
alphabeticSort, lengthSort, numericSort, Sort, alphabeticSort,
SplitOperatorType, SortingMethod lengthSort,
numericSort,
Sort,
SplitOperatorType,
SortingMethod
} from './service'; } from './service';
// Define test cases for the numericSort function // Define test cases for the numericSort function
describe('numericSort function', () => { describe('numericSort function', () => {
it('should sort a list in increasing order with comma separator not removeduplicated elements', () => { it('should sort a list in increasing order with comma separator not removeduplicated elements', () => {
const array: string[] = ['9', '8', '7', '4', '2', '2', '5']; const array: string[] = ['9', '8', '7', '4', '2', '2', '5'];
const increasing: boolean = true; const increasing: boolean = true;
const separator = ', '; const separator = ', ';
const removeDuplicated: boolean = false; const removeDuplicated: boolean = false;
const result = numericSort(array, increasing, separator, removeDuplicated); const result = numericSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('2, 2, 4, 5, 7, 8, 9'); expect(result).toBe('2, 2, 4, 5, 7, 8, 9');
}); });
it('should sort a list in decreasing order with " - " separator and remove duplicated elements', () => { it('should sort a list in decreasing order with " - " separator and remove duplicated elements', () => {
const array: string[] = ['2', '4', '4', '9', '6', '6', '7']; const array: string[] = ['2', '4', '4', '9', '6', '6', '7'];
const increasing: boolean = false; const increasing: boolean = false;
const separator = ' - '; const separator = ' - ';
const removeDuplicated: boolean = true; const removeDuplicated: boolean = true;
const result = numericSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('9 - 7 - 6 - 4 - 2');
});
it('should sort a list with numbers and characters and remove duplicated elements', () => {
const array: string[] = ['d', 'd', 'n', 'p', 'h', 'h', '6', '9', '7', '5'];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const result = numericSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('5 6 7 9 d h n p');
});
// Define test cases for the lengthSort function
describe('lengthSort function', () => {
it('should sort a list of number by length in increasing order with comma separator ', () => {
const array: string[] = ['415689521', '3', '126', '12', '1523'];
const increasing: boolean = true;
const separator = ', ';
const removeDuplicated: boolean = false;
const result = lengthSort(array, increasing, separator, removeDuplicated); const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('3, 12, 126, 1523, 415689521'); expect(result).toBe('3, 12, 126, 1523, 415689521');
}); });
it('should sort a list with numbers and characters and remove duplicated elements', () => { it('should sort a list of number by length in increasing order and remove duplicated elements ', () => {
const array: string[] = ['d', 'd', 'n', 'p', 'h', 'h', '6', '9', '7', '5']; const array: string[] = [
const increasing: boolean = true; '415689521',
const separator = ' '; '3',
const removeDuplicated: boolean = true; '3',
'126',
'12',
'12',
'1523'
];
const increasing: boolean = true;
const separator = ', ';
const removeDuplicated: boolean = true;
const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('3, 12, 126, 1523, 415689521');
});
it('should sort a mixed array by length in increasing order ', () => {
const array: string[] = [
'ddd',
'd',
'nfg',
'p',
'h',
'h',
'6555',
'9',
'7',
'5556'
];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const result = lengthSort(array, increasing, separator, removeDuplicated); const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('d p h 9 7 ddd nfg 6555 5556'); expect(result).toBe('d p h 9 7 ddd nfg 6555 5556');
@@ -44,7 +97,7 @@ describe('numericSort function', () => {
describe('alphabeticSort function', () => { describe('alphabeticSort function', () => {
// NON CASE SENSITIVE TEST // NON CASE SENSITIVE TEST
it('should sort a list of string in increasing order with comma separator ', () => { it('should sort a list of string in increasing order with comma separator ', () => {
const array: any[] = ['apple', 'pineaple', 'lemon', 'orange']; const array: string[] = ['apple', 'pineaple', 'lemon', 'orange'];
const increasing: boolean = true; const increasing: boolean = true;
const separator = ', '; const separator = ', ';
const removeDuplicated: boolean = false; const removeDuplicated: boolean = false;
@@ -60,47 +113,31 @@ describe('numericSort function', () => {
expect(result).toBe('apple, lemon, orange, pineaple'); expect(result).toBe('apple, lemon, orange, pineaple');
}); });
// Define test cases for the lengthSort function it('should sort a list of string in decreasing order with comma separator ', () => {
describe('lengthSort function', () => { const array: string[] = ['apple', 'pineaple', 'lemon', 'orange'];
it('should sort a list of number by length in increasing order with comma separator ', () => { const increasing: boolean = false;
const array: string[] = ['415689521', '3', '126', '12', '1523']; const separator = ', ';
const increasing: boolean = true; const removeDuplicated: boolean = false;
const separator = ', '; const caseSensitive: boolean = false;
const removeDuplicated: boolean = false;
const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('3, 12, 126, 1523, 415689521');
});
it('should sort a list of number by length in increasing order and remove duplicated elements ', () => {
const array: string[] = ['415689521', '3', '3', '126', '12', '12', '1523'];
const increasing: boolean = true;
const separator = ', ';
const removeDuplicated: boolean = true;
const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('3, 12, 126, 1523, 415689521');
});
it('should sort a mixed array by length in increasing order ', () => {
const array: string[] = ['ddd', 'd', 'nfg', 'p', 'h', 'h', '6555', '9', '7', '5556'];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('d p h 9 7 ddd nfg 6555 5556');
});
const result = alphabeticSort(
array,
increasing,
separator,
removeDuplicated,
caseSensitive
);
expect(result).toBe('pineaple, orange, lemon, apple');
});
it('should sort a list of string and symbols (uppercase and lower) in increasing order with comma separator ', () => { it('should sort a list of string and symbols (uppercase and lower) in increasing order with comma separator ', () => {
const array: any[] = [ const array: string[] = [
'Apple', 'Apple',
'pineaple', 'pineaple',
'lemon', 'lemon',
'Orange', 'Orange',
1, '1',
9, '9',
'@', '@',
'+' '+'
]; ];
@@ -120,13 +157,13 @@ describe('numericSort function', () => {
}); });
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => { it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: any[] = [ const array: string[] = [
'Apple', 'Apple',
'pineaple', 'pineaple',
'lemon', 'lemon',
'Orange', 'Orange',
1, '1',
9, '9',
'@', '@',
'+' '+'
]; ];
@@ -145,150 +182,80 @@ describe('numericSort function', () => {
expect(result).toBe('pineaple Orange lemon Apple 9 1 + @'); expect(result).toBe('pineaple Orange lemon Apple 9 1 + @');
}); });
// Define test cases for the alphabeticSort function // CASE SENSITIVE TEST
describe('alphabeticSort function', () => { it('should sort a list of string (uppercase) in decreasing order with comma separator ', () => {
// NON CASE SENSITIVE TEST const array: string[] = ['Apple', 'Pineaple', 'Lemon', 'Orange'];
it('should sort a list of string in increasing order with comma separator ', () => { const increasing: boolean = false;
const array: string[] = ['apple', 'pineaple', 'lemon', 'orange']; const separator = ' ';
const increasing: boolean = true; const removeDuplicated: boolean = false;
const separator = ', '; const caseSensitive: boolean = true;
const removeDuplicated: boolean = false;
const caseSensitive: boolean = false;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive); const result = alphabeticSort(
expect(result).toBe('apple, lemon, orange, pineaple'); array,
}); increasing,
separator,
it('should sort a list of string in decreasing order with comma separator ', () => { removeDuplicated,
const array: string[] = ['apple', 'pineaple', 'lemon', 'orange']; caseSensitive
const increasing: boolean = false; );
const separator = ', '; expect(result).toBe('Pineaple Orange Lemon Apple');
const removeDuplicated: boolean = false;
const caseSensitive: boolean = false;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('pineaple, orange, lemon, apple');
});
it('should sort a list of string and symbols (uppercase and lower) in increasing order with comma separator ', () => {
const array: string[] = ['Apple', 'pineaple', 'lemon', 'Orange', '1', '9', '@', '+'];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = false;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('@ + 1 9 Apple lemon Orange pineaple');
});
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: string[] = ['Apple', 'pineaple', 'lemon', 'Orange', '1', '9', '@', '+'];
const increasing: boolean = false;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = false;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('pineaple Orange lemon Apple 9 1 + @');
});
// CASE SENSITIVE TEST
it('should sort a list of string (uppercase) in decreasing order with comma separator ', () => {
const array: string[] = ['Apple', 'Pineaple', 'Lemon', 'Orange'];
const increasing: boolean = false;
const separator = ' ';
const removeDuplicated: boolean = false;
const caseSensitive: boolean = true;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('Pineaple Orange Lemon Apple');
});
it('should sort a list of string (uppercase and lowercase) in increasing order with comma separator ', () => {
const array: string[] = ['Apple', 'pineaple', 'lemon', 'Orange', '1', '9'];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('1 9 Apple Orange lemon pineaple');
});
it('should sort a list of string (uppercase and lower) in decreasing order with comma separator ', () => {
const array: string[] = ['Apple', 'pineaple', 'lemon', 'Orange', '1', '9'];
const increasing: boolean = false;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('pineaple lemon Orange Apple 9 1');
});
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: string[] = ['Apple', 'pineaple', 'lemon', 'Orange', '1', '9', '@', '+'];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('+ 1 9 @ Apple Orange lemon pineaple');
});
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: string[] = ['Apple', 'pineaple', 'lemon', 'Orange', '1', '9', '@', '+'];
const increasing: boolean = false;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive);
expect(result).toBe('pineaple lemon Orange Apple @ 9 1 +');
});
}); });
// Define test cases for the lengthSort function it('should sort a list of string (uppercase and lowercase) in increasing order with comma separator ', () => {
describe('main function', () => { const array: string[] = [
it('should do everything alph', () => {
const sortingMethod: SortingMethod = 'alphabetic';
const splitOperatorType : SplitOperatorType = 'symbol';
const input: string = 'Apple pineaple lemon Orange 1 9 @ +';
const increasing: boolean = true;
const splitSeparator: string = ' ';
const joinSeparator: string = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = Sort(sortingMethod, splitOperatorType, input, increasing, splitSeparator, joinSeparator, removeDuplicated, caseSensitive);
expect(result).toBe('+ 1 9 @ Apple Orange lemon pineaple');
});
it('should do everything numeric', () => {
const sortingMethod: SortingMethod = 'numeric';
const splitOperatorType : SplitOperatorType = 'symbol';
const input: string = '1 6 9 4 6 7 3 5 8';
const increasing: boolean = true;
const splitSeparator: string = ' ';
const joinSeparator: string = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = Sort(sortingMethod, splitOperatorType, input, increasing, splitSeparator, joinSeparator, removeDuplicated, caseSensitive);
expect(result).toBe('1 3 4 5 6 7 8 9');
});
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: any[] = [
'Apple', 'Apple',
'pineaple', 'pineaple',
'lemon', 'lemon',
'Orange', 'Orange',
1, '1',
9, '9'
];
const increasing: boolean = true;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = alphabeticSort(
array,
increasing,
separator,
removeDuplicated,
caseSensitive
);
expect(result).toBe('1 9 Apple Orange lemon pineaple');
});
it('should sort a list of string (uppercase and lower) in decreasing order with comma separator ', () => {
const array: string[] = [
'Apple',
'pineaple',
'lemon',
'Orange',
'1',
'9'
];
const increasing: boolean = false;
const separator = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = alphabeticSort(
array,
increasing,
separator,
removeDuplicated,
caseSensitive
);
expect(result).toBe('pineaple lemon Orange Apple 9 1');
});
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: string[] = [
'Apple',
'pineaple',
'lemon',
'Orange',
'1',
'9',
'@', '@',
'+' '+'
]; ];
@@ -308,13 +275,13 @@ describe('numericSort function', () => {
}); });
it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => { it('should sort a list of string and symbols (uppercase and lower) in decreasing order with comma separator ', () => {
const array: any[] = [ const array: string[] = [
'Apple', 'Apple',
'pineaple', 'pineaple',
'lemon', 'lemon',
'Orange', 'Orange',
1, '1',
9, '9',
'@', '@',
'+' '+'
]; ];
@@ -332,5 +299,54 @@ describe('numericSort function', () => {
); );
expect(result).toBe('pineaple lemon Orange Apple @ 9 1 +'); expect(result).toBe('pineaple lemon Orange Apple @ 9 1 +');
}); });
});
// Define test cases for the lengthSort function
describe('main function', () => {
it('should do everything alph', () => {
const sortingMethod: SortingMethod = 'alphabetic';
const splitOperatorType: SplitOperatorType = 'symbol';
const input: string = 'Apple pineaple lemon Orange 1 9 @ +';
const increasing: boolean = true;
const splitSeparator: string = ' ';
const joinSeparator: string = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = Sort(
sortingMethod,
splitOperatorType,
input,
increasing,
splitSeparator,
joinSeparator,
removeDuplicated,
caseSensitive
);
expect(result).toBe('+ 1 9 @ Apple Orange lemon pineaple');
});
it('should do everything numeric', () => {
const sortingMethod: SortingMethod = 'numeric';
const splitOperatorType: SplitOperatorType = 'symbol';
const input: string = '1 6 9 4 6 7 3 5 8';
const increasing: boolean = true;
const splitSeparator: string = ' ';
const joinSeparator: string = ' ';
const removeDuplicated: boolean = true;
const caseSensitive: boolean = true;
const result = Sort(
sortingMethod,
splitOperatorType,
input,
increasing,
splitSeparator,
joinSeparator,
removeDuplicated,
caseSensitive
);
expect(result).toBe('1 3 4 5 6 7 8 9');
});
});
}); });

View File

@@ -5,4 +5,4 @@ export function capitalizeFirstLetter(string: string | undefined) {
export function isNumber(number: any) { export function isNumber(number: any) {
return !isNaN(parseFloat(number)) && isFinite(number); return !isNaN(parseFloat(number)) && isFinite(number);
} }