From b47b85452958289d594f964c150ebcd0240babe7 Mon Sep 17 00:00:00 2001 From: Chesterkxng Date: Thu, 27 Jun 2024 13:27:55 +0000 Subject: [PATCH 1/2] create tool, implementing alphabeticSort and NumericSort and writing testCases --- src/pages/list/index.ts | 2 + src/pages/list/sort/index.tsx | 11 ++ src/pages/list/sort/meta.ts | 13 ++ src/pages/list/sort/service.ts | 81 ++++++++++ src/pages/list/sort/sort.service.test.ts | 182 +++++++++++++++++++++++ 5 files changed, 289 insertions(+) create mode 100644 src/pages/list/index.ts create mode 100644 src/pages/list/sort/index.tsx create mode 100644 src/pages/list/sort/meta.ts create mode 100644 src/pages/list/sort/service.ts create mode 100644 src/pages/list/sort/sort.service.test.ts diff --git a/src/pages/list/index.ts b/src/pages/list/index.ts new file mode 100644 index 0000000..08dc437 --- /dev/null +++ b/src/pages/list/index.ts @@ -0,0 +1,2 @@ +import { tool as listSort } from './sort/meta'; +export const listTools = []; diff --git a/src/pages/list/sort/index.tsx b/src/pages/list/sort/index.tsx new file mode 100644 index 0000000..0ffb78b --- /dev/null +++ b/src/pages/list/sort/index.tsx @@ -0,0 +1,11 @@ +import { Box } from '@mui/material'; +import React from 'react'; +import * as Yup from 'yup'; + +const initialValues = {}; +const validationSchema = Yup.object({ + // splitSeparator: Yup.string().required('The separator is required') +}); +export default function Sort() { + return Lorem ipsum; +} \ No newline at end of file diff --git a/src/pages/list/sort/meta.ts b/src/pages/list/sort/meta.ts new file mode 100644 index 0000000..b5afb37 --- /dev/null +++ b/src/pages/list/sort/meta.ts @@ -0,0 +1,13 @@ +import { defineTool } from '@tools/defineTool'; +import { lazy } from 'react'; +// import image from '@assets/text.png'; + +export const tool = defineTool('list', { + name: 'Sort', + path: 'sort', + // image, + description: '', + shortDescription: '', + keywords: ['sort'], + component: lazy(() => import('./index')) +}); \ No newline at end of file diff --git a/src/pages/list/sort/service.ts b/src/pages/list/sort/service.ts new file mode 100644 index 0000000..633df5c --- /dev/null +++ b/src/pages/list/sort/service.ts @@ -0,0 +1,81 @@ +import { string } from "yup"; + +// utils function that choose the way of numeric sorting mixed types of array +function customNumericSort(a: number | string, b: number | string, order: string): number { + if (typeof a === 'number' && typeof b === 'number') { + let result: number = order === "increasing" ? (a - b) : (b - a); + return result; + } else if (typeof a === 'string' && typeof b === 'string') { + 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( + array: any[], // array we build after parsing the input + order: string, // select value has to be increasing for increasing order and decreasing for decreasing order (set a default value) + separator: string, + remove_duplicated: number // the value if the checkbox has been selected 1 else 0 +) { + array.sort((a, b) => customNumericSort(a, b, order)); + if (remove_duplicated === 1) { + array = array.filter((item, index) => array.indexOf(item) === index); + } + return array.join(separator); +} + +// utils function that choose the way of numeric sorting mixed types of array +function customLengthSort(a: number | string, b: number | string, order: string): number { + let result: number = order === "increasing" ? (a.toString().length - b.toString().length) : (b.toString().length - a.toString().length); + return result; +} + +export function lengthSort( + array: any[], // array we build after parsing the input + order: string, // select value has to be increasing for increasing order and decreasing for decreasing order + separator: string, + remove_duplicated: number // the value if the checkbox has been selected 1 else 0 +) { + array.sort((a, b) => customLengthSort(a, b, order)); + if (remove_duplicated === 1) { + array = array.filter((item, index) => array.indexOf(item) === index); + } + return array.join(separator); +} + +// Utils function that chooses the way of alphabetic sorting mixed types of array +function customAlphabeticSort(a: number | string, b: number | string, case_sensitive: number): number { + const stringA : string = a.toString(); + const stringB : string = b.toString(); + + if (case_sensitive === 0) { + // Case-insensitive comparison + return stringA.toLowerCase().localeCompare(stringB.toLowerCase()); + } else { + // Case-sensitive comparison + return stringA.charCodeAt(0) - stringB.charCodeAt(0); + } +} + +export function alphabeticSort( + array: any[], // array we build after parsing the input + order: string, // select value has to be "increasing" for increasing order and "decreasing" for decreasing order + separator: string, + remove_duplicated: number, // the value if the checkbox has been selected 1 else 0 + case_sensitive: number // the value if the checkbox has been selected 1 else 0 +) +{ + array.sort((a, b) => customAlphabeticSort(a, b, case_sensitive)); + if (order === "decreasing"){ + array.reverse(); + } + if (remove_duplicated === 1) { + array = array.filter((item, index) => array.indexOf(item) === index); + } + return array.join(separator); + + +} \ No newline at end of file diff --git a/src/pages/list/sort/sort.service.test.ts b/src/pages/list/sort/sort.service.test.ts new file mode 100644 index 0000000..732e9a6 --- /dev/null +++ b/src/pages/list/sort/sort.service.test.ts @@ -0,0 +1,182 @@ +// Import necessary modules and functions +import { describe, it, expect } from 'vitest'; +import { alphabeticSort, lengthSort, numericSort } from './service'; + +// Define test cases for the numericSort function +describe('numericSort function', () => { + 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 order: string = 'increasing'; + const separator = ', '; + const remove_duplicated: number = 0; + + const result = numericSort(array, order, separator, remove_duplicated); + 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 order: string = 'decreasing'; + const separator = ' - '; + const remove_duplicated: number = 1; + + + const result = numericSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const separator = ' '; + const remove_duplicated: number = 1; + + + const result = numericSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const separator = ', '; + const remove_duplicated: number = 0; + + const result = lengthSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const separator = ', '; + const remove_duplicated: number = 1; + + const result = lengthSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const separator = ' '; + const remove_duplicated: number = 1; + + const result = lengthSort(array, order, separator, remove_duplicated); + expect(result).toBe('d p h 9 7 ddd nfg 6555 5556'); + }); + + + }); + + // Define test cases for the alphabeticSort function + 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 order: string = 'increasing'; + const separator = ', '; + const remove_duplicated: number = 0; + const case_sensitive: number = 0; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + expect(result).toBe('apple, lemon, orange, pineaple'); + }); + + it('should sort a list of string in decreasing order with comma separator ', () => { + const array: any[] = ['apple', 'pineaple', 'lemon', 'orange']; + const order: string = 'decreasing'; + const separator = ', '; + const remove_duplicated: number = 0; + const case_sensitive: number = 0; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'increasing'; + const separator = ' '; + const remove_duplicated: number = 1; + const case_sensitive: number = 0; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const separator = ' '; + const remove_duplicated: number = 1; + const case_sensitive: number = 0; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const separator = ' '; + const remove_duplicated: number = 0; + const case_sensitive: number = 1; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'increasing'; + const separator = ' '; + const remove_duplicated: number = 1; + const case_sensitive: number = 1; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const separator = ' '; + const remove_duplicated: number = 1; + const case_sensitive: number = 1; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'increasing'; + const separator = ' '; + const remove_duplicated: number = 1; + const case_sensitive: number = 1; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const separator = ' '; + const remove_duplicated: number = 1; + const case_sensitive: number = 1; + + const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + expect(result).toBe('pineaple lemon Orange Apple @ 9 1 +'); + }); + + + + + }); +}); \ No newline at end of file From 5b70d8ef5887e38d0361c3e6226c9b64e077df1c Mon Sep 17 00:00:00 2001 From: Chesterkxng Date: Thu, 27 Jun 2024 14:30:45 +0000 Subject: [PATCH 2/2] some fixes --- src/pages/list/sort/service.ts | 46 +++++----- src/pages/list/sort/sort.service.test.ts | 109 ++++++++++++----------- 2 files changed, 76 insertions(+), 79 deletions(-) diff --git a/src/pages/list/sort/service.ts b/src/pages/list/sort/service.ts index 633df5c..4286ccb 100644 --- a/src/pages/list/sort/service.ts +++ b/src/pages/list/sort/service.ts @@ -1,9 +1,7 @@ -import { string } from "yup"; - // utils function that choose the way of numeric sorting mixed types of array -function customNumericSort(a: number | string, b: number | string, order: string): number { +function customNumericSort(a: number | string, b: number | string, increasing: boolean): number { if (typeof a === 'number' && typeof b === 'number') { - let result: number = order === "increasing" ? (a - b) : (b - a); + let result: number = increasing ? (a - b) : (b - a); return result; } else if (typeof a === 'string' && typeof b === 'string') { return a.localeCompare(b); // Lexicographical comparison for strings @@ -16,42 +14,42 @@ function customNumericSort(a: number | string, b: number | string, order: string export function numericSort( array: any[], // array we build after parsing the input - order: string, // select value has to be increasing for increasing order and decreasing for decreasing order (set a default value) + increasing: boolean, separator: string, - remove_duplicated: number // 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, order)); - if (remove_duplicated === 1) { + array.sort((a, b) => customNumericSort(a, b, increasing)); + if (removeDuplicated) { array = array.filter((item, index) => array.indexOf(item) === index); } return array.join(separator); } // utils function that choose the way of numeric sorting mixed types of array -function customLengthSort(a: number | string, b: number | string, order: string): number { - let result: number = order === "increasing" ? (a.toString().length - b.toString().length) : (b.toString().length - a.toString().length); +function customLengthSort(a: number | string, 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( array: any[], // array we build after parsing the input - order: string, // 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, - remove_duplicated: number // 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, order)); - if (remove_duplicated === 1) { + array.sort((a, b) => customLengthSort(a, b, increasing)); + if (removeDuplicated) { array = array.filter((item, index) => array.indexOf(item) === index); } return array.join(separator); } // Utils function that chooses the way of alphabetic sorting mixed types of array -function customAlphabeticSort(a: number | string, b: number | string, case_sensitive: number): number { +function customAlphabeticSort(a: number | string, b: number | string, caseSensitive: boolean): number { const stringA : string = a.toString(); const stringB : string = b.toString(); - if (case_sensitive === 0) { + if (!caseSensitive) { // Case-insensitive comparison return stringA.toLowerCase().localeCompare(stringB.toLowerCase()); } else { @@ -62,20 +60,18 @@ function customAlphabeticSort(a: number | string, b: number | string, case_sensi export function alphabeticSort( array: any[], // array we build after parsing the input - order: string, // 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, - remove_duplicated: number, // the value if the checkbox has been selected 1 else 0 - case_sensitive: number // 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 ) { - array.sort((a, b) => customAlphabeticSort(a, b, case_sensitive)); - if (order === "decreasing"){ + array.sort((a, b) => customAlphabeticSort(a, b, caseSensitive)); + if (!increasing){ array.reverse(); } - if (remove_duplicated === 1) { + if (removeDuplicated) { array = array.filter((item, index) => array.indexOf(item) === index); } - return array.join(separator); - - + return array.join(separator); } \ No newline at end of file diff --git a/src/pages/list/sort/sort.service.test.ts b/src/pages/list/sort/sort.service.test.ts index 732e9a6..d702985 100644 --- a/src/pages/list/sort/sort.service.test.ts +++ b/src/pages/list/sort/sort.service.test.ts @@ -1,38 +1,39 @@ // Import necessary modules and functions import { describe, it, expect } from 'vitest'; import { alphabeticSort, lengthSort, numericSort } from './service'; +import { BlobOptions } from 'buffer'; // Define test cases for the numericSort function describe('numericSort function', () => { 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ', '; - const remove_duplicated: number = 0; + const removeDuplicated: boolean = false; - const result = numericSort(array, order, separator, remove_duplicated); + const result = numericSort(array, increasing, separator, removeDuplicated); 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 order: string = 'decreasing'; + const increasing: boolean = false; const separator = ' - '; - const remove_duplicated: number = 1; + const removeDuplicated: boolean = true; - const result = numericSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ' '; - const remove_duplicated: number = 1; + const removeDuplicated: boolean = true; - const result = numericSort(array, order, separator, remove_duplicated); + const result = numericSort(array, increasing, separator, removeDuplicated); expect(result).toBe('5 6 7 9 d h n p'); }); @@ -40,31 +41,31 @@ describe('numericSort 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ', '; - const remove_duplicated: number = 0; + const removeDuplicated: boolean = false; - const result = lengthSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ', '; - const remove_duplicated: number = 1; + const removeDuplicated: boolean = true; - const result = lengthSort(array, order, separator, remove_duplicated); + 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ' '; - const remove_duplicated: number = 1; + const removeDuplicated: boolean = true; - const result = lengthSort(array, order, separator, remove_duplicated); + const result = lengthSort(array, increasing, separator, removeDuplicated); expect(result).toBe('d p h 9 7 ddd nfg 6555 5556'); }); @@ -76,45 +77,45 @@ describe('numericSort 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ', '; - const remove_duplicated: number = 0; - const case_sensitive: number = 0; + const removeDuplicated: boolean = false; + const caseSensitive: boolean = false; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive); expect(result).toBe('apple, lemon, orange, pineaple'); }); it('should sort a list of string in decreasing order with comma separator ', () => { const array: any[] = ['apple', 'pineaple', 'lemon', 'orange']; - const order: string = 'decreasing'; + const increasing: boolean = false; const separator = ', '; - const remove_duplicated: number = 0; - const case_sensitive: number = 0; + const removeDuplicated: boolean = false; + const caseSensitive: boolean = false; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ' '; - const remove_duplicated: number = 1; - const case_sensitive: number = 0; + const removeDuplicated: boolean = true; + const caseSensitive: boolean = false; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const increasing: boolean = false; const separator = ' '; - const remove_duplicated: number = 1; - const case_sensitive: number = 0; + const removeDuplicated: boolean = true; + const caseSensitive: boolean = false; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive); expect(result).toBe('pineaple Orange lemon Apple 9 1 + @'); }); @@ -122,56 +123,56 @@ describe('numericSort function', () => { // 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 order: string = 'decreasing'; + const increasing: boolean = false; const separator = ' '; - const remove_duplicated: number = 0; - const case_sensitive: number = 1; + const removeDuplicated: boolean = false; + const caseSensitive: boolean = true; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ' '; - const remove_duplicated: number = 1; - const case_sensitive: number = 1; + const removeDuplicated: boolean = true; + const caseSensitive: boolean = true; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const increasing: boolean = false; const separator = ' '; - const remove_duplicated: number = 1; - const case_sensitive: number = 1; + const removeDuplicated: boolean = true; + const caseSensitive: boolean = true; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'increasing'; + const increasing: boolean = true; const separator = ' '; - const remove_duplicated: number = 1; - const case_sensitive: number = 1; + const removeDuplicated: boolean = true; + const caseSensitive: boolean = true; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + 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 order: string = 'decreasing'; + const increasing: boolean = false; const separator = ' '; - const remove_duplicated: number = 1; - const case_sensitive: number = 1; + const removeDuplicated: boolean = true; + const caseSensitive: boolean = true; - const result = alphabeticSort(array, order, separator, remove_duplicated, case_sensitive); + const result = alphabeticSort(array, increasing, separator, removeDuplicated, caseSensitive); expect(result).toBe('pineaple lemon Orange Apple @ 9 1 +'); });