From ff253c31dda8ad7583dd13ce6796dc7d303fe9ec Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 16 Oct 2017 14:22:38 +0300 Subject: [PATCH 1/9] codestyle format --- kek2/Java | 1 + 1 file changed, 1 insertion(+) create mode 160000 kek2/Java diff --git a/kek2/Java b/kek2/Java new file mode 160000 index 0000000..d207fbc --- /dev/null +++ b/kek2/Java @@ -0,0 +1 @@ +Subproject commit d207fbc8f6316ee94011c17d43e488e48f2e61eb From 66865afcebe7d64f67ad9e3b530bbcdceee4545f Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 16 Oct 2017 14:23:18 +0300 Subject: [PATCH 2/9] codestyle format --- Untitled Folder 2/Java/.gitignore | 49 +++++++++++ Untitled Folder 2/Java/.idea/compiler.xml | 16 ++++ Untitled Folder 2/Java/.idea/misc.xml | 13 +++ Untitled Folder 2/Java/.idea/modules.xml | 8 ++ Untitled Folder 2/Java/Maybe.iml | 17 ++++ Untitled Folder 2/Java/pom.xml | 36 ++++++++ .../java/ru/spbau/mit/kazakov/Maybe/Main.java | 63 +++++++++++++ .../ru/spbau/mit/kazakov/Maybe/Maybe.java | 83 ++++++++++++++++++ .../kazakov/Maybe/getNothingException.java | 7 ++ .../ru/spbau/mit/kazakov/Maybe/MainTest.java | 47 ++++++++++ .../ru/spbau/mit/kazakov/Maybe/MaybeTest.java | 60 +++++++++++++ .../ru/spbau/mit/kazakov/Maybe/Main.class | Bin 0 -> 3978 bytes .../ru/spbau/mit/kazakov/Maybe/Maybe.class | Bin 0 -> 2100 bytes .../kazakov/Maybe/getNothingException.class | Bin 0 -> 339 bytes .../compile/default-compile/createdFiles.lst | 3 + .../compile/default-compile/inputFiles.lst | 3 + .../default-testCompile/createdFiles.lst | 2 + .../default-testCompile/inputFiles.lst | 2 + ...ST-ru.spbau.mit.kazakov.Maybe.MainTest.xml | 64 ++++++++++++++ ...T-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml | 70 +++++++++++++++ .../ru.spbau.mit.kazakov.Maybe.MainTest.txt | 4 + .../ru.spbau.mit.kazakov.Maybe.MaybeTest.txt | 4 + .../ru/spbau/mit/kazakov/Maybe/MainTest.class | Bin 0 -> 2225 bytes .../spbau/mit/kazakov/Maybe/MaybeTest.class | Bin 0 -> 3912 bytes 24 files changed, 551 insertions(+) create mode 100644 Untitled Folder 2/Java/.gitignore create mode 100644 Untitled Folder 2/Java/.idea/compiler.xml create mode 100644 Untitled Folder 2/Java/.idea/misc.xml create mode 100644 Untitled Folder 2/Java/.idea/modules.xml create mode 100644 Untitled Folder 2/Java/Maybe.iml create mode 100644 Untitled Folder 2/Java/pom.xml create mode 100644 Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java create mode 100644 Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java create mode 100644 Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java create mode 100644 Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java create mode 100644 Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java create mode 100644 Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Main.class create mode 100644 Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Maybe.class create mode 100644 Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/getNothingException.class create mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst create mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst create mode 100644 Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MainTest.xml create mode 100644 Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml create mode 100644 Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt create mode 100644 Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt create mode 100644 Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MainTest.class create mode 100644 Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MaybeTest.class diff --git a/Untitled Folder 2/Java/.gitignore b/Untitled Folder 2/Java/.gitignore new file mode 100644 index 0000000..345e61a --- /dev/null +++ b/Untitled Folder 2/Java/.gitignore @@ -0,0 +1,49 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties diff --git a/Untitled Folder 2/Java/.idea/compiler.xml b/Untitled Folder 2/Java/.idea/compiler.xml new file mode 100644 index 0000000..067d5ff --- /dev/null +++ b/Untitled Folder 2/Java/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/.idea/misc.xml b/Untitled Folder 2/Java/.idea/misc.xml new file mode 100644 index 0000000..e8942bd --- /dev/null +++ b/Untitled Folder 2/Java/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/.idea/modules.xml b/Untitled Folder 2/Java/.idea/modules.xml new file mode 100644 index 0000000..65c89bb --- /dev/null +++ b/Untitled Folder 2/Java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/Maybe.iml b/Untitled Folder 2/Java/Maybe.iml new file mode 100644 index 0000000..57f498f --- /dev/null +++ b/Untitled Folder 2/Java/Maybe.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/pom.xml b/Untitled Folder 2/Java/pom.xml new file mode 100644 index 0000000..fe36c91 --- /dev/null +++ b/Untitled Folder 2/Java/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + ru.spbau.mit.kazakov.Maybe + Maybe + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + junit + junit + 4.8 + + + org.jetbrains + annotations + 13.0 + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java new file mode 100644 index 0000000..8bd1447 --- /dev/null +++ b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java @@ -0,0 +1,63 @@ +package ru.spbau.mit.kazakov.Maybe; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Reads numbers from input file and writes squared values to output file. If read data isn't a number writes "null" instead. + */ +public class Main { + /** + * Primary method. + * + * @param args the first argument is input file and the second one is output file + */ + public static void main(@NotNull String[] args) throws IOException, getNothingException { + ArrayList> readData = new ArrayList<>(); + try (Scanner scanner = new Scanner(new File(args[0]))) { + while (scanner.hasNextLine()) { + Integer value = tryParse(scanner.nextLine()); + if (value == null) { + readData.add(Maybe.nothing()); + } else { + readData.add(Maybe.just(value)); + } + } + } + + ArrayList> squaredNumber = new ArrayList<>(); + for (Maybe maybeInt : readData) { + squaredNumber.add(maybeInt.map(value -> value * value)); + } + + try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(args[1]))) { + for (Maybe maybeInt : squaredNumber) { + if (maybeInt.isPresent()) { + bufferedWriter.write(maybeInt.get().toString()); + } else { + bufferedWriter.write("null"); + } + bufferedWriter.newLine(); + } + } + } + + /** + * Parses specified String to Integer. + * + * @return Integer if String was a number, and null otherwise + */ + @Nullable + private static Integer tryParse(@NotNull String parsingString) { + try { + return Integer.parseInt(parsingString); + } catch (NumberFormatException e) { + return null; + } + } + +} diff --git a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java new file mode 100644 index 0000000..b0216f4 --- /dev/null +++ b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java @@ -0,0 +1,83 @@ +package ru.spbau.mit.kazakov.Maybe; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Function; + +/** + * Generic container for storing a value or nothing. + */ +public class Maybe { + @Nullable + private final T value; + + /** + * Assigns specified value to class's storing field. + * + * @param t specified value + */ + private Maybe(T t) { + value = t; + } + + /** + * Creates an object for storing specified value. + * + * @param t specified value + * @return new object + */ + @NotNull + public static Maybe just(T t) { + return new Maybe(t); + } + + /** + * Creates an object for strong nothing. + * + * @return new object + */ + @NotNull + public static Maybe nothing() { + return new Maybe(null); + } + + /** + * Returns stored value or throws exception if there is no value. + * + * @return stored value + * @throws getNothingException if there is no stored value + */ + @NotNull + public T get() throws getNothingException { + if (isPresent()) { + return value; + } else { + throw new getNothingException(); + } + } + + /** + * Checks if there is stored value. + * + * @return true if there is stored value, and false otherwise + */ + public boolean isPresent() { + return value != null; + } + + /** + * Maps stored value of type T to another value of type U. + * + * @param mapper a function acting from T to V + * @param image's type + * @return Maybe object storing mapped value if there is a storing value, and Maybe object storing nothing otherwise + */ + @NotNull + public Maybe map(@NotNull Function mapper) { + if (!isPresent()) { + return nothing(); + } + return just(mapper.apply(value)); + } +} diff --git a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java new file mode 100644 index 0000000..7789bf9 --- /dev/null +++ b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java @@ -0,0 +1,7 @@ +package ru.spbau.mit.kazakov.Maybe; + +/** + * Exception thrown when there is no value to return. + */ +public class getNothingException extends Exception { +} diff --git a/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java b/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java new file mode 100644 index 0000000..90c6fe1 --- /dev/null +++ b/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java @@ -0,0 +1,47 @@ +package ru.spbau.mit.kazakov.Maybe; + +import org.junit.Test; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Scanner; + +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; + +import static org.junit.Assert.*; + +public class MainTest { + @Rule + public TemporaryFolder testFolder = new TemporaryFolder(); + + @Test + public void testMain() throws IOException, getNothingException { + File input = testFolder.newFile("input.txt"); + File output = testFolder.newFile("output.txt"); + + try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(input))) { + bufferedWriter.write("1\n0\n-3\nj\njava\n1b\n11 22\n"); + } + + Main.main(new String[]{input.getAbsolutePath(), output.getAbsolutePath()}); + + + assertEquals("1\n0\n9\nnull\nnull\nnull\nnull\n", new String(Files.readAllBytes(Paths.get(output.getAbsolutePath())))); + } + + @Test + public void testMainEmpty() throws IOException, getNothingException { + File input = testFolder.newFile("input.txt"); + File output = testFolder.newFile("output.txt"); + + Main.main(new String[]{input.getAbsolutePath(), output.getAbsolutePath()}); + + assertEquals("", new String(Files.readAllBytes(Paths.get(output.getAbsolutePath())))); + } + +} \ No newline at end of file diff --git a/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java b/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java new file mode 100644 index 0000000..54b7846 --- /dev/null +++ b/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java @@ -0,0 +1,60 @@ +package ru.spbau.mit.kazakov.Maybe; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class MaybeTest { + @Test + public void testJustInteger() throws getNothingException { + Maybe maybeInteger = Maybe.just(5); + int storedValue = maybeInteger.get(); + assertEquals(5, storedValue); + } + + @Test + public void testNothingBoolean() { + Maybe maybeBoolean = Maybe.nothing(); + assertFalse(maybeBoolean.isPresent()); + } + + @Test + public void testGetDouble() throws getNothingException { + Maybe maybeDouble = Maybe.just(-7.0); + double storedValue = maybeDouble.get(); + assertEquals(-7.0, storedValue, 0.000000001); + } + + @Test(expected = getNothingException.class) + public void testGetCharacterThrowsException() throws getNothingException { + Maybe maybeCharacter = Maybe.nothing(); + char storedValue = maybeCharacter.get(); + } + + @Test + public void testIsPresentFalse() { + Maybe maybeBoolean = Maybe.nothing(); + assertFalse(maybeBoolean.isPresent()); + } + + @Test + public void testIsPresentTrue() { + Maybe maybeString = Maybe.just("abacaba"); + assertTrue(maybeString.isPresent()); + } + + @Test + public void testMapJust() throws getNothingException { + Maybe maybeInteger = Maybe.just(10); + Maybe mappedMaybeInteger = maybeInteger.map(value -> value * value); + int mappedValue = mappedMaybeInteger.get(); + assertEquals(100, mappedValue); + } + + @Test + public void testMapNothing() throws getNothingException { + Maybe maybeInteger = Maybe.nothing(); + Maybe mappedMaybeInteger = maybeInteger.map(value -> value * value); + assertFalse(mappedMaybeInteger.isPresent()); + } +} \ No newline at end of file diff --git a/Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Main.class b/Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6bafd51dadac3eb34fc19d52644fad85854c4d65 GIT binary patch literal 3978 zcmbVP>sMS?75^QWnL7-Zgg~Gf@&ZBpE!L{;-q^kyh``#J27#3#v;hx7n`|Q{G?S0Pu z+x=Uw19&@LkD(Rs*YHdXWzv5@!v|vs!-ye-QEA4c8IR#0%ow&~LKr7yG$jj`hUpl# zVn)d6N@S3g#@3Llp@LaqysF`vhPfDah}cK)tPr1*=6MYtieWcCEaVrWcv1R~NMi~4 zqtd*j;bYQ&T*D_cd{QBD+{#++35D|3wu=g(K6~6$*qXGmW~z`GHJuB_XquFoq&;S& zFB*;|^CB_iPFZ<{rleCyqlC29^i1t~qHs+^yxujBM6)R@V!zl}-%%M6O3OqKo_r z&6^uTHu7&7Elf<9jyZnGv0M?m!&htBiBs!V#B#%#q?5H97*55GX^fvXTtlJG7vWjf z>o~?-(#pHsUzNX7FsRB8CquA4l5@FIG>`pH%a3mmoD)=$+DP^B|5Ka@tQvNWv6(?5 z=N&Ww?O}PE0MpQ;;Zq(4a|*FD*T&48YuVYnhEHqwj6%!#Le{l1Jd9Z@ZxJi!49Ccr zjB;-_YrBTWtgtU>JCliN(;amPjC_K}TUtz{Y&TU%r)fvjb>_G~PhcEu4LDx{PJpxq z7Deu+z=|LEe%r|y?y9}wWR8-FKVO(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d9=LCkF{4^TaZby`n*@b%SY&a? z@itn}famy2^%zmOKueF}7-{#=;*BEs7vCk1;~hjFF^6vSaDP-y)2??Cqp#o}IKfdF z-bH#lclt6;uF5z`y!!mTtNgv>KSlmm(QqHTH1ugWt>MgD*sG!cO;nVnIE(eOc{jfm zR3oB+!y+F@gc6qW6-p}e*MNUR_jt~}iT(G{pn-+&jE1vsA)(XgBG#=t0Chs{vKXI9~GSVvBm#}XMEjNHB7(JbYj0uCNix)&)ysRWa8E@c)h=8kARw24ew90+!WXCv=Oj45>O8h7K z2Ym4XtGw-6wfp9SKg#laGZP>XiBOsD{=V*W&Ufkl`t9HU09?WES@dHvgCwR5T+MR4 zCZFpDZe)?hq%5ZUQN&G|%^0|)(6_2GO0_%jLzb30k{j}=n48-J5>aKUly#h_lcy^)4p`pE)EywcrI- zt6A28Rd;-AMZeH1jaBQuUMt(tm(Wfx~8Y8@@sMA{EDo!E6vyc<*pj95bJhd_wNjIu{YG2n9w% zIy2f7k{~46vH+%_@nLwZF_iKB=a5EWlwq+TPHd=nnujA?!g`@jx%v9#Iykm#Qk#BrR9!+jAq z#IS_>3dSewSsxd+e~?Mw6S7jMtuZe$<_GM%KSI{1KZavguyE%wL4wWx5MR_E;>X@eR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml b/Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml new file mode 100644 index 0000000..8af6efe --- /dev/null +++ b/Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt b/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt new file mode 100644 index 0000000..adbb610 --- /dev/null +++ b/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: ru.spbau.mit.kazakov.Maybe.MainTest +------------------------------------------------------------------------------- +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.056 sec - in ru.spbau.mit.kazakov.Maybe.MainTest diff --git a/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt b/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt new file mode 100644 index 0000000..15d544e --- /dev/null +++ b/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: ru.spbau.mit.kazakov.Maybe.MaybeTest +------------------------------------------------------------------------------- +Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.07 sec - in ru.spbau.mit.kazakov.Maybe.MaybeTest diff --git a/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MainTest.class b/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..3f48d60837c6182b50031c73aeaf1e02f1a8ebe6 GIT binary patch literal 2225 zcma)7*-{%v6g`b3MvMou8Y4Ri;3aGZ0nTEC?SwUUB9;KbmdQ4f1{fI4$fFr!@{o^6 z-s0C(`6;P#RRUC~#BYAcM}?f85kgSdNr8H~ef#ve=icu5`=3Al0`MM6DlTJGK}tmp zM(c11V{zP;lRI(TRq&C5k5$xRTtyrcaZJj7N;cC9W>hrb69xBF+{dRXK0`W=Srv1b zSFwQ4RWxBy#S)g|_(H*of(HVsXOz4d$I2V7Kv&vv*OQyRZF))9w~SJ9*(ekpS9f

nBUatnMcZWVWS$r*An=lC%0w)?jPe z%Z!0%#bqpVE^t2UudNxbk$>Qto(!!$y{SLZlctlLII+TQG1D&k9`{sSX3UVg<9oqM z{gS8Wwr2HWz$=jMVUUa&3OM~VXA}bg6l4@UIw?b$TKy5V=|a)l;jSgecXNh3NTB{G zhC#_uLnpcfI{qUS8s5U&0(AlTLGP)jVHIBzIV3GD0&QmpO}UR2B!f^RdG1%T`C8!O zusWm;+*CJJ>8B27)#2gJkr7qHH~3bAE(x{-5SDJQCzm%|XIth?Ll!v-aJ;nSxu(6Y z;Gu>*3BEE}R7`*K?Lrk_Dva^GklQ=o+Pxk!P`2`&W_^KsGRf@odSl ze9u_WJ!Yb{r_8XLH0$pTDuj0|S_rOMThHnlLCcr|v2BLA#v)6~(|DO9Bp@(W&9E%g zSui2;2@KxYQ^-<9B5SUp=f^E;VuzRQScH?Cdsio@ThHo*)VJ~Yj*U|}S5}A~45lCZ zxc#-SPGO&6BzbILi}MA(XL2416zQWTKs(z6TB&q5RUV+u3mj+I ze@~r%q$0o2TPoH^?XKYwdeBP*>QmNE#m`*pr-rTg2{$;ZArAOej31ItOu?XnWbi+v zU>JhUxfwS1_&ekmR5|TY@roQ0D^gh|=m>wcG~VQ={iqz?r%f>Uasu%KrH}-t&Pw3f vvL;?H>rnx<5fv0kr2wrAxR;?$GEgZ^XLw#kkW@vGp|T*a=lvn~*WlK_9R~(P literal 0 HcmV?d00001 diff --git a/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MaybeTest.class b/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MaybeTest.class new file mode 100644 index 0000000000000000000000000000000000000000..fe9ccbf84598e037745c1e9f962681c7c236ddc4 GIT binary patch literal 3912 zcmb7HX;;){6nIA23#v>5l37`TkD3>D!5<=wMuDg?Gk1p1cqcxGAP#8Zg$^W zyV)PnexV#c^!T}_pZgp7D|-68Z!(#gf+(CbN#5n&`@GM6?oIgf-+O-m*oR* z{e4I7c{PUDG<4$iMi_EDk)XwtbYYcT=MoT@ieV;(yg;}+9iVZtb;XDvTHW85%ioVoO< zF+X7j*D=%c2k6%4{Y=sGM{M7mG+hCGR&I)hTOR6(UYb4Man0PgkuMUM7!l~I1~*?Q z0X*PvcBn#O}WlBFJeQWRRxRInSmjJL#v7x8LNTnm?*{ch~Ui4jN za<#k$R?2m=bUkVmr1}YZ)+iLroI(`Gq*BX> zc>6MQ0`+r2)pRVonyd~XvG(p^EnIYpZq__$$wttsK#%b>yJh9*=)qNA7qozOQF?^ynP(Uh>lP2sgBR^IVZjl=zWy- zRR!+c#55HvuzLl|W#merivM$0*t1e2%crPk1)qw0cIj!QqWzV546|Q;#U1GTfp2Iq>OI?zFJ5$4zP{Ve`%{kQo%V^p88dAfgODrR zR;nTNJY?ka7cDmO814#eUBb_D=MmVn@;+>40=m^lS2Mqw*y?!Q!f~2+!FzrG?-0N7 zp$3oh+Mp(5=;gB>Y`|9ZaU`&f# zNuRaKXM(!{4UK3<2fc1Ui}K$S_z3+sB8e2XGfoGZ(2pHNw3BucMXsui5g#{+M4quHiIzpQl^KaIpnZgssU#AMNS1K~oU9=$Yx%LejwxDS!AVbuMI*NT z3QH%^_TxYWC&Ai5qIwV~ha!Aa+$HlB4>@73Iv3D&w2UX_gLEfHTRg!uMW-E`~r@%Z~lAd9d>LeYDVqWH& z6h>=eO_(4`W9|Pb=w~W-P@p?2qPB(_LAY-VEoDW>HrCS5-XnigWcgQ4RJOB2 z3QEwvJy1;E?SL~y-S^tnNbz$EPmi!qq{r!3EwlnS&rqYa@=F$3MRv+X-xhH D_sVhV literal 0 HcmV?d00001 From ab21028ead94ae8afe303731118d35904f81b236 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 25 Oct 2017 23:30:01 +0300 Subject: [PATCH 3/9] init commit --- Function/.gitignore | 49 +++++ Function/.idea/.name | 1 + Function/.idea/compiler.xml | 18 ++ Function/.idea/misc.xml | 13 ++ Function/.idea/modules.xml | 8 + Function/Function.iml | 22 +++ Function/pom.xml | 47 +++++ .../mit/kazakov/Function/Collections.java | 126 +++++++++++++ .../spbau/mit/kazakov/Function/Function1.java | 32 ++++ .../spbau/mit/kazakov/Function/Function2.java | 62 +++++++ .../spbau/mit/kazakov/Function/Predicate.java | 53 ++++++ .../mit/kazakov/Function/CollectionsTest.java | 167 ++++++++++++++++++ .../mit/kazakov/Function/Function1Test.java | 32 ++++ .../mit/kazakov/Function/Function2Test.java | 63 +++++++ .../mit/kazakov/Function/PredicateTest.java | 61 +++++++ 15 files changed, 754 insertions(+) create mode 100644 Function/.gitignore create mode 100644 Function/.idea/.name create mode 100644 Function/.idea/compiler.xml create mode 100644 Function/.idea/misc.xml create mode 100644 Function/.idea/modules.xml create mode 100644 Function/Function.iml create mode 100644 Function/pom.xml create mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java create mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java create mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java create mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java create mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java create mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java create mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java create mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java diff --git a/Function/.gitignore b/Function/.gitignore new file mode 100644 index 0000000..345e61a --- /dev/null +++ b/Function/.gitignore @@ -0,0 +1,49 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties diff --git a/Function/.idea/.name b/Function/.idea/.name new file mode 100644 index 0000000..1ff17c5 --- /dev/null +++ b/Function/.idea/.name @@ -0,0 +1 @@ +Function \ No newline at end of file diff --git a/Function/.idea/compiler.xml b/Function/.idea/compiler.xml new file mode 100644 index 0000000..8f81c05 --- /dev/null +++ b/Function/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Function/.idea/misc.xml b/Function/.idea/misc.xml new file mode 100644 index 0000000..c092288 --- /dev/null +++ b/Function/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/Function/.idea/modules.xml b/Function/.idea/modules.xml new file mode 100644 index 0000000..8962661 --- /dev/null +++ b/Function/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Function/Function.iml b/Function/Function.iml new file mode 100644 index 0000000..e6ccb8a --- /dev/null +++ b/Function/Function.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Function/pom.xml b/Function/pom.xml new file mode 100644 index 0000000..b49ba25 --- /dev/null +++ b/Function/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + ru.spbau.mit.kazakov + Function + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.8 + 1.8 + + + + + + + + junit + junit + 4.8 + + + org.jetbrains + annotations + 13.0 + + + com.google.guava + guava + 23.2-jre + + + + + UTF-8 + UTF-8 + + + \ No newline at end of file diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java new file mode 100644 index 0000000..e5eeaae --- /dev/null +++ b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java @@ -0,0 +1,126 @@ +package ru.spbau.mit.kazakov.Function; + + +import com.google.common.collect.Lists; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +/** + * Class providing methods for working with collections using functions. + */ +public class Collections { + /** + * Applies specified function to specified container's elements and adds mapped elements in new list. + * + * @param function specified function + * @param elements specified container + * @param type of elements in specified container + * @param type of elements in result list + * @return result list + */ + static public List map(@NotNull final Function1 function, @NotNull final Iterable elements) { + List resultList = new ArrayList<>(); + + for (T element : elements) { + resultList.add(function.apply(element)); + } + + return resultList; + } + + /** + * Creates new list composed of elements from specified container that satisfy specified predicate. + * + * @param predicate specified predicate + * @param elements specified container + * @param type of elements in specified container + * @return result list + */ + static public List filter(@NotNull final Predicate predicate, @NotNull final Iterable elements) { + List resultList = new ArrayList<>(); + + for (T element : elements) { + if (predicate.apply(element)) { + resultList.add(element); + } + } + + return resultList; + } + + /** + * Creates new list by adding elements from specified container while they satisfy specified predicate. + * + * @param predicate specified predicate + * @param elements specified container + * @param type of elements in specified container + * @return result list + */ + static public List takeWhile(@NotNull final Predicate predicate, @NotNull final Iterable elements) { + List resultList = new ArrayList<>(); + + for (T element : elements) { + if (!predicate.apply(element)) { + break; + } + resultList.add(element); + } + + return resultList; + } + + /** + * Creates new list by adding elements from specified container unless they satisfy specified predicate. + * + * @param predicate specified predicate + * @param elements specified container + * @param type of elements in specified container + * @return result list + */ + static public List takeUnless(@NotNull final Predicate predicate, @NotNull final Iterable elements) { + return takeWhile(predicate.not(), elements); + } + + /** + * Left-associative fold of specified collection. Reduces the list using specified function from left to right. + * + * @param function specified function + * @param startValue first value for function's first element + * @param elements specified collection + * @param type of elements in specified collection + * @param specified function's codomain + * @return result value + */ + static public U foldl(@NotNull final Function2 function, + U startValue, @NotNull final Collection elements) { + U resultValue = startValue; + + for (T element : elements) { + resultValue = function.apply(resultValue, element); + } + + return resultValue; + } + + /** + * Right-associative fold of specified collection. Reduces the list using specified function from right to left. + * + * @param function specified function + * @param startValue first value for function's second element + * @param elements specified collection + * @param type of elements in specified collection + * @param specified function's codomain + * @return result value + */ + static public U foldr(@NotNull final Function2 function, + final U startValue, @NotNull final Collection elements) { + U resultValue = startValue; + + for (T element : Lists.reverse(new ArrayList<>(elements))) { + resultValue = function.apply(element, resultValue); + } + + return resultValue; + } +} diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java new file mode 100644 index 0000000..9bbfe30 --- /dev/null +++ b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java @@ -0,0 +1,32 @@ +package ru.spbau.mit.kazakov.Function; + + +import org.jetbrains.annotations.NotNull; + +/** + * The interface for representing a function with one argument. + * + * @param domain's type + * @param codomain's type + */ +@FunctionalInterface +public interface Function1 { + /** + * Applies function to specified argument. + * + * @param argument for applying to + * @return mapped value + */ + U apply(T argument); + + /** + * Creates composition of functions. + * + * @param function for composition + * @param specified function's codomain's type + * @return result of function composition + */ + default Function1 compose(@NotNull final Function1 function) { + return argument -> function.apply(apply(argument)); + } +} diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java new file mode 100644 index 0000000..3532a7b --- /dev/null +++ b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java @@ -0,0 +1,62 @@ +package ru.spbau.mit.kazakov.Function; + + +import org.jetbrains.annotations.NotNull; + +/** + * The interface for representing a function with two arguments. + * + * @param first argument's type + * @param second argument's type + * @param codomain's type + */ +@FunctionalInterface +public interface Function2 { + /** + * Applies function to specified argument. + * + * @param firstArgument for applying to + * @param secondArgument for applying to + * @return mapped value + */ + K apply(T firstArgument, U secondArgument); + + /** + * Creates composition of functions. + * + * @param specified function's codomain's type + * @return result of function composition + */ + default Function2 compose(@NotNull final Function1 function) { + return (firstArgument, secondArgument) -> function.apply(apply(firstArgument, secondArgument)); + } + + /** + * Binds first argument to specified value. + * + * @param firstArgument specified value + * @return function of one argument + */ + default Function1 bind1(T firstArgument) { + return secondArgument -> apply(firstArgument, secondArgument); + } + + /** + * Binds second argument to specified value. + * + * @param secondArgument specified value + * @return function of one argument + */ + default Function1 bind2(U secondArgument) { + return firstArgument -> apply(firstArgument, secondArgument); + } + + /** + * Converts current function with two arguments into two functions with one argument. + * + * @return new function with one argument + */ + default Function1> curry() { + return this::bind1; + } +} \ No newline at end of file diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java new file mode 100644 index 0000000..2a4c177 --- /dev/null +++ b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java @@ -0,0 +1,53 @@ +package ru.spbau.mit.kazakov.Function; + + +import org.jetbrains.annotations.NotNull; + +/** + * The interface for representing a predicate with one argument. + * + * @param domain's type + */ +@FunctionalInterface +public interface Predicate extends Function1 { + /** + * Predicate always returning true. + */ + Predicate ALWAYS_TRUE = argument -> true; + + /** + * Predicate always returning false. + */ + Predicate ALWAYS_FALSE = ALWAYS_TRUE.not(); + + /** + * Makes new predicate with two argument composed of logical OR of current and specified predicates. + * + * @param predicate a specified predicate + * @param specified predicate's argument's type + * @return new predicate with two variables + */ + default Function2 or(@NotNull final Predicate predicate) { + return (firstArgument, secondArgument) -> Predicate.this.apply(firstArgument) || predicate.apply(secondArgument); + } + + /** + * Makes new predicate with two argument composed of logical AND of current and specified predicates. + * + * @param predicate a specified predicate + * @param specified predicate's argument's type + * @return new predicate with two variables + */ + default Function2 and(@NotNull final Predicate predicate) { + return (firstArgument, secondArgument) -> Predicate.this.apply(firstArgument) && predicate.apply(secondArgument); + } + + /** + * Makes new predicate composed of logical NOT of current predicate. + * + * @return new predicate + */ + default Predicate not() { + return argument -> !apply(argument); + } +} diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java new file mode 100644 index 0000000..8a9a311 --- /dev/null +++ b/Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java @@ -0,0 +1,167 @@ +package ru.spbau.mit.kazakov.Function; + + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + + +import static java.util.Arrays.asList; +import static org.junit.Assert.*; + +public class CollectionsTest { + @Test + public void testMapEmpty() { + Function1 function = argument -> argument * argument; + List list = new ArrayList<>(); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.map(function, list)); + } + + @Test + public void testMap() { + Function1 function = argument -> argument * argument; + List list = asList(-2, -1, 0, 4, 10); + List expected = asList(4, 1, 0, 16, 100); + + assertEquals(expected, Collections.map(function, list)); + } + + @Test + public void testFilterEmptyInput() { + Predicate function = argument -> Math.abs(argument) > 10; + List list = new ArrayList<>(); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.filter(function, list)); + } + + @Test + public void testFilterEmptyOutput() { + Predicate function = argument -> Math.abs(argument) == 1; + List list = asList(10, 3, -10, -99, 0, -23, 1001); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.filter(function, list)); + } + + @Test + public void testFilterAllListOutput() { + Predicate function = argument -> Math.abs(argument) != 1010; + List list = asList(10, 3, -10, -99, 0, -23, 1001); + List expected = asList(10, 3, -10, -99, 0, -23, 1001); + + assertEquals(expected, Collections.filter(function, list)); + } + + @Test + public void testFilter() { + Predicate function = argument -> Math.abs(argument) > 10; + List list = asList(10, 3, -10, -99, 0, -23, 1001); + List expected = asList(-99, -23, 1001); + + assertEquals(expected, Collections.filter(function, list)); + } + + @Test + public void testTakeWhileEmptyInput() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = new ArrayList<>(); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.takeWhile(function, list)); + } + + @Test + public void testTakeWhileEmptyOutput() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = asList(1, -77, 77, 77, 0, 77, -77, 198); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.takeWhile(function, list)); + } + + @Test + public void testTakeWhileAllListOutput() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = asList(-77, 77, 77, 77, -77); + List expected = asList(-77, 77, 77, 77, -77); + + assertEquals(expected, Collections.takeWhile(function, list)); + } + + @Test + public void testTakeWhile() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = asList(-77, 77, 77, 0, 77, -77, 198); + List expected = asList(-77, 77, 77); + + assertEquals(expected, Collections.takeWhile(function, list)); + } + + @Test + public void testTakeUnlessEmptyInput() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = new ArrayList<>(); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.takeUnless(function, list)); + } + + @Test + public void testTakeUnlessEmptyOutput() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = asList(-77, 77, 77, 0, 77, -77, 198); + List expected = new ArrayList<>(); + + assertEquals(expected, Collections.takeUnless(function, list)); + } + + @Test + public void testTakeUnlessAllListOutput() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = asList(0, 1, -99, 121, 89898, 32423); + List expected = asList(0, 1, -99, 121, 89898, 32423); + + assertEquals(expected, Collections.takeUnless(function, list)); + } + + @Test + public void testTakeUnless() { + Predicate function = argument -> Math.abs(argument) == 77; + List list = asList(0, 1, -99, 121, -77, 89898, 77, 32423); + List expected = asList(0, 1, -99, 121); + + assertEquals(expected, Collections.takeUnless(function, list)); + } + + @Test + public void testFoldlEmpty() { + Function2 function = (firstArgument, secondArgument) -> secondArgument / firstArgument; + List list = new ArrayList<>(); + assertEquals(1, (int) Collections.foldl(function, 1, list)); + } + + @Test + public void testFoldl() { + Function2 function = (firstArgument, secondArgument) -> secondArgument / firstArgument; + List list = asList(10, 20, 100); + assertEquals(50, (int) Collections.foldl(function, 1, list)); + } + + @Test + public void testFoldrEmpty() { + Function2 function = (firstArgument, secondArgument) -> firstArgument / secondArgument; + List list = new ArrayList<>(); + assertEquals(1, (int) Collections.foldr(function, 1, list)); + } + + @Test + public void testFoldr() { + Function2 function = (firstArgument, secondArgument) -> firstArgument / secondArgument; + List list = asList(100, 20, 10); + assertEquals(50, (int) Collections.foldr(function, 1, list)); + } +} \ No newline at end of file diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java new file mode 100644 index 0000000..3862672 --- /dev/null +++ b/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java @@ -0,0 +1,32 @@ +package ru.spbau.mit.kazakov.Function; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class Function1Test { + @Test + public void testConstructor() { + new Function1() { + @Override + public Double apply(Integer argument) { + return argument / 2.0; + } + }; + } + + @Test + public void testApply() { + Function1 function = argument -> argument * 2; + assertEquals(new Integer(10), function.apply(5)); + } + + @Test + public void compose() { + Function1 someFunction = argument -> (long) (argument / 5); + Function1 anotherFunction = Object::toString; + Function1 composition = someFunction.compose(anotherFunction); + assertEquals("6", composition.apply(30)); + } + +} \ No newline at end of file diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java new file mode 100644 index 0000000..a3d9e30 --- /dev/null +++ b/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java @@ -0,0 +1,63 @@ +package ru.spbau.mit.kazakov.Function; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class Function2Test { + @Test + public void testConstructor() { + new Function2() { + @Override + public Double apply(Long firstArgument, Integer secondArgument) { + return (firstArgument * secondArgument) / 5.0; + } + }; + } + + @Test + public void testApply() { + Function2 function = + (firstArgument, secondArgument) -> firstArgument.toString() + secondArgument.toString(); + assertEquals("8j", function.apply((byte) 8, 'j')); + } + + @Test + public void testCompose() { + Function2 someFunction = Integer::equals; + Function1 anotherFunction = argument -> { + if (argument) { + return (byte) 1; + } else { + return (byte) 0; + } + }; + Function2 composition = someFunction.compose(anotherFunction); + assertEquals(1, (byte) composition.apply(979, 979)); + } + + @Test + public void bind1() { + Function2 someFunction = + (firstArgument, secondArgument) -> (int) Math.pow(firstArgument, secondArgument); + Function1 anotherFunction = someFunction.bind1(2); + assertEquals(32, (int) anotherFunction.apply(5)); + } + + @Test + public void bind2() { + Function2 someFunction = + (firstArgument, secondArgument) -> (int) Math.pow(firstArgument, secondArgument); + Function1 anotherFunction = someFunction.bind2(3); + assertEquals(64, (int) anotherFunction.apply(4)); + } + + @Test + public void curry() { + Function2 function = + (firstArgument, secondArgument) -> Math.abs(firstArgument) + Math.abs(secondArgument); + Function1> curried = function.curry(); + assertEquals(46, (int) curried.apply(-44).apply(2)); + } + +} \ No newline at end of file diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java new file mode 100644 index 0000000..e354a30 --- /dev/null +++ b/Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java @@ -0,0 +1,61 @@ +package ru.spbau.mit.kazakov.Function; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PredicateTest { + @Test + public void testConstructor() { + new Predicate(){ + @Override + public Boolean apply(Double argument) { + return argument > 7; + } + }; + } + + @Test + public void testALWAYS_TRUE() { + assertTrue((boolean) Predicate.ALWAYS_TRUE.apply(new Object())); + } + + @Test + public void testALWAYS_FALSE() { + assertFalse((boolean) Predicate.ALWAYS_FALSE.apply(new Object())); + } + + @Test + public void testOr() { + Predicate somePredicate = argument -> argument; + Predicate anotherPredicate = argument -> argument >= 111; + Function2 or = somePredicate.or(anotherPredicate); + + assertFalse(or.apply(false, 1)); + assertTrue(or.apply(true, 110)); + assertTrue(or.apply(false, 111)); + assertTrue(or.apply(true, 1000)); + } + + @Test + public void testAnd() { + Predicate somePredicate = argument -> argument; + Predicate anotherPredicate = argument -> argument >= 111; + Function2 and = somePredicate.and(anotherPredicate); + + assertFalse(and.apply(false, 1)); + assertFalse(and.apply(true, 110)); + assertFalse(and.apply(false, 111)); + assertTrue(and.apply(true, 1000)); + } + + @Test + public void testNot() { + Predicate predicate = argument -> argument.equals("Math is painful"); + Predicate not = predicate.not(); + + assertTrue(not.apply("Math is wonderful")); + assertFalse(not.apply("Math is painful")); + } + +} \ No newline at end of file From 00de53bd8becadce62571db000232b5fe0aa2d01 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 25 Oct 2017 23:32:15 +0300 Subject: [PATCH 4/9] deleted extra files --- Untitled Folder 2/Java/.gitignore | 49 ----------- Untitled Folder 2/Java/.idea/compiler.xml | 16 ---- Untitled Folder 2/Java/.idea/misc.xml | 13 --- Untitled Folder 2/Java/.idea/modules.xml | 8 -- Untitled Folder 2/Java/Maybe.iml | 17 ---- Untitled Folder 2/Java/pom.xml | 36 -------- .../java/ru/spbau/mit/kazakov/Maybe/Main.java | 63 ------------- .../ru/spbau/mit/kazakov/Maybe/Maybe.java | 83 ------------------ .../kazakov/Maybe/getNothingException.java | 7 -- .../ru/spbau/mit/kazakov/Maybe/MainTest.java | 47 ---------- .../ru/spbau/mit/kazakov/Maybe/MaybeTest.java | 60 ------------- .../ru/spbau/mit/kazakov/Maybe/Main.class | Bin 3978 -> 0 bytes .../ru/spbau/mit/kazakov/Maybe/Maybe.class | Bin 2100 -> 0 bytes .../kazakov/Maybe/getNothingException.class | Bin 339 -> 0 bytes .../compile/default-compile/createdFiles.lst | 3 - .../compile/default-compile/inputFiles.lst | 3 - .../default-testCompile/createdFiles.lst | 2 - .../default-testCompile/inputFiles.lst | 2 - ...ST-ru.spbau.mit.kazakov.Maybe.MainTest.xml | 64 -------------- ...T-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml | 70 --------------- .../ru.spbau.mit.kazakov.Maybe.MainTest.txt | 4 - .../ru.spbau.mit.kazakov.Maybe.MaybeTest.txt | 4 - .../ru/spbau/mit/kazakov/Maybe/MainTest.class | Bin 2225 -> 0 bytes .../spbau/mit/kazakov/Maybe/MaybeTest.class | Bin 3912 -> 0 bytes kek2/Java | 1 - 25 files changed, 552 deletions(-) delete mode 100644 Untitled Folder 2/Java/.gitignore delete mode 100644 Untitled Folder 2/Java/.idea/compiler.xml delete mode 100644 Untitled Folder 2/Java/.idea/misc.xml delete mode 100644 Untitled Folder 2/Java/.idea/modules.xml delete mode 100644 Untitled Folder 2/Java/Maybe.iml delete mode 100644 Untitled Folder 2/Java/pom.xml delete mode 100644 Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java delete mode 100644 Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java delete mode 100644 Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java delete mode 100644 Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java delete mode 100644 Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java delete mode 100644 Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Main.class delete mode 100644 Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Maybe.class delete mode 100644 Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/getNothingException.class delete mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst delete mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst delete mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst delete mode 100644 Untitled Folder 2/Java/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst delete mode 100644 Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MainTest.xml delete mode 100644 Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml delete mode 100644 Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt delete mode 100644 Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt delete mode 100644 Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MainTest.class delete mode 100644 Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MaybeTest.class delete mode 160000 kek2/Java diff --git a/Untitled Folder 2/Java/.gitignore b/Untitled Folder 2/Java/.gitignore deleted file mode 100644 index 345e61a..0000000 --- a/Untitled Folder 2/Java/.gitignore +++ /dev/null @@ -1,49 +0,0 @@ -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties diff --git a/Untitled Folder 2/Java/.idea/compiler.xml b/Untitled Folder 2/Java/.idea/compiler.xml deleted file mode 100644 index 067d5ff..0000000 --- a/Untitled Folder 2/Java/.idea/compiler.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/.idea/misc.xml b/Untitled Folder 2/Java/.idea/misc.xml deleted file mode 100644 index e8942bd..0000000 --- a/Untitled Folder 2/Java/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/.idea/modules.xml b/Untitled Folder 2/Java/.idea/modules.xml deleted file mode 100644 index 65c89bb..0000000 --- a/Untitled Folder 2/Java/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/Maybe.iml b/Untitled Folder 2/Java/Maybe.iml deleted file mode 100644 index 57f498f..0000000 --- a/Untitled Folder 2/Java/Maybe.iml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/pom.xml b/Untitled Folder 2/Java/pom.xml deleted file mode 100644 index fe36c91..0000000 --- a/Untitled Folder 2/Java/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - ru.spbau.mit.kazakov.Maybe - Maybe - 1.0-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - - - - junit - junit - 4.8 - - - org.jetbrains - annotations - 13.0 - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java deleted file mode 100644 index 8bd1447..0000000 --- a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Main.java +++ /dev/null @@ -1,63 +0,0 @@ -package ru.spbau.mit.kazakov.Maybe; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.*; -import java.util.ArrayList; -import java.util.Scanner; - -/** - * Reads numbers from input file and writes squared values to output file. If read data isn't a number writes "null" instead. - */ -public class Main { - /** - * Primary method. - * - * @param args the first argument is input file and the second one is output file - */ - public static void main(@NotNull String[] args) throws IOException, getNothingException { - ArrayList> readData = new ArrayList<>(); - try (Scanner scanner = new Scanner(new File(args[0]))) { - while (scanner.hasNextLine()) { - Integer value = tryParse(scanner.nextLine()); - if (value == null) { - readData.add(Maybe.nothing()); - } else { - readData.add(Maybe.just(value)); - } - } - } - - ArrayList> squaredNumber = new ArrayList<>(); - for (Maybe maybeInt : readData) { - squaredNumber.add(maybeInt.map(value -> value * value)); - } - - try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(args[1]))) { - for (Maybe maybeInt : squaredNumber) { - if (maybeInt.isPresent()) { - bufferedWriter.write(maybeInt.get().toString()); - } else { - bufferedWriter.write("null"); - } - bufferedWriter.newLine(); - } - } - } - - /** - * Parses specified String to Integer. - * - * @return Integer if String was a number, and null otherwise - */ - @Nullable - private static Integer tryParse(@NotNull String parsingString) { - try { - return Integer.parseInt(parsingString); - } catch (NumberFormatException e) { - return null; - } - } - -} diff --git a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java deleted file mode 100644 index b0216f4..0000000 --- a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/Maybe.java +++ /dev/null @@ -1,83 +0,0 @@ -package ru.spbau.mit.kazakov.Maybe; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.function.Function; - -/** - * Generic container for storing a value or nothing. - */ -public class Maybe { - @Nullable - private final T value; - - /** - * Assigns specified value to class's storing field. - * - * @param t specified value - */ - private Maybe(T t) { - value = t; - } - - /** - * Creates an object for storing specified value. - * - * @param t specified value - * @return new object - */ - @NotNull - public static Maybe just(T t) { - return new Maybe(t); - } - - /** - * Creates an object for strong nothing. - * - * @return new object - */ - @NotNull - public static Maybe nothing() { - return new Maybe(null); - } - - /** - * Returns stored value or throws exception if there is no value. - * - * @return stored value - * @throws getNothingException if there is no stored value - */ - @NotNull - public T get() throws getNothingException { - if (isPresent()) { - return value; - } else { - throw new getNothingException(); - } - } - - /** - * Checks if there is stored value. - * - * @return true if there is stored value, and false otherwise - */ - public boolean isPresent() { - return value != null; - } - - /** - * Maps stored value of type T to another value of type U. - * - * @param mapper a function acting from T to V - * @param image's type - * @return Maybe object storing mapped value if there is a storing value, and Maybe object storing nothing otherwise - */ - @NotNull - public Maybe map(@NotNull Function mapper) { - if (!isPresent()) { - return nothing(); - } - return just(mapper.apply(value)); - } -} diff --git a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java b/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java deleted file mode 100644 index 7789bf9..0000000 --- a/Untitled Folder 2/Java/src/main/java/ru/spbau/mit/kazakov/Maybe/getNothingException.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.spbau.mit.kazakov.Maybe; - -/** - * Exception thrown when there is no value to return. - */ -public class getNothingException extends Exception { -} diff --git a/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java b/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java deleted file mode 100644 index 90c6fe1..0000000 --- a/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MainTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package ru.spbau.mit.kazakov.Maybe; - -import org.junit.Test; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Scanner; - -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; - -import static org.junit.Assert.*; - -public class MainTest { - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - - @Test - public void testMain() throws IOException, getNothingException { - File input = testFolder.newFile("input.txt"); - File output = testFolder.newFile("output.txt"); - - try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(input))) { - bufferedWriter.write("1\n0\n-3\nj\njava\n1b\n11 22\n"); - } - - Main.main(new String[]{input.getAbsolutePath(), output.getAbsolutePath()}); - - - assertEquals("1\n0\n9\nnull\nnull\nnull\nnull\n", new String(Files.readAllBytes(Paths.get(output.getAbsolutePath())))); - } - - @Test - public void testMainEmpty() throws IOException, getNothingException { - File input = testFolder.newFile("input.txt"); - File output = testFolder.newFile("output.txt"); - - Main.main(new String[]{input.getAbsolutePath(), output.getAbsolutePath()}); - - assertEquals("", new String(Files.readAllBytes(Paths.get(output.getAbsolutePath())))); - } - -} \ No newline at end of file diff --git a/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java b/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java deleted file mode 100644 index 54b7846..0000000 --- a/Untitled Folder 2/Java/src/test/java/ru/spbau/mit/kazakov/Maybe/MaybeTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package ru.spbau.mit.kazakov.Maybe; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class MaybeTest { - @Test - public void testJustInteger() throws getNothingException { - Maybe maybeInteger = Maybe.just(5); - int storedValue = maybeInteger.get(); - assertEquals(5, storedValue); - } - - @Test - public void testNothingBoolean() { - Maybe maybeBoolean = Maybe.nothing(); - assertFalse(maybeBoolean.isPresent()); - } - - @Test - public void testGetDouble() throws getNothingException { - Maybe maybeDouble = Maybe.just(-7.0); - double storedValue = maybeDouble.get(); - assertEquals(-7.0, storedValue, 0.000000001); - } - - @Test(expected = getNothingException.class) - public void testGetCharacterThrowsException() throws getNothingException { - Maybe maybeCharacter = Maybe.nothing(); - char storedValue = maybeCharacter.get(); - } - - @Test - public void testIsPresentFalse() { - Maybe maybeBoolean = Maybe.nothing(); - assertFalse(maybeBoolean.isPresent()); - } - - @Test - public void testIsPresentTrue() { - Maybe maybeString = Maybe.just("abacaba"); - assertTrue(maybeString.isPresent()); - } - - @Test - public void testMapJust() throws getNothingException { - Maybe maybeInteger = Maybe.just(10); - Maybe mappedMaybeInteger = maybeInteger.map(value -> value * value); - int mappedValue = mappedMaybeInteger.get(); - assertEquals(100, mappedValue); - } - - @Test - public void testMapNothing() throws getNothingException { - Maybe maybeInteger = Maybe.nothing(); - Maybe mappedMaybeInteger = maybeInteger.map(value -> value * value); - assertFalse(mappedMaybeInteger.isPresent()); - } -} \ No newline at end of file diff --git a/Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Main.class b/Untitled Folder 2/Java/target/classes/ru/spbau/mit/kazakov/Maybe/Main.class deleted file mode 100644 index 6bafd51dadac3eb34fc19d52644fad85854c4d65..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3978 zcmbVP>sMS?75^QWnL7-Zgg~Gf@&ZBpE!L{;-q^kyh``#J27#3#v;hx7n`|Q{G?S0Pu z+x=Uw19&@LkD(Rs*YHdXWzv5@!v|vs!-ye-QEA4c8IR#0%ow&~LKr7yG$jj`hUpl# zVn)d6N@S3g#@3Llp@LaqysF`vhPfDah}cK)tPr1*=6MYtieWcCEaVrWcv1R~NMi~4 zqtd*j;bYQ&T*D_cd{QBD+{#++35D|3wu=g(K6~6$*qXGmW~z`GHJuB_XquFoq&;S& zFB*;|^CB_iPFZ<{rleCyqlC29^i1t~qHs+^yxujBM6)R@V!zl}-%%M6O3OqKo_r z&6^uTHu7&7Elf<9jyZnGv0M?m!&htBiBs!V#B#%#q?5H97*55GX^fvXTtlJG7vWjf z>o~?-(#pHsUzNX7FsRB8CquA4l5@FIG>`pH%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_Zj!q5V5X+C#KIzKDjDA{+O2hvVU*grhPliin8Ho!3$4>E87Q zb}wMh0`|_MqO+!vgU$ss&9B^{o#*1AJE-Tpc^;=JE))-Y);{i&j)(?27rx!Ck$Z1| zyS6(@?x^pZaL2XVHxa{=crTvfkHanuV7k~lJfY|DB3|Nr8ZJ0jZK_ip=KQW|RDH!h zN%|#qSv`ZTs!yd9=LCkF{4^TaZby`n*@b%SY&a? z@itn}famy2^%zmOKueF}7-{#=;*BEs7vCk1;~hjFF^6vSaDP-y)2??Cqp#o}IKfdF z-bH#lclt6;uF5z`y!!mTtNgv>KSlmm(QqHTH1ugWt>MgD*sG!cO;nVnIE(eOc{jfm zR3oB+!y+F@gc6qW6-p}e*MNUR_jt~}iT(G{pn-+&jE1vsA)(XgBG#=t0Chs{vKXI9~GSVvBm#}XMEjNHB7(JbYj0uCNix)&)ysRWa8E@c)h=8kARw24ew90+!WXCv=Oj45>O8h7K z2Ym4XtGw-6wfp9SKg#laGZP>XiBOsD{=V*W&Ufkl`t9HU09?WES@dHvgCwR5T+MR4 zCZFpDZe)?hq%5ZUQN&G|%^0|)(6_2GO0_%jLzb30k{j}=n48-J5>aKUly#h_lcy^)4p`pE)EywcrI- zt6A28Rd;-AMZeH1jaBQuUMt(tm(Wfx~8Y8@@sMA{EDo!E6vyc<*pj95bJhd_wNjIu{YG2n9w% zIy2f7k{~46vH+%_@nLwZF_iKB=a5EWlwq+TPHd=nnujA?!g`@jx%v9#Iykm#Qk#BrR9!+jAq z#IS_>3dSewSsxd+e~?Mw6S7jMtuZe$<_GM%KSI{1KZavguyE%wL4wWx5MR_E;>X@eR - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml b/Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml deleted file mode 100644 index 8af6efe..0000000 --- a/Untitled Folder 2/Java/target/surefire-reports/TEST-ru.spbau.mit.kazakov.Maybe.MaybeTest.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt b/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt deleted file mode 100644 index adbb610..0000000 --- a/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MainTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: ru.spbau.mit.kazakov.Maybe.MainTest -------------------------------------------------------------------------------- -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.056 sec - in ru.spbau.mit.kazakov.Maybe.MainTest diff --git a/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt b/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt deleted file mode 100644 index 15d544e..0000000 --- a/Untitled Folder 2/Java/target/surefire-reports/ru.spbau.mit.kazakov.Maybe.MaybeTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: ru.spbau.mit.kazakov.Maybe.MaybeTest -------------------------------------------------------------------------------- -Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.07 sec - in ru.spbau.mit.kazakov.Maybe.MaybeTest diff --git a/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MainTest.class b/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MainTest.class deleted file mode 100644 index 3f48d60837c6182b50031c73aeaf1e02f1a8ebe6..0000000000000000000000000000000000000000 GIT bin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Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MaybeTest.class b/Untitled Folder 2/Java/target/test-classes/ru/spbau/mit/kazakov/Maybe/MaybeTest.class deleted file mode 100644 index fe9ccbf84598e037745c1e9f962681c7c236ddc4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3912 zcmb7HX;;){6nIA23#v>5l37`TkD3>D!5<=wMuDg?Gk1p1cqcxGAP#8Zg$^W zyV)PnexV#c^!T}_pZgp7D|-68Z!(#gf+(CbN#5n&`@GM6?oIgf-+O-m*oR* z{e4I7c{PUDG<4$iMi_EDk)XwtbYYcT=MoT@ieV;(yg;}+9iVZtb;XDvTHW85%ioVoO< zF+X7j*D=%c2k6%4{Y=sGM{M7mG+hCGR&I)hTOR6(UYb4Man0PgkuMUM7!l~I1~*?Q z0X*PvcBn#O}WlBFJeQWRRxRInSmjJL#v7x8LNTnm?*{ch~Ui4jN za<#k$R?2m=bUkVmr1}YZ)+iLroI(`Gq*BX> zc>6MQ0`+r2)pRVonyd~XvG(p^EnIYpZq__$$wttsK#%b>yJh9*=)qNA7qozOQF?^ynP(Uh>lP2sgBR^IVZjl=zWy- zRR!+c#55HvuzLl|W#merivM$0*t1e2%crPk1)qw0cIj!QqWzV546|Q;#U1GTfp2Iq>OI?zFJ5$4zP{Ve`%{kQo%V^p88dAfgODrR zR;nTNJY?ka7cDmO814#eUBb_D=MmVn@;+>40=m^lS2Mqw*y?!Q!f~2+!FzrG?-0N7 zp$3oh+Mp(5=;gB>Y`|9ZaU`&f# zNuRaKXM(!{4UK3<2fc1Ui}K$S_z3+sB8e2XGfoGZ(2pHNw3BucMXsui5g#{+M4quHiIzpQl^KaIpnZgssU#AMNS1K~oU9=$Yx%LejwxDS!AVbuMI*NT z3QH%^_TxYWC&Ai5qIwV~ha!Aa+$HlB4>@73Iv3D&w2UX_gLEfHTRg!uMW-E`~r@%Z~lAd9d>LeYDVqWH& z6h>=eO_(4`W9|Pb=w~W-P@p?2qPB(_LAY-VEoDW>HrCS5-XnigWcgQ4RJOB2 z3QEwvJy1;E?SL~y-S^tnNbz$EPmi!qq{r!3EwlnS&rqYa@=F$3MRv+X-xhH D_sVhV diff --git a/kek2/Java b/kek2/Java deleted file mode 160000 index d207fbc..0000000 --- a/kek2/Java +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d207fbc8f6316ee94011c17d43e488e48f2e61eb From 0ee8ee6865bd5116548e5d128656cfa829a61db7 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 14 Nov 2017 06:31:54 +0300 Subject: [PATCH 5/9] Initial commit. --- MyTreeSet/.gitignore | 49 ++ MyTreeSet/.idea/compiler.xml | 16 + MyTreeSet/.idea/misc.xml | 13 + MyTreeSet/.idea/modules.xml | 8 + MyTreeSet/MyTreeSet.iml | 17 + MyTreeSet/pom.xml | 36 ++ MyTreeSet/src/main/java/HisTreeSet.java | 33 ++ MyTreeSet/src/main/java/MyTreeSet.java | 457 ++++++++++++++++++ MyTreeSet/src/test/java/MyTreeSetTest.java | 414 ++++++++++++++++ MyTreeSet/target/classes/HisTreeSet.class | Bin 0 -> 597 bytes MyTreeSet/target/classes/MyTreeSet$1.class | Bin 0 -> 175 bytes .../classes/MyTreeSet$MyTreeSetIterator.class | Bin 0 -> 1308 bytes MyTreeSet/target/classes/MyTreeSet$Node.class | Bin 0 -> 2033 bytes MyTreeSet/target/classes/MyTreeSet.class | Bin 0 -> 9176 bytes .../target/test-classes/MyTreeSetTest.class | Bin 0 -> 13660 bytes 15 files changed, 1043 insertions(+) create mode 100644 MyTreeSet/.gitignore create mode 100644 MyTreeSet/.idea/compiler.xml create mode 100644 MyTreeSet/.idea/misc.xml create mode 100644 MyTreeSet/.idea/modules.xml create mode 100644 MyTreeSet/MyTreeSet.iml create mode 100644 MyTreeSet/pom.xml create mode 100644 MyTreeSet/src/main/java/HisTreeSet.java create mode 100644 MyTreeSet/src/main/java/MyTreeSet.java create mode 100644 MyTreeSet/src/test/java/MyTreeSetTest.java create mode 100644 MyTreeSet/target/classes/HisTreeSet.class create mode 100644 MyTreeSet/target/classes/MyTreeSet$1.class create mode 100644 MyTreeSet/target/classes/MyTreeSet$MyTreeSetIterator.class create mode 100644 MyTreeSet/target/classes/MyTreeSet$Node.class create mode 100644 MyTreeSet/target/classes/MyTreeSet.class create mode 100644 MyTreeSet/target/test-classes/MyTreeSetTest.class diff --git a/MyTreeSet/.gitignore b/MyTreeSet/.gitignore new file mode 100644 index 0000000..345e61a --- /dev/null +++ b/MyTreeSet/.gitignore @@ -0,0 +1,49 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties diff --git a/MyTreeSet/.idea/compiler.xml b/MyTreeSet/.idea/compiler.xml new file mode 100644 index 0000000..efede30 --- /dev/null +++ b/MyTreeSet/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyTreeSet/.idea/misc.xml b/MyTreeSet/.idea/misc.xml new file mode 100644 index 0000000..e8942bd --- /dev/null +++ b/MyTreeSet/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/MyTreeSet/.idea/modules.xml b/MyTreeSet/.idea/modules.xml new file mode 100644 index 0000000..0f5d373 --- /dev/null +++ b/MyTreeSet/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/MyTreeSet/MyTreeSet.iml b/MyTreeSet/MyTreeSet.iml new file mode 100644 index 0000000..57f498f --- /dev/null +++ b/MyTreeSet/MyTreeSet.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyTreeSet/pom.xml b/MyTreeSet/pom.xml new file mode 100644 index 0000000..00d906d --- /dev/null +++ b/MyTreeSet/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + ru,spbau.mit.kazakov.MyTreeSet + MyTreeSet + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + junit + junit + 4.8 + + + org.jetbrains + annotations + 13.0 + + + + \ No newline at end of file diff --git a/MyTreeSet/src/main/java/HisTreeSet.java b/MyTreeSet/src/main/java/HisTreeSet.java new file mode 100644 index 0000000..4eff59b --- /dev/null +++ b/MyTreeSet/src/main/java/HisTreeSet.java @@ -0,0 +1,33 @@ +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +public interface HisTreeSet extends Set { + + /** {@link TreeSet#descendingIterator()} **/ + Iterator descendingIterator(); + + /** {@link TreeSet#descendingSet()} **/ + HisTreeSet descendingSet(); + + + /** {@link TreeSet#first()} **/ + E first(); + + /** {@link TreeSet#last()} **/ + E last(); + + + /** {@link TreeSet#lower(E)} **/ + E lower(E e); + + /** {@link TreeSet#floor(E)} **/ + E floor(E e); + + + /** {@link TreeSet#ceiling(E)} **/ + E ceiling(E e); + + /** {@link TreeSet#higher(E)} **/ + E higher(E e); +} diff --git a/MyTreeSet/src/main/java/MyTreeSet.java b/MyTreeSet/src/main/java/MyTreeSet.java new file mode 100644 index 0000000..74326ea --- /dev/null +++ b/MyTreeSet/src/main/java/MyTreeSet.java @@ -0,0 +1,457 @@ +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.AbstractSet; +import java.util.Comparator; +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * A generic set implemented using binary search tree. + * + * @param type of stored value + */ +public class MyTreeSet extends AbstractSet implements HisTreeSet { + private Comparator comparator; + private int size = 0; + private Node root = null; + private boolean reverse = false; + + /** + * Makes new myTreeSet containing values from specified myTreeSet, but with reversed order view of the values. + * + * @param originalSet specified myTreeSet + */ + private MyTreeSet(MyTreeSet originalSet) { + root = originalSet.root; + size = originalSet.size; + comparator = originalSet.comparator; + reverse = !originalSet.reverse; + } + + /** + * Returns Node storing specified value. + * + * @param value specified value + * @return found Node if there is such Node, and null otherwise. + */ + @Nullable + private Node find(@NotNull E value) { + Node current = root; + + while (current != null) { + int compareResult = comparator.compare(current.value, value); + if (compareResult == 0) { + return current; + } else if (compareResult > 0) { + current = current.left; + } else { + current = current.right; + } + } + + return null; + } + + /** + * Returns lowest value. + * + * @return found value if there is such value, and null otherwise + */ + private E normalOrderFirst() { + Node current = root; + if (current == null) { + return null; + } + + while (current.left != null) { + current = current.left; + } + + return current.value; + } + + /** + * Returns highest value. + * + * @return found value if there is such value, and null otherwise + */ + private E normalOrderLast() { + Node current = root; + if (current == null) { + return null; + } + + while (current.right != null) { + current = current.right; + } + + return current.value; + } + + /** + * Returns the greatest value in this set strictly less than the specified value. + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + private E normalOrderLower(@NotNull E value) { + Node current = root; + if (current == null) { + return null; + } + E answer = null; + + while (current != null) { + int compareResult = comparator.compare(current.value, value); + if (compareResult >= 0) { + current = current.left; + } else { + answer = current.value; + current = current.right; + } + } + + return answer; + } + + /** + * Returns the greatest value in this set less than or equal to the specified value, + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + private E normalOrderFloor(@NotNull E value) { + Node found = find(value); + return found != null ? found.value : normalOrderLower(value); + } + + /** + * Returns the least value in this set greater than or equal to the specified value. + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + private E normalOrderCeiling(@NotNull E value) { + Node found = find(value); + return found != null ? found.value : normalOrderHigher(value); + } + + /** + * Returns the least value in this set strictly greater than the given value, + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + private E normalOrderHigher(@NotNull E value) { + Node current = root; + E answer = null; + + while (current != null) { + int compareResult = comparator.compare(current.value, value); + if (compareResult <= 0) { + current = current.right; + } else { + answer = current.value; + current = current.left; + } + } + + return answer; + } + + /** + * Initializes comparator for values ordering by specified comparator. + * + * @param comparator specified comparator + */ + public MyTreeSet(@NotNull Comparator comparator) { + this.comparator = comparator; + } + + /** + * Initializes comparator for values ordering using value's comparability, + * therefore generic type must implements Comparable interface. + */ + public MyTreeSet() { + comparator = (o1, o2) -> ((Comparable) o1).compareTo(o2); + } + + /** + * Checks if there is a value equals to specified value. + * + * @param value to check + * @return true if there is such value, and false otherwise + */ + @Override + public boolean contains(@NotNull Object value) { + return find((E) value) != null; + } + + /** + * Adds new Node storing specified value to the tree. + * + * @param value to add + * @return false if there was specified value, and true otherwise + */ + @Override + public boolean add(@NotNull E value) { + if (contains(value)) { + return false; + } + if (root == null) { + root = new Node(value); + size = 1; + return true; + } + + Node current = root; + Node parent = null; + while (current != null) { + parent = current; + int compareResult = comparator.compare(current.value, value); + if (compareResult > 0) { + current = current.left; + } else if (compareResult < 0) { + current = current.right; + } + + } + + int compareResult = comparator.compare(parent.value, value); + if (compareResult < 0) { + parent.right = new Node(value); + } else if (compareResult > 0) { + parent.left = new Node(value); + } + + size++; + return true; + } + + /** + * Removes Node storing specified value from tree. + * + * @param value to remove + * @return true if there was specified value, and false otherwise + */ + @Override + public boolean remove(@NotNull Object value) { + if (!contains(value)) { + return false; + } + size--; + + Node current = root; + Node parent = null; + int compareResult; + while ((compareResult = comparator.compare(current.value, (E) value)) != 0) { + parent = current; + if (compareResult > 0) { + current = current.left; + } else { + current = current.right; + } + } + + boolean isLeftChild = parent != null && parent.left == current; + if (parent != null) { + if (current.left == null) { + if (isLeftChild) { + parent.left = current.right; + return true; + } else { + parent.right = current.right; + return true; + } + } else if (current.right == null) { + if (isLeftChild) { + parent.left = current.left; + return true; + } else { + parent.right = current.left; + return true; + } + } + } else { + if (current.left == null) { + root = current.right; + return true; + } else if (current.right == null) { + root = current.left; + return true; + } + } + + E nextValue = normalOrderHigher(current.value); + remove(nextValue); + current.value = nextValue; + + return true; + } + + /** + * Returns an iterator over the values in this set in descending order. + */ + public Iterator descendingIterator() { + return descendingSet().iterator(); + } + + /** + * Returns a reverse order view of the values contained in this set. + */ + public MyTreeSet descendingSet() { + return new MyTreeSet<>(this); + } + + /** + * Returns lowest value if order isn't reversed, and highest value otherwise. + * + * @return found value if there is such value, and null otherwise + */ + public E first() { + if (reverse) { + return normalOrderLast(); + } else { + return normalOrderFirst(); + } + } + + /** + * Returns highest value if order isn't reversed, and lowest value otherwise. + * + * @return found value if there is such value, and null otherwise + */ + public E last() { + if (reverse) { + return normalOrderFirst(); + } else { + return normalOrderLast(); + } + } + + /** + * Returns the greatest value in this set strictly less than the specified value if order isn't reversed, and + * the least value in this set strictly greater than the specified value otherwise. + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + public E lower(@NotNull E value) { + if (reverse) { + return normalOrderHigher(value); + } else { + return normalOrderLower(value); + } + } + + /** + * Returns the greatest value in this set less than or equal to the specified value if order isn't reversed, and + * the least value in this set greater than or equal to the specified value otherwise. + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + public E floor(@NotNull E value) { + if (reverse) { + return normalOrderCeiling(value); + } else { + return normalOrderFloor(value); + } + } + + /** + * Returns the least value in this set greater than or equal to the specified value if order isn't reversed, and + * the greatest value in this set less than or equal to the specified value otherwise. + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + public E ceiling(@NotNull E value) { + if (reverse) { + return normalOrderLower(value); + } else { + return normalOrderCeiling(value); + } + } + + /** + * Returns the least value in this set strictly greater than the given value if order isn't reversed, and + * the greatest value in this set strictly less than the specified value otherwise. + * + * @param value specified value + * @return found value if there is such value, and null otherwise + */ + @Nullable + public E higher(@NotNull E value) { + if (reverse) { + return normalOrderLower(value); + } else { + return normalOrderHigher(value); + } + } + + /** + * Returns an iterator over the values in this set. + */ + @NotNull + public Iterator iterator() { + return new MyTreeSetIterator(); + } + + /** + * Returns number of stored values in the tree. + */ + public int size() { + return size; + } + + /** + * Node for binary search tree. Stores left, right children and value. + */ + private class Node { + private Node left = null; + private Node right = null; + private E value; + + /** + * Initializes stored value with specified value. + * + * @param value specified value + */ + private Node(@NotNull E value) { + this.value = value; + } + + } + + /** + * Iterator for MyTreeSet. + */ + private class MyTreeSetIterator implements Iterator { + private E next = first(); + + @Override + public boolean hasNext() { + return next != null; + } + + @Override + public E next() { + if (next == null) { + throw new NoSuchElementException(); + } + + E prev = next; + next = higher(next); + return prev; + } + } +} diff --git a/MyTreeSet/src/test/java/MyTreeSetTest.java b/MyTreeSet/src/test/java/MyTreeSetTest.java new file mode 100644 index 0000000..46ab593 --- /dev/null +++ b/MyTreeSet/src/test/java/MyTreeSetTest.java @@ -0,0 +1,414 @@ +import org.junit.Test; + +import java.util.*; +import java.util.concurrent.ThreadLocalRandom; + +import static org.junit.Assert.*; + +public class MyTreeSetTest { + @Test + public void testConstructor() { + new MyTreeSet(); + } + + @Test + public void testConstructorWithComparator() { + new MyTreeSet((o1, o2) -> -1 * o1.compareTo(o2)); + } + + @Test + public void testAddReturnTrue() { + MyTreeSet mySet = new MyTreeSet<>(); + assertTrue(mySet.add(1L)); + } + + @Test + public void testAddReturnFalse() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(1L); + + assertFalse(mySet.add(1L)); + } + + @Test + public void testAdd() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(17L); + mySet.add(13L); + mySet.add(2L); + + assertArrayEquals(new Long[]{2L, 13L, 17L}, mySet.toArray()); + } + + @Test + public void testAddTheSame() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(17L); + mySet.add(13L); + mySet.add(2L); + mySet.add(13L); + + assertArrayEquals(new Long[]{2L, 13L, 17L}, mySet.toArray()); + } + + @Test + public void testAddRandom() { + MyTreeSet mySet = new MyTreeSet<>(); + TreeSet random = new TreeSet<>(); + + for (int i = 0; i < 100; i++) { + Integer valueToAdd = ThreadLocalRandom.current().nextInt(0, 30); + random.add(valueToAdd); + mySet.add(valueToAdd); + } + + assertArrayEquals(random.toArray(), mySet.toArray()); + } + + @Test + public void testRemoveReturnTrue() { + MyTreeSet mySet = new MyTreeSet<>((o1, o2) -> -1 * o1.compareTo(o2)); + mySet.add((char) 1); + + assertTrue(mySet.remove((char) 1)); + } + + @Test + public void testRemoveReturnFalse() { + MyTreeSet mySet = new MyTreeSet<>((o1, o2) -> -1 * o1.compareTo(o2)); + mySet.add((char) 1); + + assertFalse(mySet.remove((char) 2)); + } + + @Test + public void testRemove() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add('a'); + mySet.add('z'); + mySet.add('v'); + mySet.add('t'); + mySet.remove('t'); + mySet.remove('a'); + + assertArrayEquals(new Character[]{'v', 'z'}, mySet.toArray()); + } + + @Test + public void testRemoveTheSame() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add('a'); + mySet.add('z'); + mySet.add('v'); + mySet.add('t'); + mySet.remove('t'); + mySet.remove('a'); + mySet.remove('t'); + + assertArrayEquals(new Character[]{'v', 'z'}, mySet.toArray()); + } + + @Test + public void testRemoveRandom() { + MyTreeSet mySet = new MyTreeSet<>(); + TreeSet random = new TreeSet<>(); + + for (int i = 0; i < 100; i++) { + Integer valueToAdd = ThreadLocalRandom.current().nextInt(0, 30); + random.add(valueToAdd); + mySet.add(valueToAdd); + } + + for (int i = 0; i < 30; i++) { + Integer valueToRemove = ThreadLocalRandom.current().nextInt(0, 30); + random.remove(valueToRemove); + mySet.remove(valueToRemove); + } + + assertArrayEquals(random.toArray(), mySet.toArray()); + } + + @Test + public void testSizeEmpty() { + assertEquals(0, new MyTreeSet().size()); + } + + @Test + public void testSizeAdd() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(5); + mySet.add(2); + + assertEquals(2, mySet.size()); + } + + @Test + public void testSizeAddTheSame() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(2); + mySet.add(2); + + assertEquals(1, mySet.size()); + } + + @Test + public void testSizeRemove() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(5); + mySet.add(2); + mySet.remove(2); + + assertEquals(1, mySet.size()); + } + + @Test + public void testSizeRemoveTheSame() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add(5); + mySet.add(2); + mySet.remove(2); + mySet.remove(2); + + assertEquals(1, mySet.size()); + } + + @Test + public void testSizeOneHundred() { + MyTreeSet mySet = new MyTreeSet<>(); + for (int i = 0; i < 100; i++) { + mySet.add(i); + } + + assertEquals(100, mySet.size()); + } + + @Test + public void testContainsNotExisting() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add((byte) 1); + + assertFalse(mySet.contains((byte) 2)); + } + + @Test + public void testContainsAdd() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add((byte) 55); + + assertTrue(mySet.contains((byte) 55)); + } + + @Test + public void testContainsRemove() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.add((byte) 111); + mySet.remove((byte) 111); + + assertFalse(mySet.contains((byte) 111)); + } + + @Test + public void testFirstEmptySet() { + assertNull(new MyTreeSet((o1, o2) -> -1 * o1.compareTo(o2)).first()); + } + + @Test + public void testFirst() { + MyTreeSet mySet = new MyTreeSet<>((o1, o2) -> -1 * o1.compareTo(o2)); + mySet.addAll(Arrays.asList((short) 100, (short) -2, (short) -33, (short) 4)); + assertEquals(100, mySet.first().shortValue()); + } + + @Test + public void testFirstDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>((o1, o2) -> -1 * o1.compareTo(o2)); + mySet.addAll(Arrays.asList((short) 100, (short) -2, (short) -33, (short) 4)); + assertEquals(-33, mySet.descendingSet().first().shortValue()); + } + + @Test + public void testLastEmptySet() { + assertNull(new MyTreeSet((o1, o2) -> -1 * o1.compareTo(o2)).last()); + } + + @Test + public void testLast() { + MyTreeSet mySet = new MyTreeSet<>((o1, o2) -> -1 * o1.compareTo(o2)); + mySet.addAll(Arrays.asList((short) 100, (short) -2, (short) -33, (short) 4)); + assertEquals(-33, mySet.last().shortValue()); + } + + @Test + public void testLastDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>((o1, o2) -> -1 * o1.compareTo(o2)); + mySet.addAll(Arrays.asList((short) 100, (short) -2, (short) -33, (short) 4)); + assertEquals(100, mySet.descendingSet().last().shortValue()); + } + + @Test + public void testEmptyHigher() { + assertNull(new MyTreeSet().higher((short) 15)); + } + + @Test + public void testNotExistingHigher() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.higher((short) 15)); + } + + @Test + public void testNotExistingHigherDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.descendingSet().higher((short) 1)); + } + + @Test + public void testHigher() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(10, mySet.higher((short) 3).shortValue()); + } + + @Test + public void testHigherDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(3, mySet.descendingSet().higher((short) 10).shortValue()); + } + + @Test + public void testEmptyLower() { + assertNull(new MyTreeSet().lower((short) 15)); + } + + @Test + public void testNotExistingLower() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.lower((short) 1)); + } + + @Test + public void testNotExistingLowerDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.descendingSet().lower((short) 15)); + } + + @Test + public void testLower() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(1, mySet.lower((short) 2).shortValue()); + } + + @Test + public void testLowerDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(10, mySet.descendingSet().lower((short) 4).shortValue()); + } + + @Test + public void testEmptyFloor() { + assertNull(new MyTreeSet<>().floor((short) 15)); + } + + @Test + public void testNotExistingFloor() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.floor((short) 0)); + } + + @Test + public void testNotExistingFloorDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.descendingSet().floor((short) 17)); + } + + @Test + public void testFloor() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(15, mySet.floor((short) 15).shortValue()); + } + + @Test + public void testFloorDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(10, mySet.descendingSet().lower((short) 4).shortValue()); + } + + @Test + public void testEmptyCeiling() { + assertNull(new MyTreeSet<>().ceiling((short) 15)); + } + + @Test + public void testNotExistingCeiling() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.ceiling((short) 100)); + } + + @Test + public void testNotExistingCeilingDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertNull(mySet.descendingSet().ceiling((short) -17)); + } + + @Test + public void testCeiling() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(15, mySet.ceiling((short) 15).shortValue()); + } + + @Test + public void testCeilingDescendingSet() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 15, (short) 10)); + assertEquals(3, mySet.descendingSet().ceiling((short) 4).shortValue()); + } + + @Test(expected = NoSuchElementException.class) + public void testIteratorThrowsNoSuchElementException() { + Iterator iterator = new MyTreeSet().iterator(); + iterator.next(); + } + + @Test + public void testIterator() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 2, (short) 0)); + Iterator iterator = mySet.iterator(); + + for (byte i = 0; i < 4; i++) { + assertTrue(iterator.hasNext()); + assertEquals(i, iterator.next().byteValue()); + } + + assertFalse(iterator.hasNext()); + } + + @Test + public void testDescendingIterator() { + MyTreeSet mySet = new MyTreeSet<>(); + mySet.addAll(Arrays.asList((short) 1, (short) 3, (short) 2, (short) 0)); + Iterator iterator = mySet.descendingIterator(); + + for (byte i = 3; i >= 0; i--) { + assertTrue(iterator.hasNext()); + assertEquals(i, iterator.next().byteValue()); + } + + assertFalse(iterator.hasNext()); + } + +} \ No newline at end of file diff --git a/MyTreeSet/target/classes/HisTreeSet.class b/MyTreeSet/target/classes/HisTreeSet.class new file mode 100644 index 0000000000000000000000000000000000000000..cdebd9aabd839b7d7f339dadab88c9720d406281 GIT binary patch literal 597 zcmZvZ%TB^T7=_Ouy-?*MAYRy;vauUi(y+s5V&bB_KrKTVGHH`u@ZDVa06vuQFSQqo zi!Q!@&Ybzr>DTwiCxClQHC$=9)^NixT=UrD!CD0VbHXDx2_uGyIeXc;d)G=6A+2IQ zXXrS>58Nb;IK%W`k-b{Z7o_Y~z79_qdZd05@hak+m;|FggW{U95m8L?abYgqz_(uC zcHGM@Ddvp)8QRj#REiAWIqiFE=IhqQzX|Fi2Hm9VxrMTkVU|_%xR8{dLEQ>}o7vg+ z^5NKUaXhM(M4^fdh7+cd#~+2HmikrbyR1?Mqna=b4mH=7q~@yT$y8-vXwi2*O}hTU%tTPu)*aI*vy4% literal 0 HcmV?d00001 diff --git a/MyTreeSet/target/classes/MyTreeSet$1.class b/MyTreeSet/target/classes/MyTreeSet$1.class new file mode 100644 index 0000000000000000000000000000000000000000..fd625a8452600b1aeba6e33416d324e262d22509 GIT binary patch literal 175 zcmX^0Z`VEs1_l!bZgvKCb_PyH2Cm@z(xT*4x6GVWMg~6L%8;Ve)Zo+-y{yEtL`DXF z*SzGM{Nl{Kbl=pHjQkXK1};VhZn!EHLq-N3&%C_UBIlgM;^Nd|Mg{?pM*W<`ymWp4 yq^#8B5=I72xOxEv21W)ZpaVdF83-AGJQfC4AkD(S1|&Ivmg52yyDJWhc#Dri%Qt+XbMBkP=(#5hR+bw}V;otDZ z2Ti0Tl6XlJ6MvNP%(k>($!2%v`{tW-zH?^UKYzb`1u%yN3o&G4{M@!+;f{rA7)K&;?ydQMRHr9h;(%#0C~ z-P**AKyQ9^zvxR@kgCvFa6LCz6zET#%BR-}zf^tA-SNEZ$+i0ShV+ZhMunNde6{3M z)*atfaVx1Sc!7a7_DUdqC#d=Y_KN38f2rcsYLX?_Iy@6y)$AyF7Jh%{gkr3-ae7c zqwUd2ZEuzYXVwI=-SEv!J#Z_z6IVh36l)c#b-yH^xyso7wxDTsq&5a|!A1fDYWC2? zBO8w~YQsjKz-V~tA?RAQP%o92D{@1w{sIN;tI!+ zGnuQ5crkIkMN#Cas{05WJ%*{jhaUOBgdRd0YEc}Wg6->qRT%|)gKrdC?^A_nQ?3?@ zc*ic;A0`#UZ}c9)czFo(n+o%x9yM#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4^OK3 zcuFn6(`pf(Rg3X6mB34CsfD2hsER~hvC_9ylq^!=noa5==BeoHXgppHpCQ&ec3irS z;Fpl7B~PLL6lP0~_C`O=F>opT$c#7qKs7rk9VRD!WOF!6ViL}gvzXJ*fO};*>&P_L zGBcI+I)`t72lk77W4a)EF>26OT|+~sY?d6y>r$y z@06LMcS>mk^$AN3j(3I`WbL>8VfXb)Uhoya9Q*}aIeasFIXp-|@ky@mhO*$a<78&) zaYy5u8N$qI>=+zH`paa8>UdN>{W|P6I_?}xKEZds$I#?sMJrz@N?(&=7-vqBKQYz} z@?k|h)G`H5k{Q2d+RXefGKW!BU#{U1i+-!sLW)>^WVrmNyY3ucIP3m(0)C5Qr-z@6 zFZb!<`)fEzZeK;8BcgR}!d7II4>sk`jtX;Lnw$Flb^q2kfm!UIVjpAwP4>3Lw$5bn zs%@~nKVb2Tv4467zT0`m9zM778R3)TbC}QFeBRCHgM9Ae^Dv(YK40n&)_sfohS`6c z{XX{JVZWRGciH!{{~r4-?7z>xo&68kuV?>5_N&=H!+t6IXW1`c|0DLZ*+0j=n*ER2 z)8zcr_lwu${&t+j3pd|-8ZVLkSzM6ezmxsfsg4q#R0CM}zt|Sw*MjF?Mkm`2KJo(1 zlE=rPn&kI4XB@_FCt0ukvA?$d2`K;g)BoI*d?&RnMk~FHZ8Y8W_Vb?%r2;33mhYiq t-^;S|y-o}~jN7>4;|ouMy?h#9%pP%#QSurr;mQ{FOWB{r*YJ;+`+wE~zc2s* literal 0 HcmV?d00001 diff --git a/MyTreeSet/target/test-classes/MyTreeSetTest.class b/MyTreeSet/target/test-classes/MyTreeSetTest.class new file mode 100644 index 0000000000000000000000000000000000000000..dec8e367f2f12420a1dcea5f3b87d0a53740a52c GIT binary patch literal 13660 zcmcgy3wT^dbv~olO6!%qmL=IvB>5%FlGe7I_?1|)VoA0lDU$72subCfc%{9z)?V$( zyDPs4B(!mW0D%w_T=IgnB@hB6w3QWyB(%^_AQVbN+mN&g&^FM9q-}t{{zB%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Rr^Y<|h`x?!XFI8=TB?dVN^gpz Date: Tue, 14 Nov 2017 06:34:45 +0300 Subject: [PATCH 6/9] Extra files removed. --- Function/.gitignore | 49 ----- Function/.idea/.name | 1 - Function/.idea/compiler.xml | 18 -- Function/.idea/misc.xml | 13 -- Function/.idea/modules.xml | 8 - Function/Function.iml | 22 --- Function/pom.xml | 47 ----- .../mit/kazakov/Function/Collections.java | 126 ------------- .../spbau/mit/kazakov/Function/Function1.java | 32 ---- .../spbau/mit/kazakov/Function/Function2.java | 62 ------- .../spbau/mit/kazakov/Function/Predicate.java | 53 ------ .../mit/kazakov/Function/CollectionsTest.java | 167 ------------------ .../mit/kazakov/Function/Function1Test.java | 32 ---- .../mit/kazakov/Function/Function2Test.java | 63 ------- .../mit/kazakov/Function/PredicateTest.java | 61 ------- 15 files changed, 754 deletions(-) delete mode 100644 Function/.gitignore delete mode 100644 Function/.idea/.name delete mode 100644 Function/.idea/compiler.xml delete mode 100644 Function/.idea/misc.xml delete mode 100644 Function/.idea/modules.xml delete mode 100644 Function/Function.iml delete mode 100644 Function/pom.xml delete mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java delete mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java delete mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java delete mode 100644 Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java delete mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java delete mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java delete mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java delete mode 100644 Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java diff --git a/Function/.gitignore b/Function/.gitignore deleted file mode 100644 index 345e61a..0000000 --- a/Function/.gitignore +++ /dev/null @@ -1,49 +0,0 @@ -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties diff --git a/Function/.idea/.name b/Function/.idea/.name deleted file mode 100644 index 1ff17c5..0000000 --- a/Function/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Function \ No newline at end of file diff --git a/Function/.idea/compiler.xml b/Function/.idea/compiler.xml deleted file mode 100644 index 8f81c05..0000000 --- a/Function/.idea/compiler.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Function/.idea/misc.xml b/Function/.idea/misc.xml deleted file mode 100644 index c092288..0000000 --- a/Function/.idea/misc.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Function/.idea/modules.xml b/Function/.idea/modules.xml deleted file mode 100644 index 8962661..0000000 --- a/Function/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Function/Function.iml b/Function/Function.iml deleted file mode 100644 index e6ccb8a..0000000 --- a/Function/Function.iml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Function/pom.xml b/Function/pom.xml deleted file mode 100644 index b49ba25..0000000 --- a/Function/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - 4.0.0 - - ru.spbau.mit.kazakov - Function - 1.0-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.8 - 1.8 - - - - - - - - junit - junit - 4.8 - - - org.jetbrains - annotations - 13.0 - - - com.google.guava - guava - 23.2-jre - - - - - UTF-8 - UTF-8 - - - \ No newline at end of file diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java deleted file mode 100644 index e5eeaae..0000000 --- a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Collections.java +++ /dev/null @@ -1,126 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - - -import com.google.common.collect.Lists; -import org.jetbrains.annotations.NotNull; - -import java.util.*; - -/** - * Class providing methods for working with collections using functions. - */ -public class Collections { - /** - * Applies specified function to specified container's elements and adds mapped elements in new list. - * - * @param function specified function - * @param elements specified container - * @param type of elements in specified container - * @param type of elements in result list - * @return result list - */ - static public List map(@NotNull final Function1 function, @NotNull final Iterable elements) { - List resultList = new ArrayList<>(); - - for (T element : elements) { - resultList.add(function.apply(element)); - } - - return resultList; - } - - /** - * Creates new list composed of elements from specified container that satisfy specified predicate. - * - * @param predicate specified predicate - * @param elements specified container - * @param type of elements in specified container - * @return result list - */ - static public List filter(@NotNull final Predicate predicate, @NotNull final Iterable elements) { - List resultList = new ArrayList<>(); - - for (T element : elements) { - if (predicate.apply(element)) { - resultList.add(element); - } - } - - return resultList; - } - - /** - * Creates new list by adding elements from specified container while they satisfy specified predicate. - * - * @param predicate specified predicate - * @param elements specified container - * @param type of elements in specified container - * @return result list - */ - static public List takeWhile(@NotNull final Predicate predicate, @NotNull final Iterable elements) { - List resultList = new ArrayList<>(); - - for (T element : elements) { - if (!predicate.apply(element)) { - break; - } - resultList.add(element); - } - - return resultList; - } - - /** - * Creates new list by adding elements from specified container unless they satisfy specified predicate. - * - * @param predicate specified predicate - * @param elements specified container - * @param type of elements in specified container - * @return result list - */ - static public List takeUnless(@NotNull final Predicate predicate, @NotNull final Iterable elements) { - return takeWhile(predicate.not(), elements); - } - - /** - * Left-associative fold of specified collection. Reduces the list using specified function from left to right. - * - * @param function specified function - * @param startValue first value for function's first element - * @param elements specified collection - * @param type of elements in specified collection - * @param specified function's codomain - * @return result value - */ - static public U foldl(@NotNull final Function2 function, - U startValue, @NotNull final Collection elements) { - U resultValue = startValue; - - for (T element : elements) { - resultValue = function.apply(resultValue, element); - } - - return resultValue; - } - - /** - * Right-associative fold of specified collection. Reduces the list using specified function from right to left. - * - * @param function specified function - * @param startValue first value for function's second element - * @param elements specified collection - * @param type of elements in specified collection - * @param specified function's codomain - * @return result value - */ - static public U foldr(@NotNull final Function2 function, - final U startValue, @NotNull final Collection elements) { - U resultValue = startValue; - - for (T element : Lists.reverse(new ArrayList<>(elements))) { - resultValue = function.apply(element, resultValue); - } - - return resultValue; - } -} diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java deleted file mode 100644 index 9bbfe30..0000000 --- a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function1.java +++ /dev/null @@ -1,32 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - - -import org.jetbrains.annotations.NotNull; - -/** - * The interface for representing a function with one argument. - * - * @param domain's type - * @param codomain's type - */ -@FunctionalInterface -public interface Function1 { - /** - * Applies function to specified argument. - * - * @param argument for applying to - * @return mapped value - */ - U apply(T argument); - - /** - * Creates composition of functions. - * - * @param function for composition - * @param specified function's codomain's type - * @return result of function composition - */ - default Function1 compose(@NotNull final Function1 function) { - return argument -> function.apply(apply(argument)); - } -} diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java deleted file mode 100644 index 3532a7b..0000000 --- a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Function2.java +++ /dev/null @@ -1,62 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - - -import org.jetbrains.annotations.NotNull; - -/** - * The interface for representing a function with two arguments. - * - * @param first argument's type - * @param second argument's type - * @param codomain's type - */ -@FunctionalInterface -public interface Function2 { - /** - * Applies function to specified argument. - * - * @param firstArgument for applying to - * @param secondArgument for applying to - * @return mapped value - */ - K apply(T firstArgument, U secondArgument); - - /** - * Creates composition of functions. - * - * @param specified function's codomain's type - * @return result of function composition - */ - default Function2 compose(@NotNull final Function1 function) { - return (firstArgument, secondArgument) -> function.apply(apply(firstArgument, secondArgument)); - } - - /** - * Binds first argument to specified value. - * - * @param firstArgument specified value - * @return function of one argument - */ - default Function1 bind1(T firstArgument) { - return secondArgument -> apply(firstArgument, secondArgument); - } - - /** - * Binds second argument to specified value. - * - * @param secondArgument specified value - * @return function of one argument - */ - default Function1 bind2(U secondArgument) { - return firstArgument -> apply(firstArgument, secondArgument); - } - - /** - * Converts current function with two arguments into two functions with one argument. - * - * @return new function with one argument - */ - default Function1> curry() { - return this::bind1; - } -} \ No newline at end of file diff --git a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java b/Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java deleted file mode 100644 index 2a4c177..0000000 --- a/Function/src/main/java/ru/spbau/mit/kazakov/Function/Predicate.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - - -import org.jetbrains.annotations.NotNull; - -/** - * The interface for representing a predicate with one argument. - * - * @param domain's type - */ -@FunctionalInterface -public interface Predicate extends Function1 { - /** - * Predicate always returning true. - */ - Predicate ALWAYS_TRUE = argument -> true; - - /** - * Predicate always returning false. - */ - Predicate ALWAYS_FALSE = ALWAYS_TRUE.not(); - - /** - * Makes new predicate with two argument composed of logical OR of current and specified predicates. - * - * @param predicate a specified predicate - * @param specified predicate's argument's type - * @return new predicate with two variables - */ - default Function2 or(@NotNull final Predicate predicate) { - return (firstArgument, secondArgument) -> Predicate.this.apply(firstArgument) || predicate.apply(secondArgument); - } - - /** - * Makes new predicate with two argument composed of logical AND of current and specified predicates. - * - * @param predicate a specified predicate - * @param specified predicate's argument's type - * @return new predicate with two variables - */ - default Function2 and(@NotNull final Predicate predicate) { - return (firstArgument, secondArgument) -> Predicate.this.apply(firstArgument) && predicate.apply(secondArgument); - } - - /** - * Makes new predicate composed of logical NOT of current predicate. - * - * @return new predicate - */ - default Predicate not() { - return argument -> !apply(argument); - } -} diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java deleted file mode 100644 index 8a9a311..0000000 --- a/Function/src/test/java/ru/spbau/mit/kazakov/Function/CollectionsTest.java +++ /dev/null @@ -1,167 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - - -import static java.util.Arrays.asList; -import static org.junit.Assert.*; - -public class CollectionsTest { - @Test - public void testMapEmpty() { - Function1 function = argument -> argument * argument; - List list = new ArrayList<>(); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.map(function, list)); - } - - @Test - public void testMap() { - Function1 function = argument -> argument * argument; - List list = asList(-2, -1, 0, 4, 10); - List expected = asList(4, 1, 0, 16, 100); - - assertEquals(expected, Collections.map(function, list)); - } - - @Test - public void testFilterEmptyInput() { - Predicate function = argument -> Math.abs(argument) > 10; - List list = new ArrayList<>(); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.filter(function, list)); - } - - @Test - public void testFilterEmptyOutput() { - Predicate function = argument -> Math.abs(argument) == 1; - List list = asList(10, 3, -10, -99, 0, -23, 1001); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.filter(function, list)); - } - - @Test - public void testFilterAllListOutput() { - Predicate function = argument -> Math.abs(argument) != 1010; - List list = asList(10, 3, -10, -99, 0, -23, 1001); - List expected = asList(10, 3, -10, -99, 0, -23, 1001); - - assertEquals(expected, Collections.filter(function, list)); - } - - @Test - public void testFilter() { - Predicate function = argument -> Math.abs(argument) > 10; - List list = asList(10, 3, -10, -99, 0, -23, 1001); - List expected = asList(-99, -23, 1001); - - assertEquals(expected, Collections.filter(function, list)); - } - - @Test - public void testTakeWhileEmptyInput() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = new ArrayList<>(); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.takeWhile(function, list)); - } - - @Test - public void testTakeWhileEmptyOutput() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = asList(1, -77, 77, 77, 0, 77, -77, 198); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.takeWhile(function, list)); - } - - @Test - public void testTakeWhileAllListOutput() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = asList(-77, 77, 77, 77, -77); - List expected = asList(-77, 77, 77, 77, -77); - - assertEquals(expected, Collections.takeWhile(function, list)); - } - - @Test - public void testTakeWhile() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = asList(-77, 77, 77, 0, 77, -77, 198); - List expected = asList(-77, 77, 77); - - assertEquals(expected, Collections.takeWhile(function, list)); - } - - @Test - public void testTakeUnlessEmptyInput() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = new ArrayList<>(); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.takeUnless(function, list)); - } - - @Test - public void testTakeUnlessEmptyOutput() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = asList(-77, 77, 77, 0, 77, -77, 198); - List expected = new ArrayList<>(); - - assertEquals(expected, Collections.takeUnless(function, list)); - } - - @Test - public void testTakeUnlessAllListOutput() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = asList(0, 1, -99, 121, 89898, 32423); - List expected = asList(0, 1, -99, 121, 89898, 32423); - - assertEquals(expected, Collections.takeUnless(function, list)); - } - - @Test - public void testTakeUnless() { - Predicate function = argument -> Math.abs(argument) == 77; - List list = asList(0, 1, -99, 121, -77, 89898, 77, 32423); - List expected = asList(0, 1, -99, 121); - - assertEquals(expected, Collections.takeUnless(function, list)); - } - - @Test - public void testFoldlEmpty() { - Function2 function = (firstArgument, secondArgument) -> secondArgument / firstArgument; - List list = new ArrayList<>(); - assertEquals(1, (int) Collections.foldl(function, 1, list)); - } - - @Test - public void testFoldl() { - Function2 function = (firstArgument, secondArgument) -> secondArgument / firstArgument; - List list = asList(10, 20, 100); - assertEquals(50, (int) Collections.foldl(function, 1, list)); - } - - @Test - public void testFoldrEmpty() { - Function2 function = (firstArgument, secondArgument) -> firstArgument / secondArgument; - List list = new ArrayList<>(); - assertEquals(1, (int) Collections.foldr(function, 1, list)); - } - - @Test - public void testFoldr() { - Function2 function = (firstArgument, secondArgument) -> firstArgument / secondArgument; - List list = asList(100, 20, 10); - assertEquals(50, (int) Collections.foldr(function, 1, list)); - } -} \ No newline at end of file diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java deleted file mode 100644 index 3862672..0000000 --- a/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function1Test.java +++ /dev/null @@ -1,32 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class Function1Test { - @Test - public void testConstructor() { - new Function1() { - @Override - public Double apply(Integer argument) { - return argument / 2.0; - } - }; - } - - @Test - public void testApply() { - Function1 function = argument -> argument * 2; - assertEquals(new Integer(10), function.apply(5)); - } - - @Test - public void compose() { - Function1 someFunction = argument -> (long) (argument / 5); - Function1 anotherFunction = Object::toString; - Function1 composition = someFunction.compose(anotherFunction); - assertEquals("6", composition.apply(30)); - } - -} \ No newline at end of file diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java deleted file mode 100644 index a3d9e30..0000000 --- a/Function/src/test/java/ru/spbau/mit/kazakov/Function/Function2Test.java +++ /dev/null @@ -1,63 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class Function2Test { - @Test - public void testConstructor() { - new Function2() { - @Override - public Double apply(Long firstArgument, Integer secondArgument) { - return (firstArgument * secondArgument) / 5.0; - } - }; - } - - @Test - public void testApply() { - Function2 function = - (firstArgument, secondArgument) -> firstArgument.toString() + secondArgument.toString(); - assertEquals("8j", function.apply((byte) 8, 'j')); - } - - @Test - public void testCompose() { - Function2 someFunction = Integer::equals; - Function1 anotherFunction = argument -> { - if (argument) { - return (byte) 1; - } else { - return (byte) 0; - } - }; - Function2 composition = someFunction.compose(anotherFunction); - assertEquals(1, (byte) composition.apply(979, 979)); - } - - @Test - public void bind1() { - Function2 someFunction = - (firstArgument, secondArgument) -> (int) Math.pow(firstArgument, secondArgument); - Function1 anotherFunction = someFunction.bind1(2); - assertEquals(32, (int) anotherFunction.apply(5)); - } - - @Test - public void bind2() { - Function2 someFunction = - (firstArgument, secondArgument) -> (int) Math.pow(firstArgument, secondArgument); - Function1 anotherFunction = someFunction.bind2(3); - assertEquals(64, (int) anotherFunction.apply(4)); - } - - @Test - public void curry() { - Function2 function = - (firstArgument, secondArgument) -> Math.abs(firstArgument) + Math.abs(secondArgument); - Function1> curried = function.curry(); - assertEquals(46, (int) curried.apply(-44).apply(2)); - } - -} \ No newline at end of file diff --git a/Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java b/Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java deleted file mode 100644 index e354a30..0000000 --- a/Function/src/test/java/ru/spbau/mit/kazakov/Function/PredicateTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package ru.spbau.mit.kazakov.Function; - -import org.junit.Test; - -import static org.junit.Assert.*; - -public class PredicateTest { - @Test - public void testConstructor() { - new Predicate(){ - @Override - public Boolean apply(Double argument) { - return argument > 7; - } - }; - } - - @Test - public void testALWAYS_TRUE() { - assertTrue((boolean) Predicate.ALWAYS_TRUE.apply(new Object())); - } - - @Test - public void testALWAYS_FALSE() { - assertFalse((boolean) Predicate.ALWAYS_FALSE.apply(new Object())); - } - - @Test - public void testOr() { - Predicate somePredicate = argument -> argument; - Predicate anotherPredicate = argument -> argument >= 111; - Function2 or = somePredicate.or(anotherPredicate); - - assertFalse(or.apply(false, 1)); - assertTrue(or.apply(true, 110)); - assertTrue(or.apply(false, 111)); - assertTrue(or.apply(true, 1000)); - } - - @Test - public void testAnd() { - Predicate somePredicate = argument -> argument; - Predicate anotherPredicate = argument -> argument >= 111; - Function2 and = somePredicate.and(anotherPredicate); - - assertFalse(and.apply(false, 1)); - assertFalse(and.apply(true, 110)); - assertFalse(and.apply(false, 111)); - assertTrue(and.apply(true, 1000)); - } - - @Test - public void testNot() { - Predicate predicate = argument -> argument.equals("Math is painful"); - Predicate not = predicate.not(); - - assertTrue(not.apply("Math is wonderful")); - assertFalse(not.apply("Math is painful")); - } - -} \ No newline at end of file From 9b17cdde090253f925663564753114214bd26627 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 14 Nov 2017 06:36:37 +0300 Subject: [PATCH 7/9] Extra files removed. --- MyTreeSet/target/classes/HisTreeSet.class | Bin 597 -> 0 bytes MyTreeSet/target/classes/MyTreeSet$1.class | Bin 175 -> 0 bytes .../classes/MyTreeSet$MyTreeSetIterator.class | Bin 1308 -> 0 bytes MyTreeSet/target/classes/MyTreeSet$Node.class | Bin 2033 -> 0 bytes MyTreeSet/target/classes/MyTreeSet.class | Bin 9176 -> 0 bytes .../target/test-classes/MyTreeSetTest.class | Bin 13660 -> 0 bytes 6 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 MyTreeSet/target/classes/HisTreeSet.class delete mode 100644 MyTreeSet/target/classes/MyTreeSet$1.class delete mode 100644 MyTreeSet/target/classes/MyTreeSet$MyTreeSetIterator.class delete mode 100644 MyTreeSet/target/classes/MyTreeSet$Node.class delete mode 100644 MyTreeSet/target/classes/MyTreeSet.class delete mode 100644 MyTreeSet/target/test-classes/MyTreeSetTest.class diff --git a/MyTreeSet/target/classes/HisTreeSet.class b/MyTreeSet/target/classes/HisTreeSet.class deleted file mode 100644 index cdebd9aabd839b7d7f339dadab88c9720d406281..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 597 zcmZvZ%TB^T7=_Ouy-?*MAYRy;vauUi(y+s5V&bB_KrKTVGHH`u@ZDVa06vuQFSQqo zi!Q!@&Ybzr>DTwiCxClQHC$=9)^NixT=UrD!CD0VbHXDx2_uGyIeXc;d)G=6A+2IQ zXXrS>58Nb;IK%W`k-b{Z7o_Y~z79_qdZd05@hak+m;|FggW{U95m8L?abYgqz_(uC zcHGM@Ddvp)8QRj#REiAWIqiFE=IhqQzX|Fi2Hm9VxrMTkVU|_%xR8{dLEQ>}o7vg+ z^5NKUaXhM(M4^fdh7+cd#~+2HmikrbyR1?Mqna=b4mH=7q~@yT$y8-vXwi2*O}hTU%tTPu)*aI*vy4% diff --git a/MyTreeSet/target/classes/MyTreeSet$1.class b/MyTreeSet/target/classes/MyTreeSet$1.class deleted file mode 100644 index fd625a8452600b1aeba6e33416d324e262d22509..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 175 zcmX^0Z`VEs1_l!bZgvKCb_PyH2Cm@z(xT*4x6GVWMg~6L%8;Ve)Zo+-y{yEtL`DXF z*SzGM{Nl{Kbl=pHjQkXK1};VhZn!EHLq-N3&%C_UBIlgM;^Nd|Mg{?pM*W<`ymWp4 yq^#8B5=I72xOxEv21W)ZpaVdF83-AGJQfC4AkD(S1|&Ivmg52yyDJWhc#Dri%Qt+XbMBkP=(#5hR+bw}V;otDZ z2Ti0Tl6XlJ6MvNP%(k>($!2%v`{tW-zH?^UKYzb`1u%yN3o&G4{M@!+;f{rA7)K&;?ydQMRHr9h;(%#0C~ z-P**AKyQ9^zvxR@kgCvFa6LCz6zET#%BR-}zf^tA-SNEZ$+i0ShV+ZhMunNde6{3M z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wE~zc2s* diff --git a/MyTreeSet/target/test-classes/MyTreeSetTest.class b/MyTreeSet/target/test-classes/MyTreeSetTest.class deleted file mode 100644 index dec8e367f2f12420a1dcea5f3b87d0a53740a52c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13660 zcmcgy3wT^dbv~olO6!%qmL=IvB>5%FlGe7I_?1|)VoA0lDU$72subCfc%{9z)?V$( zyDPs4B(!mW0D%w_T=IgnB@hB6w3QWyB(%^_AQVbN+mN&g&^FM9q-}t{{zB%)2C%S-L_h=(5aQWiZ@gu3%w8uyZ)9^=vl zFFj6Q;mZ@bXyw0!PNC2#WO?XG?)((@`>Kcj!b^+j5ik8EeT^?)_tIa{(_9B>i|DB$ z5{WTBzW)UvuJ@jpE`zF^s!(zVU2oHJbZ|J*R|Ggs0w(4kPu#M)tz?gtNYd znn=b+2a~b5pr!jpqsj2F)f-NPA)qN5jU|K0FuDlxcgEs}>yC^9NSzW;o+h9#oE&P2 z4UYulK`Cw_w>O1C`>f<>JlYc<1;pIpQ$QeSUJ4GNluiVGYQzCwp6b@nc_er|SQiOK z57%|ZqKE4nF|cUD6s^HX0&{p&rJ(t$)H7st2ZzyA==2XpL$P5&-s8c@sMQk#N#!Ba6e5iOb}T|%jZxi3li^66Viet$XGZGCVX)PL&Qq#8@3azwRx|{3Qi`OrGiVCV=e}H}R*8#gqan0aT&e|C}!IMe@G=!__6=`$I>NHuBJ=I^5lc`f`!q!NP zBU1W=sycl_S)FM@)!$wX7Ma#bu7=dG#R^BH1|!>@vh7R}(i}j)t^pDz{?yN~?1`w{nZ1Wk#EH;S_dwW#wk{4jF87IzVv|p77Ii+cMQr5@yr581+yh4e z%_%T@29Cf#VUQ_u9QX2yE5$ZAyJ=T;_j<#0R8390m)Zn8*fS_|GGsqXs%z|ilJZol zhE7Y(bl8DUQK zex78WU8hsHSW`S6L@rTMU30*#9Bjw#FMI7eHj2zoP)&7)t{JL$zN!?xgR$t~XgrRX zTZcGo1w%3$b&?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ph*J2l$hjeqQz+&@MD`WQgR;U5VD^z8lPtOk8i{vmTKd;6FI_6fi~ z3D~FLAEyo2v-gjWYuG_`Od(GL@Z>Q@O`U%2%c0Jv2|;1RuHCnA$lJ z;1|Dl;dC+es?@GIr=Gj#;ogn^KOCe_;&!()Kb{?OaqdMFo-!74LV%|e-c+2U0>tYk zere`;fU4F$M)=?Y2Rr3wPy}|l^gHX|s4g zHHZ%&rMQjyP`*KY7;my}m)h0>Il_dkkvU;AqjNW=K{}UGY0-} zfKMFrvua@otwRr^Y<|h`x?!XFI8=TB?dVN^gpz Date: Tue, 14 Nov 2017 06:42:01 +0300 Subject: [PATCH 8/9] Added forgotten annotations. --- MyTreeSet/src/main/java/MyTreeSet.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MyTreeSet/src/main/java/MyTreeSet.java b/MyTreeSet/src/main/java/MyTreeSet.java index 74326ea..93abf9a 100644 --- a/MyTreeSet/src/main/java/MyTreeSet.java +++ b/MyTreeSet/src/main/java/MyTreeSet.java @@ -22,7 +22,7 @@ public class MyTreeSet extends AbstractSet implements HisTreeSet { * * @param originalSet specified myTreeSet */ - private MyTreeSet(MyTreeSet originalSet) { + private MyTreeSet(@NotNull MyTreeSet originalSet) { root = originalSet.root; size = originalSet.size; comparator = originalSet.comparator; @@ -58,6 +58,7 @@ private Node find(@NotNull E value) { * * @return found value if there is such value, and null otherwise */ + @Nullable private E normalOrderFirst() { Node current = root; if (current == null) { @@ -76,6 +77,7 @@ private E normalOrderFirst() { * * @return found value if there is such value, and null otherwise */ + @Nullable private E normalOrderLast() { Node current = root; if (current == null) { @@ -297,6 +299,7 @@ public boolean remove(@NotNull Object value) { /** * Returns an iterator over the values in this set in descending order. */ + @NotNull public Iterator descendingIterator() { return descendingSet().iterator(); } @@ -313,6 +316,7 @@ public MyTreeSet descendingSet() { * * @return found value if there is such value, and null otherwise */ + @Nullable public E first() { if (reverse) { return normalOrderLast(); @@ -326,6 +330,7 @@ public E first() { * * @return found value if there is such value, and null otherwise */ + @Nullable public E last() { if (reverse) { return normalOrderFirst(); From 5631d5808a1e1ca261bc539b22f634c377cb1228 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Wed, 22 Nov 2017 17:19:12 +0300 Subject: [PATCH 9/9] Added packages. --- .../mit/kazakov/TreeSet}/HisTreeSet.java | 2 ++ .../spabu/mit/kazakov/TreeSet}/MyTreeSet.java | 4 +++- MyTreeSet/src/test/java/MyTreeSetTest.java | 21 +------------------ 3 files changed, 6 insertions(+), 21 deletions(-) rename MyTreeSet/src/main/java/{ => ru/spabu/mit/kazakov/TreeSet}/HisTreeSet.java (94%) rename MyTreeSet/src/main/java/{ => ru/spabu/mit/kazakov/TreeSet}/MyTreeSet.java (99%) diff --git a/MyTreeSet/src/main/java/HisTreeSet.java b/MyTreeSet/src/main/java/ru/spabu/mit/kazakov/TreeSet/HisTreeSet.java similarity index 94% rename from MyTreeSet/src/main/java/HisTreeSet.java rename to MyTreeSet/src/main/java/ru/spabu/mit/kazakov/TreeSet/HisTreeSet.java index 4eff59b..2b2c8fe 100644 --- a/MyTreeSet/src/main/java/HisTreeSet.java +++ b/MyTreeSet/src/main/java/ru/spabu/mit/kazakov/TreeSet/HisTreeSet.java @@ -1,3 +1,5 @@ +package ru.spabu.mit.kazakov.TreeSet; + import java.util.Iterator; import java.util.Set; import java.util.TreeSet; diff --git a/MyTreeSet/src/main/java/MyTreeSet.java b/MyTreeSet/src/main/java/ru/spabu/mit/kazakov/TreeSet/MyTreeSet.java similarity index 99% rename from MyTreeSet/src/main/java/MyTreeSet.java rename to MyTreeSet/src/main/java/ru/spabu/mit/kazakov/TreeSet/MyTreeSet.java index 74326ea..9c6a947 100644 --- a/MyTreeSet/src/main/java/MyTreeSet.java +++ b/MyTreeSet/src/main/java/ru/spabu/mit/kazakov/TreeSet/MyTreeSet.java @@ -1,3 +1,5 @@ +package ru.spabu.mit.kazakov.TreeSet; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -433,7 +435,7 @@ private Node(@NotNull E value) { } /** - * Iterator for MyTreeSet. + * Iterator for ru.spabu.mit.kazakov.TreeSet.MyTreeSet. */ private class MyTreeSetIterator implements Iterator { private E next = first(); diff --git a/MyTreeSet/src/test/java/MyTreeSetTest.java b/MyTreeSet/src/test/java/MyTreeSetTest.java index 46ab593..acc6aaa 100644 --- a/MyTreeSet/src/test/java/MyTreeSetTest.java +++ b/MyTreeSet/src/test/java/MyTreeSetTest.java @@ -1,4 +1,5 @@ import org.junit.Test; +import ru.spabu.mit.kazakov.TreeSet.MyTreeSet; import java.util.*; import java.util.concurrent.ThreadLocalRandom; @@ -108,26 +109,6 @@ public void testRemoveTheSame() { assertArrayEquals(new Character[]{'v', 'z'}, mySet.toArray()); } - @Test - public void testRemoveRandom() { - MyTreeSet mySet = new MyTreeSet<>(); - TreeSet random = new TreeSet<>(); - - for (int i = 0; i < 100; i++) { - Integer valueToAdd = ThreadLocalRandom.current().nextInt(0, 30); - random.add(valueToAdd); - mySet.add(valueToAdd); - } - - for (int i = 0; i < 30; i++) { - Integer valueToRemove = ThreadLocalRandom.current().nextInt(0, 30); - random.remove(valueToRemove); - mySet.remove(valueToRemove); - } - - assertArrayEquals(random.toArray(), mySet.toArray()); - } - @Test public void testSizeEmpty() { assertEquals(0, new MyTreeSet().size());