From 716cc180e61b36041bc1400ef8c1bdb4dda46c0a Mon Sep 17 00:00:00 2001 From: Frida Tveit Date: Tue, 17 Oct 2017 10:58:33 +0100 Subject: [PATCH 1/3] custom-set: use generics and tidy up tests --- .../src/test/java/CustomSetTest.java | 354 +++++------------- 1 file changed, 103 insertions(+), 251 deletions(-) diff --git a/exercises/custom-set/src/test/java/CustomSetTest.java b/exercises/custom-set/src/test/java/CustomSetTest.java index a28287d97..663f3d3d6 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(2, 1, 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()); + char 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)); + int 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()); From f37c602ca75d29222a98607679020f21a9b1114b Mon Sep 17 00:00:00 2001 From: Frida Tveit Date: Wed, 18 Oct 2017 19:44:24 +0100 Subject: [PATCH 2/3] custom-set: pattern for generics in tests --- .../src/test/java/CustomSetTest.java | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/exercises/custom-set/src/test/java/CustomSetTest.java b/exercises/custom-set/src/test/java/CustomSetTest.java index 663f3d3d6..3dbb7fe01 100644 --- a/exercises/custom-set/src/test/java/CustomSetTest.java +++ b/exercises/custom-set/src/test/java/CustomSetTest.java @@ -17,44 +17,44 @@ public void setsWithNoElementsAreEmpty() { @Ignore("Remove to run test") @Test public void setsWithElementsAreNotEmpty() { - CustomSet customSet = new CustomSet<>(Collections.singletonList(1)); + CustomSet customSet = new CustomSet<>(Collections.singletonList('1')); assertFalse(customSet.isEmpty()); } @Ignore("Remove to run test") @Test public void nothingIsContainedInAnEmptySet() { - CustomSet customSet = new CustomSet<>(Collections.emptyList()); - assertFalse(customSet.contains('1')); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + assertFalse(customSet.contains("1")); } @Ignore("Remove to run test") @Test public void whenTheElementIsInTheSet() { - CustomSet customSet = new CustomSet<>(Arrays.asList("1", "2", "3")); - assertTrue(customSet.contains("1")); + CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2, 3)); + assertTrue(customSet.contains(1)); } @Ignore("Remove to run test") @Test public void whenTheElementIsNotInTheSet() { - CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2, 3)); - assertFalse(customSet.contains(4)); + CustomSet customSet = new CustomSet<>(Arrays.asList('1', '2', '3')); + assertFalse(customSet.contains('4')); } @Ignore("Remove to run test") @Test public void emptySetIsASubsetOfAnotherEmptySet() { - CustomSet customSet = new CustomSet<>(Collections.emptyList()); - CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + 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() { - CustomSet customSet = new CustomSet<>(Collections.singletonList('1')); - CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + CustomSet customSet = new CustomSet<>(Collections.singletonList(1)); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); assertTrue(customSet.isSubset(secondCustomSet)); } @@ -85,16 +85,16 @@ public void setIsASubsetOfLargerSetWithSameElements() { @Ignore("Remove to run test") @Test public void setIsNotASubsetOfSetThatDoesNotContainItsElements() { - CustomSet customSet = new CustomSet<>(Arrays.asList(4, 1, 3)); - CustomSet secondCustomSet = new CustomSet<>(Arrays.asList(1, 2, 3)); + 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() { - CustomSet customSet = new CustomSet<>(Collections.emptyList()); - CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); assertTrue(customSet.isDisjoint(secondCustomSet)); } @@ -117,32 +117,32 @@ public void nonEmptySetIsDisjointWithEmptySet() { @Ignore("Remove to run test") @Test public void setsAreNotDisjointIfTheyShareAnElement() { - CustomSet customSet = new CustomSet<>(Arrays.asList('1', '2')); - CustomSet secondCustomSet = new CustomSet<>(Arrays.asList('2', '3')); + 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() { - CustomSet customSet = new CustomSet<>(Arrays.asList("1", "2")); - CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("3", "4")); + 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() { - CustomSet customSet = new CustomSet<>(Collections.emptyList()); - CustomSet secondCustomSet = new CustomSet<>(Collections.emptyList()); + 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() { - CustomSet customSet = new CustomSet<>(Collections.emptyList()); - CustomSet secondCustomSet = new CustomSet<>(Arrays.asList(1, 2, 3)); + CustomSet customSet = new CustomSet<>(Collections.emptyList()); + CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3")); assertFalse(customSet.equals(secondCustomSet)); } @@ -157,25 +157,25 @@ public void nonEmptySetIsNotEqualToEmptySet() { @Ignore("Remove to run test") @Test public void setsWithTheSameElementsAreEqual() { - CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2)); - CustomSet secondCustomSet = new CustomSet<>(Arrays.asList(2, 1)); + 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() { - CustomSet customSet = new CustomSet<>(Arrays.asList(1, 2, 3)); - CustomSet secondCustomSet = new CustomSet<>(Arrays.asList(2, 1, 4)); + 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() { - char element = '3'; - CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(element))); - 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); @@ -187,9 +187,9 @@ public void addToEmptySet() { @Ignore("Remove to run test") @Test public void addToNonEmptySet() { - int element = 3; - CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 2, 3, 4))); - 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); @@ -224,8 +224,8 @@ public void intersectionOfTwoEmptySetsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() { - 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()); @@ -234,7 +234,7 @@ public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() { - CustomSet actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4')) + CustomSet actual = new CustomSet<>(Arrays.asList("1", "2", "3", "4")) .getIntersection(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); @@ -255,9 +255,9 @@ public void intersectionOfTwoSetsWithNoSharedElementsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() { - 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))); + 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()); @@ -267,7 +267,7 @@ public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() { @Ignore("Remove to run test") @Test public void differenceOfTwoEmptySetsIsAnEmptySet() { - CustomSet actual = new CustomSet(Collections.emptyList()) + CustomSet actual = new CustomSet(Collections.emptyList()) .getDifference(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); @@ -277,8 +277,8 @@ public void differenceOfTwoEmptySetsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() { - 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()); @@ -287,8 +287,8 @@ public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() { @Ignore("Remove to run test") @Test public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { - CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 2, 3, 4))); - CustomSet actual = new CustomSet<>(Arrays.asList(1, 2, 3, 4)) + 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); @@ -299,9 +299,9 @@ public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { @Ignore("Remove to run test") @Test public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet() { - 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))); + 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()); @@ -321,9 +321,9 @@ public void unionOfTwoEmptySetsIsAnEmptySet() { @Ignore("Remove to run test") @Test public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() { - CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(2))); - 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()); @@ -333,8 +333,8 @@ public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() { @Ignore("Remove to run test") @Test public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { - CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 3))); - CustomSet actual = new CustomSet<>(Arrays.asList(1, 3)) + 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); @@ -345,9 +345,9 @@ public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() { @Ignore("Remove to run test") @Test public void unionOfTwoNonEmptySetsContainsAllUniqueElements() { - 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'))); + 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()); From 642f14990163682be5d2da017b6691a55d16e2e9 Mon Sep 17 00:00:00 2001 From: Frida Tveit Date: Wed, 18 Oct 2017 19:47:54 +0100 Subject: [PATCH 3/3] custom-set: add version file --- exercises/custom-set/.meta/version | 1 + 1 file changed, 1 insertion(+) create mode 100644 exercises/custom-set/.meta/version 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