Skip to content

Commit f3489be

Browse files
authored
Sync flatten-array tests (#1628)
1 parent 37fd81d commit f3489be

2 files changed

Lines changed: 82 additions & 13 deletions

File tree

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[8c71dabd-da60-422d-a290-4a571471fb14]
13+
description = "empty"
414

515
[d268b919-963c-442d-9f07-82b93f1b518c]
616
description = "no nesting"
717

18+
[3f15bede-c856-479e-bb71-1684b20c6a30]
19+
description = "flattens a nested array"
20+
821
[c84440cc-bb3a-48a6-862c-94cf23f2815d]
922
description = "flattens array with just integers present"
1023

@@ -14,8 +27,37 @@ description = "5 level nesting"
1427
[d572bdba-c127-43ed-bdcd-6222ac83d9f7]
1528
description = "6 level nesting"
1629

30+
[0705a8e5-dc86-4cec-8909-150c5e54fa9c]
31+
description = "null values are omitted from the final result"
32+
33+
[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
34+
description = "consecutive null values at the front of the list are omitted from the final result"
35+
include = false
36+
37+
[bc72da10-5f55-4ada-baf3-50e4da02ec8e]
38+
description = "consecutive null values at the front of the array are omitted from the final result"
39+
reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc"
40+
41+
[382c5242-587e-4577-b8ce-a5fb51e385a1]
42+
description = "consecutive null values in the middle of the list are omitted from the final result"
43+
include = false
44+
45+
[6991836d-0d9b-4703-80a0-3f1f23eb5981]
46+
description = "consecutive null values in the middle of the array are omitted from the final result"
47+
reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1"
48+
1749
[ef1d4790-1b1e-4939-a179-51ace0829dbd]
1850
description = "6 level nest list with null values"
51+
include = false
52+
53+
[dc90a09c-5376-449c-a7b3-c2d20d540069]
54+
description = "6 level nested array with null values"
55+
reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd"
1956

2057
[85721643-705a-4150-93ab-7ae398e2942d]
2158
description = "all values in nested list are null"
59+
include = false
60+
61+
[51f5d9af-8f7f-4fb5-a156-69e8282cb275]
62+
description = "all values in nested array are null"
63+
reimplements = "85721643-705a-4150-93ab-7ae398e2942d"

exercises/practice/flatten-array/flatten-array.test.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,61 @@ import { describe, it, expect, xit } from '@jest/globals'
22
import { flatten } from './flatten-array.ts'
33

44
describe('Flatten Array', () => {
5-
it('no nesting', () => {
5+
it('empty', () => {
6+
const arr = []
7+
const expected = []
8+
expect(flatten(arr)).toEqual(expected)
9+
})
10+
11+
xit('no nesting', () => {
12+
const arr = [0, 1, 2]
613
const expected = [0, 1, 2]
7-
expect(flatten([0, 1, 2])).toEqual(expected)
14+
expect(flatten(arr)).toEqual(expected)
15+
})
16+
17+
xit('flattens a nested array', () => {
18+
const arr = [[[]]]
19+
const expected = []
20+
expect(flatten(arr)).toEqual(expected)
821
})
922

1023
xit('flattens array with just integers present', () => {
24+
const arr = [1, [2, 3, 4, 5, 6, 7], 8]
1125
const expected = [1, 2, 3, 4, 5, 6, 7, 8]
12-
expect(flatten([1, [2, 3, 4, 5, 6, 7], 8])).toEqual(expected)
26+
expect(flatten(arr)).toEqual(expected)
1327
})
1428

1529
xit('5 level nesting', () => {
30+
const arr = [0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2]
1631
const expected = [0, 2, 2, 3, 8, 100, 4, 50, -2]
17-
expect(flatten([0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2])).toEqual(expected)
32+
expect(flatten(arr)).toEqual(expected)
1833
})
1934

2035
xit('6 level nesting', () => {
36+
const arr = [1, [2, [[3]], [4, [[5]]], 6, 7], 8]
2137
const expected = [1, 2, 3, 4, 5, 6, 7, 8]
22-
expect(flatten([1, [2, [[3]], [4, [[5]]], 6, 7], 8])).toEqual(expected)
38+
expect(flatten(arr)).toEqual(expected)
39+
})
40+
41+
xit('consecutive null values at the front of the array are omitted from the final result', () => {
42+
const arr = [undefined, undefined, 3]
43+
const expected = [3]
44+
expect(flatten(arr)).toEqual(expected)
45+
})
46+
47+
xit('consecutive null values in the middle of the array are omitted from the final result', () => {
48+
const arr = [1, undefined, undefined, 4]
49+
const expected = [1, 4]
50+
expect(flatten(arr)).toEqual(expected)
2351
})
2452

25-
xit('6 level nest list with null values', () => {
53+
xit('6 level nest array with null values', () => {
54+
const arr = [0, 2, [[2, 3], 8, [[100]], undefined, [[undefined]]], -2]
2655
const expected = [0, 2, 2, 3, 8, 100, -2]
27-
expect(
28-
flatten([0, 2, [[2, 3], 8, [[100]], undefined, [[undefined]]], -2])
29-
).toEqual(expected)
56+
expect(flatten(arr)).toEqual(expected)
3057
})
3158

32-
xit('all values in nested list are null', () => {
59+
xit('all values in nested array are null', () => {
3360
const expected: number[] = []
3461
expect(
3562
flatten([

0 commit comments

Comments
 (0)