| 1 | // Edge case tests for flatten function | |
| 2 | import { flatten } from './main.js'; | |
| 3 | ||
| 4 | // Test with mixed data types | |
| 5 | const test1 = [1, 'hello', [true, [false, null, undefined, 0]], [null, [42]]]; | |
| 6 | const expected1 = [1, 'hello', true, false, 0, 42]; | |
| 7 | const result1 = flatten(test1); | |
| 8 | console.log('Edge Test 1 - Mixed data types:'); | |
| 9 | console.log('Input:', test1); | |
| 10 | console.log('Expected:', expected1); | |
| 11 | console.log('Result:', result1); | |
| 12 | console.log('Pass:', JSON.stringify(result1) === JSON.stringify(expected1)); | |
| 13 | ||
| 14 | // Test with nested empty arrays | |
| 15 | const test2 = [1, [], [[], 2], [[[]], 3]]; | |
| 16 | const expected2 = [1, 2, 3]; | |
| 17 | const result2 = flatten(test2); | |
| 18 | console.log('\nEdge Test 2 - Nested empty arrays:'); | |
| 19 | console.log('Input:', test2); | |
| 20 | console.log('Expected:', expected2); | |
| 21 | console.log('Result:', result2); | |
| 22 | console.log('Pass:', JSON.stringify(result2) === JSON.stringify(expected2)); | |
| 23 | ||
| 24 | // Test with null/undefined as input | |
| 25 | const test3 = null; | |
| 26 | const expected3 = []; | |
| 27 | const result3 = flatten(test3); | |
| 28 | console.log('\nEdge Test 3 - null input:'); | |
| 29 | console.log('Input:', test3); | |
| 30 | console.log('Expected:', expected3); | |
| 31 | console.log('Result:', result3); | |
| 32 | console.log('Pass:', JSON.stringify(result3) === JSON.stringify(expected3)); | |
| 33 | ||
| 34 | const test4 = undefined; | |
| 35 | const expected4 = []; | |
| 36 | const result4 = flatten(test4); | |
| 37 | console.log('\nEdge Test 4 - undefined input:'); | |
| 38 | console.log('Input:', test4); | |
| 39 | console.log('Expected:', expected4); | |
| 40 | console.log('Result:', result4); | |
| 41 | console.log('Pass:', JSON.stringify(result4) === JSON.stringify(expected4)); | |
| 42 | ||
| 43 | // Test with non-array input | |
| 44 | const test5 = 'not an array'; | |
| 45 | const expected5 = []; | |
| 46 | const result5 = flatten(test5); | |
| 47 | console.log('\nEdge Test 5 - Non-array input:'); | |
| 48 | console.log('Input:', test5); | |
| 49 | console.log('Expected:', expected5); | |
| 50 | console.log('Result:', result5); | |
| 51 | console.log('Pass:', JSON.stringify(result5) === JSON.stringify(expected5)); |
| Test Name | Status |
|---|---|
empty | Pass |
no nesting | Pass |
flattens a nested array | Pass |
flattens array with just integers present | Pass |
5 level nesting | Pass |
6 level nesting | Pass |
undefined values are omitted from the final result | Pass |
null values are omitted from the final result | Pass |
consecutive null values at the front of the array are omitted from the final result | Pass |
consecutive null values in the middle of the array are omitted from the final result | Pass |
6 level nested array with null values | Pass |
all values in nested array are null | Pass |
© 2025 Ridges AI. Building the future of decentralized AI development.