Skip to content

Commit ec8572c

Browse files
Sync tests for practice exercise flatten-array (#2535)
1 parent de4bc17 commit ec8572c

File tree

3 files changed

+96
-34
lines changed

3 files changed

+96
-34
lines changed

exercises/practice/flatten-array/.meta/tests.toml

Lines changed: 25 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,6 +27,15 @@ 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+
36+
[382c5242-587e-4577-b8ce-a5fb51e385a1]
37+
description = "consecutive null values in the middle of the list are omitted from the final result"
38+
1739
[ef1d4790-1b1e-4939-a179-51ace0829dbd]
1840
description = "6 level nest list with null values"
1941

exercises/practice/flatten-array/.meta/version

Lines changed: 0 additions & 1 deletion
This file was deleted.

exercises/practice/flatten-array/src/test/java/FlattenerTest.java

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Test;
44

55
import static java.util.Arrays.asList;
6+
import static java.util.Collections.emptyList;
67
import static java.util.Collections.singletonList;
78
import static org.assertj.core.api.Assertions.assertThat;
89

@@ -15,65 +16,105 @@ public void setUp() {
1516
flattener = new Flattener();
1617
}
1718

19+
@Test
20+
public void testEmpty() {
21+
assertThat(flattener.flatten(emptyList()))
22+
.isEmpty();
23+
}
24+
25+
@Ignore("Remove to run test")
1826
@Test
1927
public void testFlatListIsPreserved() {
2028
assertThat(flattener.flatten(asList(0, '1', "two")))
21-
.containsExactly(0, '1', "two");
29+
.containsExactly(0, '1', "two");
30+
}
31+
32+
@Ignore("Remove to run test")
33+
@Test
34+
public void testNestedList() {
35+
assertThat(flattener.flatten(singletonList(emptyList())))
36+
.isEmpty();
2237
}
2338

2439
@Ignore("Remove to run test")
2540
@Test
2641
public void testASingleLevelOfNestingWithNoNulls() {
2742
assertThat(flattener.flatten(asList(1, asList('2', 3, 4, 5, "six", "7"), 8)))
28-
.containsExactly(1, '2', 3, 4, 5, "six", "7", 8);
43+
.containsExactly(1, '2', 3, 4, 5, "six", "7", 8);
2944
}
3045

3146
@Ignore("Remove to run test")
3247
@Test
3348
public void testFiveLevelsOfNestingWithNoNulls() {
34-
assertThat(flattener.flatten(asList(0,
35-
'2',
36-
asList(asList(2, "three"),
37-
'8',
38-
100,
39-
"four",
40-
singletonList(singletonList(singletonList(50)))), "-2")))
41-
.containsExactly(0, '2', 2, "three", '8', 100, "four", 50, "-2");
49+
assertThat(flattener.flatten(
50+
asList(0,
51+
'2',
52+
asList(asList(2, "three"),
53+
'8',
54+
100,
55+
"four",
56+
singletonList(singletonList(singletonList(50)))), "-2")))
57+
.containsExactly(0, '2', 2, "three", '8', 100, "four", 50, "-2");
4258
}
4359

4460
@Ignore("Remove to run test")
4561
@Test
4662
public void testSixLevelsOfNestingWithNoNulls() {
47-
assertThat(flattener.flatten(asList("one",
48-
asList('2',
49-
singletonList(singletonList(3)),
50-
asList('4',
51-
singletonList(singletonList(5))), "six", 7), "8")))
52-
.containsExactly("one", '2', 3, '4', 5, "six", 7, "8");
63+
assertThat(flattener.flatten(
64+
asList("one",
65+
asList('2',
66+
singletonList(singletonList(3)),
67+
asList('4',
68+
singletonList(singletonList(5))), "six", 7), "8")))
69+
.containsExactly("one", '2', 3, '4', 5, "six", 7, "8");
70+
}
71+
72+
@Ignore("Remove to run test")
73+
@Test
74+
public void testNullValuesAreOmitted() {
75+
assertThat(flattener.flatten(asList("1", "two", null)))
76+
.containsExactly("1", "two");
77+
}
78+
79+
@Ignore("Remove to run test")
80+
@Test
81+
public void testConsecutiveNullValuesAtFrontOfListAreOmitted() {
82+
assertThat(flattener.flatten(asList(null, null, 3)))
83+
.containsExactly(3);
84+
}
85+
86+
@Ignore("Remove to run test")
87+
@Test
88+
public void testConsecutiveNullValuesInMiddleOfListAreOmitted() {
89+
assertThat(flattener.flatten(asList(1, null, null, "4")))
90+
.containsExactly(1, "4");
5391
}
5492

5593
@Ignore("Remove to run test")
5694
@Test
5795
public void testSixLevelsOfNestingWithNulls() {
58-
assertThat(flattener.flatten(asList("0",
59-
2,
60-
asList(asList("two", '3'),
61-
"8",
62-
singletonList(singletonList("one hundred")),
63-
null,
64-
singletonList(singletonList(null))),
65-
"negative two")))
66-
.containsExactly("0", 2, "two", '3', "8", "one hundred", "negative two");
96+
assertThat(flattener.flatten(
97+
asList("0",
98+
2,
99+
asList(asList("two", '3'),
100+
"8",
101+
singletonList(singletonList("one hundred")),
102+
null,
103+
singletonList(singletonList(null))),
104+
"negative two")))
105+
.containsExactly("0", 2, "two", '3', "8", "one hundred", "negative two");
67106
}
68107

69108
@Ignore("Remove to run test")
70109
@Test
71110
public void testNestedListsFullOfNullsOnly() {
72-
assertThat(flattener.flatten(asList(null,
73-
singletonList(singletonList(singletonList(null))),
74-
null,
75-
null,
76-
asList(asList(null, null), null), null))).isEmpty();
111+
assertThat(flattener.flatten(
112+
asList(null,
113+
singletonList(singletonList(singletonList(null))),
114+
null,
115+
null,
116+
asList(asList(null, null), null), null)))
117+
.isEmpty();
77118
}
78119

79120
}

0 commit comments

Comments
 (0)