Skip to content

Commit

Permalink
Sync tests for practice exercise flatten-array (#2535)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderploegsma authored Oct 24, 2023
1 parent de4bc17 commit ec8572c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 34 deletions.
28 changes: 25 additions & 3 deletions exercises/practice/flatten-array/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"

Expand Down
1 change: 0 additions & 1 deletion exercises/practice/flatten-array/.meta/version

This file was deleted.

101 changes: 71 additions & 30 deletions exercises/practice/flatten-array/src/test/java/FlattenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

}

0 comments on commit ec8572c

Please sign in to comment.