import org.junit.Ignore; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import static org.junit.Assert.*; public class CustomSetTest { @Test public void setsWithNoElementsAreEmpty() { CustomSet customSet = new CustomSet<>(Collections.emptyList()); assertTrue(customSet.isEmpty()); } @Ignore("Remove to run test") @Test public void setsWithElementsAreNotEmpty() { 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")); } @Ignore("Remove to run test") @Test public void whenTheElementIsInTheSet() { 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')); } @Ignore("Remove to run test") @Test public void emptySetIsASubsetOfAnotherEmptySet() { 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()); assertTrue(customSet.isSubset(secondCustomSet)); } @Ignore("Remove to run test") @Test public void nonEmptySetIsNotASubsetOfEmptySet() { 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() { 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() { 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() { 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()); assertTrue(customSet.isDisjoint(secondCustomSet)); } @Ignore("Remove to run test") @Test public void emptySetIsDisjointWithNonEmptySet() { 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() { 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() { 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)); 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()); 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")); assertFalse(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void nonEmptySetIsNotEqualToEmptySet() { 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() { 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("1", "2", "4")); assertFalse(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void setIsNotEqualToLargerSetWithSameElements() { CustomSet customSet = new CustomSet<>(Arrays.asList("1", "2", "3")); CustomSet secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3", "4")); assertFalse(customSet.equals(secondCustomSet)); } @Ignore("Remove to run test") @Test public void addToEmptySet() { int element = 3; CustomSet expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(element))); CustomSet actual = new CustomSet<>(Collections.emptyList()); actual.add(element); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @Ignore("Remove to run test") @Test public void addToNonEmptySet() { 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); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @Ignore("Remove to run test") @Test public void addingAnExistingElementDoesNotChangeTheSet() { 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); assertNotNull(actual); assertTrue(expected.equals(actual)); } @Ignore("Remove to run test") @Test public void intersectionOfTwoEmptySetsIsAnEmptySet() { CustomSet actual = new CustomSet(Collections.emptyList()) .getIntersection(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); } @Ignore("Remove to run test") @Test public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() { CustomSet actual = new CustomSet(Collections.emptyList()) .getIntersection(new CustomSet<>(Arrays.asList('3', '2', '5'))); assertNotNull(actual); assertTrue(actual.isEmpty()); } @Ignore("Remove to run test") @Test public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() { CustomSet actual = new CustomSet<>(Arrays.asList("1", "2", "3", "4")) .getIntersection(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); } @Ignore("Remove to run test") @Test public void intersectionOfTwoSetsWithNoSharedElementsIsAnEmptySet() { CustomSet actual = new CustomSet<>(Arrays.asList(1, 2, 3)) .getIntersection(new CustomSet<>(Arrays.asList(4, 5, 6))); assertNotNull(actual); assertTrue(actual.isEmpty()); } @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'))); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @Ignore("Remove to run test") @Test public void differenceOfTwoEmptySetsIsAnEmptySet() { CustomSet actual = new CustomSet(Collections.emptyList()) .getDifference(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); } @Ignore("Remove to run test") @Test public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() { CustomSet actual = new CustomSet(Collections.emptyList()) .getDifference(new CustomSet<>(Arrays.asList(3, 2, 5))); assertNotNull(actual); assertTrue(actual.isEmpty()); } @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')) .getDifference(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @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"))); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @Ignore("Remove to run test") @Test public void unionOfTwoEmptySetsIsAnEmptySet() { CustomSet actual = new CustomSet(Collections.emptyList()) .getUnion(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertTrue(actual.isEmpty()); } @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'))); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @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")) .getUnion(new CustomSet<>(Collections.emptyList())); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } @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))); assertNotNull(actual); assertFalse(actual.isEmpty()); assertTrue(expected.equals(actual)); } }