diff --git a/frontend/src/utils/arrayParser.test.ts b/frontend/src/utils/arrayParser.test.ts index 5c93928..6cce14a 100644 --- a/frontend/src/utils/arrayParser.test.ts +++ b/frontend/src/utils/arrayParser.test.ts @@ -2,36 +2,38 @@ import { describe, it, expect } from 'vitest'; import { parseCustomArrayInput } from './arrayParser'; describe('parseCustomArrayInput', () => { - it('should parse a typical comma-separated input', () => { - expect(parseCustomArrayInput("1, 2, 3")).toEqual([1, 2, 3]); + it('should parse standard comma-separated integers', () => { + expect(parseCustomArrayInput('5, 8, 10')).toEqual([5, 8, 10]); }); it('should handle trailing commas', () => { - expect(parseCustomArrayInput("5, 8,")).toEqual([5, 8]); + expect(parseCustomArrayInput('5, 8,')).toEqual([5, 8]); }); it('should handle empty middle commas', () => { - expect(parseCustomArrayInput("5,, 8")).toEqual([5, 8]); + expect(parseCustomArrayInput('5,, 8')).toEqual([5, 8]); }); - it('should handle a single element', () => { - expect(parseCustomArrayInput("5")).toEqual([5]); + it('should parse a single element', () => { + expect(parseCustomArrayInput('5')).toEqual([5]); }); - it('should handle a zero element', () => { - expect(parseCustomArrayInput("0")).toEqual([0]); + it('should parse a zero element', () => { + expect(parseCustomArrayInput('0')).toEqual([0]); }); it('should handle duplicate elements', () => { - expect(parseCustomArrayInput("5, 5, 5")).toEqual([5, 5, 5]); + expect(parseCustomArrayInput('5, 5, 5')).toEqual([5, 5, 5]); }); it('should ignore invalid non-numeric entries', () => { - expect(parseCustomArrayInput("5, abc, 8")).toEqual([5, 8]); + expect(parseCustomArrayInput('5, abc, 8')).toEqual([5, 8]); + expect(parseCustomArrayInput('abc, def')).toEqual([]); + expect(parseCustomArrayInput('1, 2.5, 3')).toEqual([1, 3]); // ignores floats based on regex /^-?\d+$/ }); - it('should parse negative numbers', () => { - expect(parseCustomArrayInput("-5, 0, 10")).toEqual([-5, 0, 10]); + it('should handle negative numbers', () => { + expect(parseCustomArrayInput('-5, 0, 10')).toEqual([-5, 0, 10]); }); it('should return an empty array for an empty string or all non-numeric input', () => { @@ -39,12 +41,12 @@ describe('parseCustomArrayInput', () => { expect(parseCustomArrayInput("abc, def")).toEqual([]); }); - it('should return an empty array for null/undefined/non-string input', () => { - // @ts-expect-error testing invalid input types + it('should return empty array for non-string inputs', () => { + // @ts-expect-error Testing invalid input type expect(parseCustomArrayInput(null)).toEqual([]); - // @ts-expect-error testing invalid input types + // @ts-expect-error Testing invalid input type expect(parseCustomArrayInput(undefined)).toEqual([]); - // @ts-expect-error testing invalid input types + // @ts-expect-error Testing invalid input type expect(parseCustomArrayInput(123)).toEqual([]); }); });