diff --git a/exercises/custom-set/.meta/version b/exercises/custom-set/.meta/version new file mode 100644 index 000000000..7dea76edb --- /dev/null +++ b/exercises/custom-set/.meta/version @@ -0,0 +1 @@ +1.0.1 diff --git a/exercises/custom-set/src/test/java/CustomSetTest.java b/exercises/custom-set/src/test/java/CustomSetTest.java index a28287d97..3dbb7fe01 100644 --- a/exercises/custom-set/src/test/java/CustomSetTest.java +++ b/exercises/custom-set/src/test/java/CustomSetTest.java @@ -1,264 +1,181 @@ +import org.junit.Ignore; +import org.junit.Test; import java.util.Arrays; import java.util.Collections; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.Ignore; + +import static org.junit.Assert.*; public class CustomSetTest { @Test public void setsWithNoElementsAreEmpty() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .isEmpty(); - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + assertTrue(customSet.isEmpty()); } @Ignore("Remove to run test") @Test public void setsWithElementsAreNotEmpty() { - final boolean actual - = new CustomSet<>(Collections.singletonList(1)) - .isEmpty(); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Collections.singletonList('1')); + assertFalse(customSet.isEmpty()); } @Ignore("Remove to run test") @Test public void nothingIsContainedInAnEmptySet() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .contains(1); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + assertFalse(customSet.contains("1")); } @Ignore("Remove to run test") @Test public void whenTheElementIsInTheSet() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2, 3)) - .contains(1); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2, 3)); + assertTrue(customSet.contains(1)); } @Ignore("Remove to run test") @Test public void whenTheElementIsNotInTheSet() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2, 3)) - .contains(4); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList('1', '2', '3')); + assertFalse(customSet.contains('4')); } @Ignore("Remove to run test") @Test public void emptySetIsASubsetOfAnotherEmptySet() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .isSubset( - new CustomSet<>(Collections.emptyList()) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + assertTrue(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void emptySetIsASubsetOfNonEmptySet() { - final boolean actual - = new CustomSet<>(Collections.singletonList(1)) - .isSubset( - new CustomSet<>(Collections.emptyList()) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.singletonList(1)); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + assertTrue(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void nonEmptySetIsNotASubsetOfEmptySet() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .isSubset( - new CustomSet<>(Collections.singletonList(1)) - ); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Collections.singletonList('1')); + assertFalse(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setIsASubsetOfSetWithExactSameElements() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2, 3)) - .isSubset( - new CustomSet<>(Arrays.asList(1, 2, 3)) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList("1", "2", "3")); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3")); + assertTrue(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setIsASubsetOfLargerSetWithSameElements() { - final boolean actual - = new CustomSet<>(Arrays.asList(4, 1, 2, 3)) - .isSubset( - new CustomSet<>(Arrays.asList(1, 2, 3)) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList(4, 1, 2, 3)); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList(1, 2, 3)); + assertTrue(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setIsNotASubsetOfSetThatDoesNotContainItsElements() { - final boolean actual - = new CustomSet<>(Arrays.asList(4, 1, 3)) - .isSubset( - new CustomSet<>(Arrays.asList(1, 2, 3)) - ); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList('4', '1', '3')); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList('1', '2', '3')); + assertFalse(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void theEmptySetIsDisjointWithItself() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .isDisjoint( - new CustomSet<>(Collections.emptyList()) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + assertTrue(customSet.isDisjoint(secondCustomSet)); } @Ignore("Remove to run test") @Test public void emptySetIsDisjointWithNonEmptySet() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .isDisjoint( - new CustomSet<>(Collections.singletonList(1)) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Collections.singletonList(1)); + assertTrue(customSet.isDisjoint(secondCustomSet)); } @Ignore("Remove to run test") @Test public void nonEmptySetIsDisjointWithEmptySet() { - final boolean actual - = new CustomSet<>(Collections.singletonList(1)) - .isDisjoint( - new CustomSet<>(Collections.emptyList()) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.singletonList('1')); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + assertTrue(customSet.isDisjoint(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setsAreNotDisjointIfTheyShareAnElement() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2)) - .isDisjoint( - new CustomSet<>(Arrays.asList(2, 3)) - ); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList("1", "2")); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("2", "3")); + assertFalse(customSet.isDisjoint(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setsAreDisjointIfTheyShareNoElements() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2)) - .isDisjoint( - new CustomSet<>(Arrays.asList(3, 4)) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2)); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList(3, 4)); + assertTrue(customSet.isDisjoint(secondCustomSet)); } @Ignore("Remove to run test") @Test public void emptySetsAreEqual() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .equals( - new CustomSet<>(Collections.emptyList()) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + assertTrue(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void emptySetIsNotEqualToNonEmptySet() { - final boolean actual - = new CustomSet<>(Collections.emptyList()) - .equals( - new CustomSet<>(Arrays.asList(1, 2, 3)) - ); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3")); + assertFalse(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void nonEmptySetIsNotEqualToEmptySet() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2, 3)) - .equals( - new CustomSet<>(Collections.emptyList()) - ); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2, 3)); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + assertFalse(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setsWithTheSameElementsAreEqual() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2)) - .equals( - new CustomSet<>(Arrays.asList(2, 1)) - ); - - assertTrue(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList('1', '2')); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList('2', '1')); + assertTrue(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setsWithDifferentElementsAreNotEqual() { - final boolean actual - = new CustomSet<>(Arrays.asList(1, 2, 3)) - .equals( - new CustomSet<>(Arrays.asList(1, 2, 4)) - ); - - assertFalse(actual); + CustomSet customSet = new CustomSet<>(Arrays.asList("1", "2", "3")); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "4")); + assertFalse(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void addToEmptySet() { - final int element = 3; - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Collections.singletonList(element)) - ); - final CustomSet actual - = new CustomSet<>(Collections.emptyList()); + int element = 3; + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(element))); + CustomSet actual = new CustomSet<>(Collections.emptyList()); actual.add(element); @@ -270,13 +187,9 @@ public void addToEmptySet() { @Ignore("Remove to run test") @Test public void addToNonEmptySet() { - final int element = 3; - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(1, 2, 3, 4)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 2, 4)); + char element = '3'; + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('1', '2', '3', '4'))); + CustomSet actual = new CustomSet<>(Arrays.asList('1', '2', '4')); actual.add(element); @@ -288,13 +201,9 @@ public void addToNonEmptySet() { @Ignore("Remove to run test") @Test public void addingAnExistingElementDoesNotChangeTheSet() { - final int element = 3; - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(1, 2, 3)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 2, 3)); + String element = "3"; + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "2", "3"))); + CustomSet actual = new CustomSet<>(Arrays.asList("1", "2", "3")); actual.add(element); @@ -305,11 +214,8 @@ public void addingAnExistingElementDoesNotChangeTheSet() { @Ignore("Remove to run test") @Test public void intersectionOfTwoEmptySetsIsAnEmptySet() { - final CustomSet actual - = new CustomSet(Collections.emptyList()) - .getIntersection( - new CustomSet<>(Collections.emptyList()) - ); + CustomSet actual = new CustomSet(Collections.emptyList()) + .getIntersection(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -318,11 +224,8 @@ public void intersectionOfTwoEmptySetsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() { - final CustomSet actual - = new CustomSet(Collections.emptyList()) - .getIntersection( - new CustomSet<>(Arrays.asList(3, 2, 5)) - ); + CustomSet actual = new CustomSet(Collections.emptyList()) + .getIntersection(new CustomSet<>(Arrays.asList('3', '2', '5'))); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -331,11 +234,8 @@ public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() { - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 2, 3, 4)) - .getIntersection( - new CustomSet<>(Collections.emptyList()) - ); + CustomSet actual = new CustomSet<>(Arrays.asList("1", "2", "3", "4")) + .getIntersection(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -345,11 +245,8 @@ public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfTwoSetsWithNoSharedElementsIsAnEmptySet() { - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 2, 3)) - .getIntersection( - new CustomSet<>(Arrays.asList(4, 5, 6)) - ); + CustomSet actual = new CustomSet<>(Arrays.asList(1, 2, 3)) + .getIntersection(new CustomSet<>(Arrays.asList(4, 5, 6))); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -358,15 +255,9 @@ public void intersectionOfTwoSetsWithNoSharedElementsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() { - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(2, 3)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 2, 3, 4)) - .getIntersection( - new CustomSet<>(Arrays.asList(3, 2, 5)) - ); + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('2', '3'))); + CustomSet actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4')) + .getIntersection(new CustomSet<>(Arrays.asList('3', '2', '5'))); assertNotNull(actual); assertFalse(actual.isEmpty()); @@ -376,11 +267,8 @@ public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() { @Ignore("Remove to run test") @Test public void differenceOfTwoEmptySetsIsAnEmptySet() { - final CustomSet actual - = new CustomSet(Collections.emptyList()) - .getDifference( - new CustomSet<>(Collections.emptyList()) - ); + CustomSet actual = new CustomSet(Collections.emptyList()) + .getDifference(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -389,11 +277,8 @@ public void differenceOfTwoEmptySetsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() { - final CustomSet actual - = new CustomSet(Collections.emptyList()) - .getDifference( - new CustomSet<>(Arrays.asList(3, 2, 5)) - ); + CustomSet actual = new CustomSet(Collections.emptyList()) + .getDifference(new CustomSet<>(Arrays.asList(3, 2, 5))); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -402,15 +287,9 @@ public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() { @Ignore("Remove to run test") @Test public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(1, 2, 3, 4)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 2, 3, 4)) - .getDifference( - new CustomSet<>(Collections.emptyList()) - ); + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('1', '2', '3', '4'))); + CustomSet actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4')) + .getDifference(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertFalse(actual.isEmpty()); @@ -420,15 +299,9 @@ public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { @Ignore("Remove to run test") @Test public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet() { - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(1, 3)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(3, 2, 1)) - .getDifference( - new CustomSet<>(Arrays.asList(2, 4)) - ); + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "3"))); + CustomSet actual = new CustomSet<>(Arrays.asList("3", "2", "1")) + .getDifference(new CustomSet<>(Arrays.asList("2", "4"))); assertNotNull(actual); assertFalse(actual.isEmpty()); @@ -438,11 +311,8 @@ public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet( @Ignore("Remove to run test") @Test public void unionOfTwoEmptySetsIsAnEmptySet() { - final CustomSet actual - = new CustomSet(Collections.emptyList()) - .getUnion( - new CustomSet<>(Collections.emptyList()) - ); + CustomSet actual = new CustomSet(Collections.emptyList()) + .getUnion(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); @@ -451,15 +321,9 @@ public void unionOfTwoEmptySetsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() { - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Collections.singletonList(2)) - ); - final CustomSet actual - = new CustomSet(Collections.emptyList()) - .getUnion( - new CustomSet<>(Collections.singletonList(2)) - ); + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList('2'))); + CustomSet actual = new CustomSet(Collections.emptyList()) + .getUnion(new CustomSet<>(Collections.singletonList('2'))); assertNotNull(actual); assertFalse(actual.isEmpty()); @@ -469,15 +333,9 @@ public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() { @Ignore("Remove to run test") @Test public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(1, 3)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 3)) - .getUnion( - new CustomSet<>(Collections.emptyList()) - ); + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "3"))); + CustomSet actual = new CustomSet<>(Arrays.asList("1", "3")) + .getUnion(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertFalse(actual.isEmpty()); @@ -487,15 +345,9 @@ public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { @Ignore("Remove to run test") @Test public void unionOfTwoNonEmptySetsContainsAllUniqueElements() { - final CustomSet expected - = new CustomSet<>( - Collections.unmodifiableList(Arrays.asList(3, 2, 1)) - ); - final CustomSet actual - = new CustomSet<>(Arrays.asList(1, 3)) - .getUnion( - new CustomSet<>(Arrays.asList(2, 3)) - ); + CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(3, 2, 1))); + CustomSet actual = new CustomSet<>(Arrays.asList(1, 3)) + .getUnion(new CustomSet<>(Arrays.asList(2, 3))); assertNotNull(actual); assertFalse(actual.isEmpty());