diff --git a/exercises/practice/flatten-array/.meta/tests.toml b/exercises/practice/flatten-array/.meta/tests.toml index 99eea4950..6300219d7 100644 --- a/exercises/practice/flatten-array/.meta/tests.toml +++ b/exercises/practice/flatten-array/.meta/tests.toml @@ -1,10 +1,23 @@ -# This is an auto-generated file. Regular comments will be removed when this -# file is regenerated. Regenerating will not touch any manually added keys, -# so comments can be added in a "comment" key. +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[8c71dabd-da60-422d-a290-4a571471fb14] +description = "empty" [d268b919-963c-442d-9f07-82b93f1b518c] description = "no nesting" +[3f15bede-c856-479e-bb71-1684b20c6a30] +description = "flattens a nested array" + [c84440cc-bb3a-48a6-862c-94cf23f2815d] description = "flattens array with just integers present" @@ -14,6 +27,15 @@ description = "5 level nesting" [d572bdba-c127-43ed-bdcd-6222ac83d9f7] description = "6 level nesting" +[0705a8e5-dc86-4cec-8909-150c5e54fa9c] +description = "null values are omitted from the final result" + +[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc] +description = "consecutive null values at the front of the list are omitted from the final result" + +[382c5242-587e-4577-b8ce-a5fb51e385a1] +description = "consecutive null values in the middle of the list are omitted from the final result" + [ef1d4790-1b1e-4939-a179-51ace0829dbd] description = "6 level nest list with null values" diff --git a/exercises/practice/flatten-array/.meta/version b/exercises/practice/flatten-array/.meta/version deleted file mode 100644 index 26aaba0e8..000000000 --- a/exercises/practice/flatten-array/.meta/version +++ /dev/null @@ -1 +0,0 @@ -1.2.0 diff --git a/exercises/practice/flatten-array/src/test/java/FlattenerTest.java b/exercises/practice/flatten-array/src/test/java/FlattenerTest.java index 2516c2c02..c7a77b816 100644 --- a/exercises/practice/flatten-array/src/test/java/FlattenerTest.java +++ b/exercises/practice/flatten-array/src/test/java/FlattenerTest.java @@ -3,6 +3,7 @@ import org.junit.Test; import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; @@ -15,65 +16,105 @@ public void setUp() { flattener = new Flattener(); } + @Test + public void testEmpty() { + assertThat(flattener.flatten(emptyList())) + .isEmpty(); + } + + @Ignore("Remove to run test") @Test public void testFlatListIsPreserved() { assertThat(flattener.flatten(asList(0, '1', "two"))) - .containsExactly(0, '1', "two"); + .containsExactly(0, '1', "two"); + } + + @Ignore("Remove to run test") + @Test + public void testNestedList() { + assertThat(flattener.flatten(singletonList(emptyList()))) + .isEmpty(); } @Ignore("Remove to run test") @Test public void testASingleLevelOfNestingWithNoNulls() { assertThat(flattener.flatten(asList(1, asList('2', 3, 4, 5, "six", "7"), 8))) - .containsExactly(1, '2', 3, 4, 5, "six", "7", 8); + .containsExactly(1, '2', 3, 4, 5, "six", "7", 8); } @Ignore("Remove to run test") @Test public void testFiveLevelsOfNestingWithNoNulls() { - assertThat(flattener.flatten(asList(0, - '2', - asList(asList(2, "three"), - '8', - 100, - "four", - singletonList(singletonList(singletonList(50)))), "-2"))) - .containsExactly(0, '2', 2, "three", '8', 100, "four", 50, "-2"); + assertThat(flattener.flatten( + asList(0, + '2', + asList(asList(2, "three"), + '8', + 100, + "four", + singletonList(singletonList(singletonList(50)))), "-2"))) + .containsExactly(0, '2', 2, "three", '8', 100, "four", 50, "-2"); } @Ignore("Remove to run test") @Test public void testSixLevelsOfNestingWithNoNulls() { - assertThat(flattener.flatten(asList("one", - asList('2', - singletonList(singletonList(3)), - asList('4', - singletonList(singletonList(5))), "six", 7), "8"))) - .containsExactly("one", '2', 3, '4', 5, "six", 7, "8"); + assertThat(flattener.flatten( + asList("one", + asList('2', + singletonList(singletonList(3)), + asList('4', + singletonList(singletonList(5))), "six", 7), "8"))) + .containsExactly("one", '2', 3, '4', 5, "six", 7, "8"); + } + + @Ignore("Remove to run test") + @Test + public void testNullValuesAreOmitted() { + assertThat(flattener.flatten(asList("1", "two", null))) + .containsExactly("1", "two"); + } + + @Ignore("Remove to run test") + @Test + public void testConsecutiveNullValuesAtFrontOfListAreOmitted() { + assertThat(flattener.flatten(asList(null, null, 3))) + .containsExactly(3); + } + + @Ignore("Remove to run test") + @Test + public void testConsecutiveNullValuesInMiddleOfListAreOmitted() { + assertThat(flattener.flatten(asList(1, null, null, "4"))) + .containsExactly(1, "4"); } @Ignore("Remove to run test") @Test public void testSixLevelsOfNestingWithNulls() { - assertThat(flattener.flatten(asList("0", - 2, - asList(asList("two", '3'), - "8", - singletonList(singletonList("one hundred")), - null, - singletonList(singletonList(null))), - "negative two"))) - .containsExactly("0", 2, "two", '3', "8", "one hundred", "negative two"); + assertThat(flattener.flatten( + asList("0", + 2, + asList(asList("two", '3'), + "8", + singletonList(singletonList("one hundred")), + null, + singletonList(singletonList(null))), + "negative two"))) + .containsExactly("0", 2, "two", '3', "8", "one hundred", "negative two"); } @Ignore("Remove to run test") @Test public void testNestedListsFullOfNullsOnly() { - assertThat(flattener.flatten(asList(null, - singletonList(singletonList(singletonList(null))), - null, - null, - asList(asList(null, null), null), null))).isEmpty(); + assertThat(flattener.flatten( + asList(null, + singletonList(singletonList(singletonList(null))), + null, + null, + asList(asList(null, null), null), null))) + .isEmpty(); } }