style: lint

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-27 15:51:33 +01:00
parent 0c501055e6
commit d75043d282
3 changed files with 331 additions and 236 deletions

32
.idea/workspace.xml generated
View File

@@ -4,10 +4,10 @@
<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="chore: remove unused deps"> <list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: misc">
<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/home/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/home/index.tsx" 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/video/gif/change-speed/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/video/gif/change-speed/index.tsx" 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" />
</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" />
@@ -200,15 +200,9 @@
<workItem from="1719363272227" duration="390000" /> <workItem from="1719363272227" duration="390000" />
<workItem from="1719379971872" duration="8943000" /> <workItem from="1719379971872" duration="8943000" />
<workItem from="1719464673797" duration="38000" /> <workItem from="1719464673797" duration="38000" />
<workItem from="1719475764139" duration="14630000" /> <workItem from="1719475764139" duration="14903000" />
</task> <workItem from="1719492452780" duration="8000" />
<task id="LOCAL-00022" summary="feat: react helmet"> <workItem from="1719496624579" duration="2920000" />
<option name="closed" value="true" />
<created>1719085085537</created>
<option name="number" value="00022" />
<option name="presentableId" value="LOCAL-00022" />
<option name="project" value="LOCAL" />
<updated>1719085085537</updated>
</task> </task>
<task id="LOCAL-00023" summary="feat: tools normalized"> <task id="LOCAL-00023" summary="feat: tools normalized">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -594,7 +588,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1719488576835</updated> <updated>1719488576835</updated>
</task> </task>
<option name="localTasksCounter" value="71" /> <task id="LOCAL-00071" summary="fix: misc">
<option name="closed" value="true" />
<created>1719491470485</created>
<option name="number" value="00071" />
<option name="presentableId" value="LOCAL-00071" />
<option name="project" value="LOCAL" />
<updated>1719491470485</updated>
</task>
<option name="localTasksCounter" value="72" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -615,7 +617,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="feat: change colors in png init" />
<MESSAGE value="feat: change colors in png" /> <MESSAGE value="feat: change colors in png" />
<MESSAGE value="chore: ResultFooter" /> <MESSAGE value="chore: ResultFooter" />
<MESSAGE value="feat: change color in png finished" /> <MESSAGE value="feat: change color in png finished" />
@@ -640,7 +641,8 @@
<MESSAGE value="refactor: optimize imports" /> <MESSAGE value="refactor: optimize imports" />
<MESSAGE value="feat: change gif speed" /> <MESSAGE value="feat: change gif speed" />
<MESSAGE value="chore: remove unused deps" /> <MESSAGE value="chore: remove unused deps" />
<option name="LAST_COMMIT_MESSAGE" value="chore: remove unused deps" /> <MESSAGE value="fix: misc" />
<option name="LAST_COMMIT_MESSAGE" value="fix: misc" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View File

@@ -1,77 +1,90 @@
// 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: number | string, b: number | string, increasing: boolean): number { function customNumericSort(
if (typeof a === 'number' && typeof b === 'number') { a: number | string,
let result: number = increasing ? (a - b) : (b - a); b: number | string,
return result; increasing: boolean
} else if (typeof a === 'string' && typeof b === 'string') { ): number {
return a.localeCompare(b); // Lexicographical comparison for strings if (typeof a === 'number' && typeof b === 'number') {
} else if (typeof a === 'number' && typeof b === 'string') { let result: number = increasing ? a - b : b - a;
return -1; // Numbers before strings return result;
} else { } else if (typeof a === 'string' && typeof b === 'string') {
return 1; // Strings after numbers return a.localeCompare(b); // Lexicographical comparison for strings
} } else if (typeof a === 'number' && typeof b === 'string') {
return -1; // Numbers before strings
} else {
return 1; // Strings after numbers
}
} }
export function numericSort( export function numericSort(
array: any[], // array we build after parsing the input array: any[], // array we build after parsing the input
increasing: boolean, increasing: boolean,
separator: string, separator: 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(separator); return array.join(separator);
} }
// 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: number | string, b: number | string, increasing: boolean): number { function customLengthSort(
let result: number = increasing ? (a.toString().length - b.toString().length) : (b.toString().length - a.toString().length); a: number | string,
return result; b: number | string,
increasing: boolean
): number {
let result: number = increasing
? a.toString().length - b.toString().length
: b.toString().length - a.toString().length;
return result;
} }
export function lengthSort( export function lengthSort(
array: any[], // array we build after parsing the input array: any[], // 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
separator: string, separator: 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(separator); return array.join(separator);
} }
// 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: number | string, b: number | string, caseSensitive: boolean): number { function customAlphabeticSort(
const stringA : string = a.toString(); a: number | string,
const stringB : string = b.toString(); b: number | string,
caseSensitive: boolean
): number {
const stringA: string = a.toString();
const stringB: string = b.toString();
if (!caseSensitive) { if (!caseSensitive) {
// Case-insensitive comparison // Case-insensitive comparison
return stringA.toLowerCase().localeCompare(stringB.toLowerCase()); return stringA.toLowerCase().localeCompare(stringB.toLowerCase());
} else { } else {
// Case-sensitive comparison // Case-sensitive comparison
return stringA.charCodeAt(0) - stringB.charCodeAt(0); return stringA.charCodeAt(0) - stringB.charCodeAt(0);
} }
} }
export function alphabeticSort( export function alphabeticSort(
array: any[], // array we build after parsing the input array: any[], // 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
separator: string, separator: 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));
array.sort((a, b) => customAlphabeticSort(a, b, caseSensitive)); if (!increasing) {
if (!increasing){ array.reverse();
array.reverse(); }
} 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(separator);
return array.join(separator);
} }

