diff --git a/kotlin/custom-set/.exercism/metadata.json b/kotlin/custom-set/.exercism/metadata.json new file mode 100644 index 0000000..d962d54 --- /dev/null +++ b/kotlin/custom-set/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"kotlin","exercise":"custom-set","id":"bae351839e7547ebb21a6dbc840e2b04","url":"https://exercism.io/my/solutions/bae351839e7547ebb21a6dbc840e2b04","handle":"anthonycicc","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/kotlin/custom-set/.gradle/6.0.1/executionHistory/executionHistory.bin b/kotlin/custom-set/.gradle/6.0.1/executionHistory/executionHistory.bin new file mode 100644 index 0000000..7fa0c37 Binary files /dev/null and b/kotlin/custom-set/.gradle/6.0.1/executionHistory/executionHistory.bin differ diff --git a/kotlin/custom-set/.gradle/6.0.1/executionHistory/executionHistory.lock b/kotlin/custom-set/.gradle/6.0.1/executionHistory/executionHistory.lock new file mode 100644 index 0000000..2233249 Binary files /dev/null and b/kotlin/custom-set/.gradle/6.0.1/executionHistory/executionHistory.lock differ diff --git a/kotlin/custom-set/.gradle/6.0.1/fileChanges/last-build.bin b/kotlin/custom-set/.gradle/6.0.1/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/kotlin/custom-set/.gradle/6.0.1/fileChanges/last-build.bin differ diff --git a/kotlin/custom-set/.gradle/6.0.1/fileContent/fileContent.lock b/kotlin/custom-set/.gradle/6.0.1/fileContent/fileContent.lock new file mode 100644 index 0000000..24c433c Binary files /dev/null and b/kotlin/custom-set/.gradle/6.0.1/fileContent/fileContent.lock differ diff --git a/kotlin/custom-set/.gradle/6.0.1/fileHashes/fileHashes.bin b/kotlin/custom-set/.gradle/6.0.1/fileHashes/fileHashes.bin new file mode 100644 index 0000000..7f628b8 Binary files /dev/null and b/kotlin/custom-set/.gradle/6.0.1/fileHashes/fileHashes.bin differ diff --git a/kotlin/custom-set/.gradle/6.0.1/fileHashes/fileHashes.lock b/kotlin/custom-set/.gradle/6.0.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000..8cd3633 Binary files /dev/null and b/kotlin/custom-set/.gradle/6.0.1/fileHashes/fileHashes.lock differ diff --git a/kotlin/custom-set/.gradle/6.0.1/gc.properties b/kotlin/custom-set/.gradle/6.0.1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/kotlin/custom-set/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/kotlin/custom-set/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..5f6a022 Binary files /dev/null and b/kotlin/custom-set/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/kotlin/custom-set/.gradle/buildOutputCleanup/cache.properties b/kotlin/custom-set/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..2ea8b15 --- /dev/null +++ b/kotlin/custom-set/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Sat Mar 07 17:31:28 EST 2020 +gradle.version=6.0.1 diff --git a/kotlin/custom-set/.gradle/buildOutputCleanup/outputFiles.bin b/kotlin/custom-set/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..c0268e2 Binary files /dev/null and b/kotlin/custom-set/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/kotlin/custom-set/.gradle/vcs-1/gc.properties b/kotlin/custom-set/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/kotlin/custom-set/.idea/.gitignore b/kotlin/custom-set/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/kotlin/custom-set/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/kotlin/custom-set/.idea/compiler.xml b/kotlin/custom-set/.idea/compiler.xml new file mode 100644 index 0000000..7e7ee62 --- /dev/null +++ b/kotlin/custom-set/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/custom-set/.idea/jarRepositories.xml b/kotlin/custom-set/.idea/jarRepositories.xml new file mode 100644 index 0000000..efa4625 --- /dev/null +++ b/kotlin/custom-set/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/custom-set/.idea/misc.xml b/kotlin/custom-set/.idea/misc.xml new file mode 100644 index 0000000..b9d0e72 --- /dev/null +++ b/kotlin/custom-set/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/kotlin/custom-set/.idea/vcs.xml b/kotlin/custom-set/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/kotlin/custom-set/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/custom-set/README.md b/kotlin/custom-set/README.md new file mode 100644 index 0000000..f5dcb1b --- /dev/null +++ b/kotlin/custom-set/README.md @@ -0,0 +1,35 @@ +# Custom Set + +Create a custom set type. + +Sometimes it is necessary to define a custom data structure of some +type, like a set. In this exercise you will define your own set. How it +works internally doesn't matter, as long as it behaves like a set of +unique elements. + +## Setup + +Go through the setup instructions for Kotlin to install the necessary +dependencies: + +[https://exercism.io/tracks/kotlin/installation](https://exercism.io/tracks/kotlin/installation) + +## Making the test suite pass + +Execute the tests with: + +```bash +$ ./gradlew test +``` + +> Use `gradlew.bat` if you're on Windows + +In the test suites all tests but the first have been skipped. + +Once you get a test passing, you can enable the next one by removing the +`@Ignore` annotation. + +## Submitting Incomplete Solutions + +It's possible to submit an incomplete solution so you can see how others have +completed the exercise. diff --git a/kotlin/custom-set/build.gradle.kts b/kotlin/custom-set/build.gradle.kts new file mode 100644 index 0000000..1793ac4 --- /dev/null +++ b/kotlin/custom-set/build.gradle.kts @@ -0,0 +1,23 @@ +import org.gradle.api.tasks.testing.logging.TestExceptionFormat + +plugins { + kotlin("jvm") version "1.3.60" +} + +repositories { + jcenter() +} + +dependencies { + compile(kotlin("stdlib")) + + testImplementation("junit:junit:4.12") + testImplementation(kotlin("test-junit")) +} + +tasks.withType { + testLogging { + exceptionFormat = TestExceptionFormat.FULL + events("passed", "failed", "skipped") + } +} diff --git a/kotlin/custom-set/gradle/wrapper/gradle-wrapper.properties b/kotlin/custom-set/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9492014 --- /dev/null +++ b/kotlin/custom-set/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/kotlin/custom-set/gradlew b/kotlin/custom-set/gradlew new file mode 100644 index 0000000..83f2acf --- /dev/null +++ b/kotlin/custom-set/gradlew @@ -0,0 +1,188 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/kotlin/custom-set/gradlew.bat b/kotlin/custom-set/gradlew.bat new file mode 100644 index 0000000..9618d8d --- /dev/null +++ b/kotlin/custom-set/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/kotlin/custom-set/src/main/kotlin/CustomSet.kt b/kotlin/custom-set/src/main/kotlin/CustomSet.kt new file mode 100644 index 0000000..78d79bf --- /dev/null +++ b/kotlin/custom-set/src/main/kotlin/CustomSet.kt @@ -0,0 +1,42 @@ +class CustomSet() { + + var internals = mutableSetOf() + + constructor(vararg stuff: Int): this() { + stuff.forEach { this.add(it) } + } + + constructor(wrapped: Set): this() { + wrapped.forEach { this.add(it) } + } + + fun isEmpty(): Boolean = internals.isEmpty() + + fun isSubset(other: CustomSet): Boolean = other.internals.containsAll(internals) + + fun isDisjoint(other: CustomSet): Boolean { + return if (this.internals.isNotEmpty() && other.internals.isNotEmpty()) { + other.internals.all { it !in this.internals } + } else true + } + + fun contains(other: Int): Boolean = this.internals.contains(other) + + fun intersection(other: CustomSet): CustomSet = CustomSet(other.internals.intersect(this.internals)) + + fun add(other: Int) { + internals.add(other) + } + + override fun equals(other: Any?) = if (other is CustomSet) { + other.internals == internals + } else { + false + } + + operator fun plus(other: CustomSet) = CustomSet(internals.plus(other.internals)) + + operator fun minus(other: CustomSet) = CustomSet(this.internals.minus(other.internals)) + + override fun hashCode() = javaClass.hashCode() +} diff --git a/kotlin/custom-set/src/test/kotlin/CustomSetTest.kt b/kotlin/custom-set/src/test/kotlin/CustomSetTest.kt new file mode 100644 index 0000000..1b8e041 --- /dev/null +++ b/kotlin/custom-set/src/test/kotlin/CustomSetTest.kt @@ -0,0 +1,286 @@ +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotEquals +import kotlin.test.assertTrue + +class CustomSetTest { + + @Test + fun `sets with no elements are empty`() { + val sut = CustomSet() + assertTrue(sut.isEmpty()) + } + + @Test + fun `sets with elements are not empty`() { + val sut = CustomSet(1) + assertFalse(sut.isEmpty()) + } + + @Test + fun `nothing is contained in an empty set`() { + val sut = CustomSet() + assertFalse(sut.contains(1)) + } + + @Test + fun `when the element is in the set`() { + val sut = CustomSet(1, 2, 3) + assertTrue(sut.contains(1)) + } + + @Test + fun `when the element is not in the set`() { + val sut = CustomSet(1, 2, 3) + assertFalse(sut.contains(4)) + } + + @Test + fun `empty set is a subset of another empty set`() { + val set1 = CustomSet() + val set2 = CustomSet() + assertTrue(set1.isSubset(set2)) + } + + @Test + fun `empty set is a subset of non empty set`() { + val set1 = CustomSet() + val set2 = CustomSet(1) + assertTrue(set1.isSubset(set2)) + } + + @Test + fun `non empty set is not a subset of empty set`() { + val set1 = CustomSet(1) + val set2 = CustomSet() + assertFalse(set1.isSubset(set2)) + } + + @Test + fun `set is a subset of set with exact same elements`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet(1, 2, 3) + assertTrue(set1.isSubset(set2)) + } + + @Test + fun `set is a subset of larger set with same elements`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet(4, 1, 2, 3) + assertTrue(set1.isSubset(set2)) + } + + @Test + fun `set is not a subset of set that does not contain its elements`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet(4, 1, 3) + assertFalse(set1.isSubset(set2)) + } + + @Test + fun `the empty set is disjoint with itself`() { + val set1 = CustomSet() + val set2 = CustomSet() + assertTrue(set1.isDisjoint(set2)) + } + + @Test + fun `empty set is disjoint with non empty set`() { + val set1 = CustomSet() + val set2 = CustomSet(1) + assertTrue(set1.isDisjoint(set2)) + } + + @Test + fun `non empty set is disjoint with empty set`() { + val set1 = CustomSet(1) + val set2 = CustomSet() + assertTrue(set1.isDisjoint(set2)) + } + + @Test + fun `sets are not disjoint if they share an element`() { + val set1 = CustomSet(1, 2) + val set2 = CustomSet(2, 3) + assertFalse(set1.isDisjoint(set2)) + } + + @Test + fun `sets are disjoint if they share no elements`() { + val set1 = CustomSet(1, 2) + val set2 = CustomSet(3, 4) + assertTrue(set1.isDisjoint(set2)) + } + + @Test + fun `empty sets are equal`() { + val set1 = CustomSet() + val set2 = CustomSet() + assertEquals(set1, set2) + } + + @Test + fun `empty set is not equal to non empty set`() { + val set1 = CustomSet() + val set2 = CustomSet(1, 2, 3) + assertNotEquals(set1, set2) + } + + @Test + fun `non empty set is not equal to empty set`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet() + assertNotEquals(set1, set2) + } + + @Test + fun `sets with the same elements are equal`() { + val set1 = CustomSet(1, 2) + val set2 = CustomSet(2, 1) + assertEquals(set1, set2) + + } + + @Test + fun `sets with different elements are not equal`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet(1, 2, 4) + assertNotEquals(set1, set2) + } + + @Test + fun `set is not equal to larger set with same elements`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet(1, 2, 3, 4) + assertNotEquals(set1, set2) + } + + @Test + fun `add to empty set`() { + val sut = CustomSet() + val expected = CustomSet(3) + sut.add(3) + assertEquals(expected, sut) + } + + @Test + fun `add to non empty set`() { + val sut = CustomSet(1, 2, 4) + val expected = CustomSet(1, 2, 3, 4) + sut.add(3) + assertEquals(expected, sut) + } + + @Test + fun `adding an existing element does not change the set`() { + val sut = CustomSet(1, 2, 3) + val expected = CustomSet(1, 2, 3) + sut.add(3) + assertEquals(expected, sut) + } + + @Test + fun `intersection of two empty sets is an empty set`() { + val set1 = CustomSet() + val set2 = CustomSet() + val expected = CustomSet() + assertEquals(expected, set1.intersection(set2)) + } + + @Test + fun `intersection of an empty set and non empty set is an empty set`() { + val set1 = CustomSet() + val set2 = CustomSet(3, 2, 5) + val expected = CustomSet() + assertEquals(expected, set1.intersection(set2)) + } + + @Test + fun `intersection of a non empty set and an empty set is an empty set`() { + val set1 = CustomSet(1, 2, 3, 4) + val set2 = CustomSet() + val expected = CustomSet() + assertEquals(expected, set1.intersection(set2)) + } + + @Test + fun `intersection of two sets with no shared elements is an empty set`() { + val set1 = CustomSet(1, 2, 3) + val set2 = CustomSet(4, 5, 6) + val expected = CustomSet() + assertEquals(expected, set1.intersection(set2)) + } + + @Test + fun `intersection of two sets with shared elements is a set of the shared elements`() { + val set1 = CustomSet(1, 2, 3, 4) + val set2 = CustomSet(3, 2, 5) + val expected = CustomSet(2, 3) + assertEquals(expected, set1.intersection(set2)) + } + + @Test + fun `difference of two empty sets is an empty set`() { + val set1 = CustomSet() + val set2 = CustomSet() + val expected = CustomSet() + assertEquals(expected, set1 - set2) + } + + @Test + fun `difference of empty set and non empty set is an empty set`() { + val set1 = CustomSet() + val set2 = CustomSet(3, 2, 5) + val expected = CustomSet() + assertEquals(expected, set1 - set2) + } + + @Test + fun `difference of a non empty set and an empty set is the non empty set`() { + val set1 = CustomSet(1, 2, 3, 4) + val set2 = CustomSet() + val expected = CustomSet(1, 2, 3, 4) + assertEquals(expected, set1 - set2) + } + + @Test + fun `difference of two non empty sets is a set of elements that are only in the first set`() { + val set1 = CustomSet(3, 2, 1) + val set2 = CustomSet(2, 4) + val expected = CustomSet(1, 3) + assertEquals(expected, set1 - set2) + } + + @Test + fun `union of empty sets is an empty set`() { + val set1 = CustomSet() + val set2 = CustomSet() + val expected = CustomSet() + assertEquals(expected, set1 + set2) + } + + @Test + fun `union of an empty set and non empty set is the non empty set`() { + val set1 = CustomSet() + val set2 = CustomSet(2) + val expected = CustomSet(2) + assertEquals(expected, set1 + set2) + } + + @Test + fun `union of a non empty set and empty set is the non empty set`() { + val set1 = CustomSet(1, 3) + val set2 = CustomSet() + val expected = CustomSet(1, 3) + assertEquals(expected, set1 + set2) + } + + @Test + fun `union of non empty sets contains all unique elements`() { + val set1 = CustomSet(1, 3) + val set2 = CustomSet(2, 3) + val expected = CustomSet(3, 2, 1) + assertEquals(expected, set1 + set2) + } +}