View File

@@ -1,183 +1,263 @@
// Import necessary modules and functions // Import necessary modules and functions
import { describe, it, expect } from 'vitest'; import { describe, expect, it } from 'vitest';
import { alphabeticSort, lengthSort, numericSort } from './service'; import { alphabeticSort, lengthSort, numericSort } from './service';
import { BlobOptions } from 'buffer';
// 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: number[] = [9, 8, 7, 4, 2, 2, 5]; const array: number[] = [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', () => {
const array: number[] = [2, 4, 4, 9, 6, 6, 7];
const increasing: boolean = false;
const separator = ' - ';
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: any[] = ['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: number[] = [415689521, 3, 126, 12, 1523];
const increasing: boolean = true;
const separator = ', ';
const removeDuplicated: boolean = false;
const result = lengthSort(array, increasing, separator, removeDuplicated);
expect(result).toBe('3, 12, 126, 1523, 415689521');
}); });
it('should sort a list in decreasing order with " - " separator and remove duplicated elements', () => { it('should sort a list of number by length in increasing order and remove duplicated elements ', () => {
const array: number[] = [2, 4, 4, 9, 6, 6, 7]; const array: number[] = [415689521, 3, 3, 126, 12, 12, 1523];
const increasing: boolean = false; const increasing: boolean = true;
const separator = ' - '; const separator = ', ';
const removeDuplicated: boolean = true; const removeDuplicated: boolean = true;
const result = lengthSort(array, increasing, separator, removeDuplicated);
const result = numericSort(array, increasing, separator, removeDuplicated); expect(result).toBe('3, 12, 126, 1523, 415689521');
expect(result).toBe('9 - 7 - 6 - 4 - 2');
}); });
it('should sort a list with numbers and characters and remove duplicated elements', () => { it('should sort a mixed array by length in increasing order ', () => {
const array: any[] = ['d','d', 'n', 'p', 'h', 'h', 6, 9, 7, 5]; const array: any[] = ['ddd', 'd', 'nfg', 'p', 'h', 'h', 6555, 9, 7, 5556];
const increasing: boolean = true; const increasing: boolean = true;
const separator = ' '; const separator = ' ';
const removeDuplicated: boolean = true; 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 = numericSort(array, increasing, separator, removeDuplicated); // Define test cases for the alphabeticSort function
expect(result).toBe('5 6 7 9 d h n p'); describe('alphabeticSort function', () => {
// NON CASE SENSITIVE TEST
it('should sort a list of string in increasing order with comma separator ', () => {
const array: any[] = ['apple', 'pineaple', 'lemon', 'orange'];
const increasing: boolean = true;
const separator = ', ';
const removeDuplicated: boolean = false;
const caseSensitive: boolean = false;
const result = alphabeticSort(
array,
increasing,
separator,
removeDuplicated,
caseSensitive
);
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: any[] = ['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: number[] = [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: number[] = [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: any[] = ['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');
}); });
// Define test cases for the alphabeticSort function it('should sort a list of string and symbols (uppercase and lower) in increasing order with comma separator ', () => {
describe('alphabeticSort function', () => { const array: any[] = [
// NON CASE SENSITIVE TEST 'Apple',
it('should sort a list of string in increasing order with comma separator ', () => { 'pineaple',
const array: any[] = ['apple', 'pineaple', 'lemon', 'orange']; 'lemon',
const increasing: boolean = true; 'Orange',
const separator = ', '; 1,
const removeDuplicated: boolean = false; 9,
const caseSensitive: boolean = false; '@',
'+'
const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive); ];
expect(result).toBe('apple, lemon, orange, pineaple'); const increasing: boolean = true;
}); const separator = ' ';
const removeDuplicated: boolean = true;
it('should sort a list of string in decreasing order with comma separator ', () => { const caseSensitive: boolean = false;
const array: any[] = ['apple', 'pineaple', 'lemon', 'orange'];
const increasing: boolean = false;
const separator = ', ';
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: any[] = ['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: any[] = ['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: any[] = ['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: any[] = ['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: any[] = ['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: any[] = ['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: any[] = ['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 +');
});
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: any[] = [
'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: any[] = ['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: any[] = ['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: any[] = ['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: any[] = [
'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: any[] = [
'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 +');
});
});
}); });