diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..6ef9f6f
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,74 @@
+
+
+ 4.0.0
+
+ groupId
+ SoftServe-1
+ 1.0-SNAPSHOT
+
+
+ 1.8
+ 1.8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.22.0
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.5
+
+
+
+ prepare-agent
+
+
+
+
+ report
+ test
+
+ report
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 11
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.5
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.6.2
+ test
+
+
+ junit
+ junit
+ 4.13
+ test
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Runner.java b/src/main/java/Runner.java
similarity index 100%
rename from src/Runner.java
rename to src/main/java/Runner.java
diff --git a/src/sequences/hierarchy/Displayer.java b/src/main/java/sequences/hierarchy/Displayer.java
similarity index 96%
rename from src/sequences/hierarchy/Displayer.java
rename to src/main/java/sequences/hierarchy/Displayer.java
index acdfce7..a733bdf 100644
--- a/src/sequences/hierarchy/Displayer.java
+++ b/src/main/java/sequences/hierarchy/Displayer.java
@@ -18,7 +18,6 @@ public class Displayer extends Thread {
public Displayer(String name) {
super(name);
-
}
private String readFromFile(String fileName) {
@@ -44,6 +43,9 @@ public void run() {
if (!searchingRunning) {
System.out.println("Enter file name");
fileName = scanner.nextLine();
+ if(fileName.equals("42")){
+ break;
+ }
text = readFromFile(fileName);
if (searcher == null) {
searcher = new Searcher(this, minPatternSize, text, "Sequences Searcher");
diff --git a/src/sequences/hierarchy/Searcher.java b/src/main/java/sequences/hierarchy/Searcher.java
similarity index 89%
rename from src/sequences/hierarchy/Searcher.java
rename to src/main/java/sequences/hierarchy/Searcher.java
index 21e4402..282db57 100644
--- a/src/sequences/hierarchy/Searcher.java
+++ b/src/main/java/sequences/hierarchy/Searcher.java
@@ -40,7 +40,6 @@ private ResultSet checkAllPatterns(int patternSize) {
if (lastMatches.found())
return lastMatches;
}
-// lastMatches = searcherImpl.find(text, pattern).results().stream().flatMap(a -> Stream.of(a.start)).collect(Collectors.toList());
return lastMatches;
}
@@ -50,7 +49,6 @@ public void run() {
searchingRunning = true;
while (pattern.length() < text.length() / 2) {
for (int i = minPatternSize; i <= text.length() / 2; i++) {
- System.out.println("!!!!!!!!!!!!!!!!!!!!!!NEW SIZE OF PATTERN " + i + "!!!!!!!!!!!!!!!!!!!!");
searchResult = checkAllPatterns(i);
if (searchResult.found()) {
matches = searchResult;
diff --git a/src/sequences/hierarchy/Threads.java b/src/main/java/sequences/hierarchy/Threads.java
similarity index 100%
rename from src/sequences/hierarchy/Threads.java
rename to src/main/java/sequences/hierarchy/Threads.java
diff --git a/src/sequences/karprabin/data/Result.java b/src/main/java/sequences/karprabin/data/Result.java
similarity index 100%
rename from src/sequences/karprabin/data/Result.java
rename to src/main/java/sequences/karprabin/data/Result.java
diff --git a/src/sequences/karprabin/data/ResultSet.java b/src/main/java/sequences/karprabin/data/ResultSet.java
similarity index 100%
rename from src/sequences/karprabin/data/ResultSet.java
rename to src/main/java/sequences/karprabin/data/ResultSet.java
diff --git a/src/sequences/karprabin/impl/KarpRabinAlgorithm.java b/src/main/java/sequences/karprabin/impl/KarpRabinAlgorithm.java
similarity index 100%
rename from src/sequences/karprabin/impl/KarpRabinAlgorithm.java
rename to src/main/java/sequences/karprabin/impl/KarpRabinAlgorithm.java
diff --git a/src/threads/ExecutorServiceRunner.java b/src/main/java/threads/ExecutorServiceRunner.java
similarity index 94%
rename from src/threads/ExecutorServiceRunner.java
rename to src/main/java/threads/ExecutorServiceRunner.java
index 2373bf6..242063e 100644
--- a/src/threads/ExecutorServiceRunner.java
+++ b/src/main/java/threads/ExecutorServiceRunner.java
@@ -43,9 +43,7 @@ public static void main(String[] args) {
for (int i = 0; i task, List primes, bool
this.isSynchronized = isSynchronized;
}
- public PrimeNumberCounter(int id, int number, List primes) {
- this.id = id;
- this.number = number;
- this.primes = primes;
- }
-
private void calculate(int number) {
isPrime = true;
for (int i = 2; i < number / 2; i++) {
@@ -60,8 +54,4 @@ public void run() {
if (!isSynchronized)
saveAllPrimes(localPrimes);
}
-
- public void setNumber(int number) {
- this.number = number;
- }
}
diff --git a/src/threads/PrimeNumberCounterCallable.java b/src/main/java/threads/PrimeNumberCounterCallable.java
similarity index 76%
rename from src/threads/PrimeNumberCounterCallable.java
rename to src/main/java/threads/PrimeNumberCounterCallable.java
index b8d81b7..ff5ab93 100644
--- a/src/threads/PrimeNumberCounterCallable.java
+++ b/src/main/java/threads/PrimeNumberCounterCallable.java
@@ -22,19 +22,6 @@ public PrimeNumberCounterCallable(int id, List task, List prim
this.isSynchronized = isSynchronized;
}
- public PrimeNumberCounterCallable(int id, int number, List primes) {
- this.id = id;
- this.number = number;
- this.primes = primes;
- }
-
- public PrimeNumberCounterCallable(int id, int startNumber, int endNumber, List primes) {
- this.id = id;
- this.startNumber = startNumber;
- this.endNumber = endNumber;
- this.primes = primes;
- }
-
private void calculate(int number) {
isPrime = true;
for (int i = 2; i < number / 2; i++) {
@@ -59,10 +46,6 @@ private void saveAllPrimes(List localPrimes) {
}
}
- public void setNumber(int number) {
- this.number = number;
- }
-
@Override
public Integer call() throws Exception {
for (int i = 0; i < task.size(); i++) {
diff --git a/src/threads/ThreadKeeper.java b/src/main/java/threads/ThreadKeeper.java
similarity index 74%
rename from src/threads/ThreadKeeper.java
rename to src/main/java/threads/ThreadKeeper.java
index bcb3a76..02be596 100644
--- a/src/threads/ThreadKeeper.java
+++ b/src/main/java/threads/ThreadKeeper.java
@@ -38,17 +38,9 @@ private List> setTasks(int threadPoolSize, int startNumber, int en
public void start() {
System.out.println("Thread pool size is " + threadPoolSize);
if (startNumber > endNumber || threadPoolSize < 1) throw new IllegalArgumentException();
- if (endNumber - startNumber < threadPoolSize) {
- System.out.println("Wow, isn't it too much threads for so little amount of numbers?");
- startTime = System.currentTimeMillis();
- for (int i = startNumber; i <= endNumber; i++) {
- new Thread(group, new PrimeNumberCounter(i, i, primes)).start();
- }
- } else {
- tasks = setTasks(threadPoolSize, startNumber, endNumber);
- for (int i = 0; i < threadPoolSize; i++) {
- new Thread(group, new PrimeNumberCounter(i, tasks.get(i), primes,isSynchronized)).start();
- }
+ tasks = setTasks(threadPoolSize, startNumber, endNumber);
+ for (int i = 0; i < threadPoolSize; i++) {
+ new Thread(group, new PrimeNumberCounter(i, tasks.get(i), primes, isSynchronized)).start();
}
while (group.activeCount() > 0) {
diff --git a/src/resources/test.txt b/src/main/resources/test.txt
similarity index 100%
rename from src/resources/test.txt
rename to src/main/resources/test.txt
diff --git a/src/resources/text.txt b/src/main/resources/text.txt
similarity index 100%
rename from src/resources/text.txt
rename to src/main/resources/text.txt
diff --git a/src/test/java/SequencesTest.java b/src/test/java/SequencesTest.java
new file mode 100644
index 0000000..a3bae7f
--- /dev/null
+++ b/src/test/java/SequencesTest.java
@@ -0,0 +1,39 @@
+import org.junit.jupiter.api.Test;
+import sequences.hierarchy.Displayer;
+import sequences.hierarchy.Searcher;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class SequencesTest {
+
+ @Test
+ void TwoFileTest() throws InterruptedException {
+ String rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
+ rootPath = rootPath.replace("/", "\\").substring(1,rootPath.length());
+ System.setIn(new ByteArrayInputStream((rootPath + "test.txt\n" +
+ rootPath + "test.txt" +
+ "\n42").getBytes()));
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ PrintStream printStream = new PrintStream(byteArrayOutputStream);
+ PrintStream out = System.out;
+ System.setOut(printStream);
+ new Displayer("Test").run();
+ System.setOut(out);
+ System.out.println(byteArrayOutputStream.toString());
+ assertTrue(byteArrayOutputStream.toString().contains("The longest sequences of 24 symbols"));
+ }
+
+ @Test
+ void searcherTest() {
+ String text = "hehe karp-rabin algo is cool, cause it is karp-rabin algo!\n" +
+ "karp-rabin algo is cool,ho hehe cause it is karp-rabin algo!\n" +
+ "hehe";
+ Searcher searcher = new Searcher(new Displayer("Test"), 3, text, "TestSearcher");
+ searcher.start();
+ searcher.setText(text);
+ }
+}
\ No newline at end of file
diff --git a/test/ThreadKeeperTest.java b/src/test/java/ThreadKeeperTest.java
similarity index 55%
rename from test/ThreadKeeperTest.java
rename to src/test/java/ThreadKeeperTest.java
index 4e68c6d..443e537 100644
--- a/test/ThreadKeeperTest.java
+++ b/src/test/java/ThreadKeeperTest.java
@@ -3,19 +3,17 @@
import java.io.ByteArrayInputStream;
-import static org.junit.jupiter.api.Assertions.*;
-
class ThreadKeeperTest {
@Test
void start() {
- System.setIn(new ByteArrayInputStream("3\n 10\n 100000".getBytes()));
+ System.setIn(new ByteArrayInputStream("5\n 10\n 100000".getBytes()));
Runner.main(new String[1]);
- System.setIn(new ByteArrayInputStream("3\n 10\n 100000".getBytes()));
+ System.setIn(new ByteArrayInputStream("5\n 10\n 100000".getBytes()));
Runner.main(null);
- System.setIn(new ByteArrayInputStream("3\n 10\n 100000".getBytes()));
+ System.setIn(new ByteArrayInputStream("5\n 10\n 100000".getBytes()));
ExecutorServiceRunner.main(new String[1]);
- System.setIn(new ByteArrayInputStream("3\n 10\n 100000".getBytes()));
+ System.setIn(new ByteArrayInputStream("5\n 10\n 100000".getBytes()));
ExecutorServiceRunner.main(null);
}
}
\ No newline at end of file
diff --git a/src/test/java/resources/test.txt b/src/test/java/resources/test.txt
new file mode 100644
index 0000000..269311c
--- /dev/null
+++ b/src/test/java/resources/test.txt
@@ -0,0 +1,3 @@
+hehe karp-rabin algo is cool, cause it is karp-rabin algo!
+ karp-rabin algo is cool,ho hehe cause it is karp-rabin algo!
+ hehe
\ No newline at end of file
diff --git a/src/test/java/sequences/hierarchy/DisplayerTest.java b/src/test/java/sequences/hierarchy/DisplayerTest.java
new file mode 100644
index 0000000..f3c6ed5
--- /dev/null
+++ b/src/test/java/sequences/hierarchy/DisplayerTest.java
@@ -0,0 +1,9 @@
+package sequences.hierarchy;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class DisplayerTest {
+
+
+
+}
\ No newline at end of file
diff --git a/target/site/jacoco/index.html b/target/site/jacoco/index.html
new file mode 100644
index 0000000..3a51e4a
--- /dev/null
+++ b/target/site/jacoco/index.html
@@ -0,0 +1 @@
+SoftServe-1SoftServe-1
\ No newline at end of file
diff --git a/test/sequences/hierarchy/DisplayerTest.java b/test/sequences/hierarchy/DisplayerTest.java
deleted file mode 100644
index 1e31361..0000000
--- a/test/sequences/hierarchy/DisplayerTest.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package sequences.hierarchy;
-
-import java.io.ByteArrayInputStream;
-
-class DisplayerTest {
-
- @org.junit.jupiter.api.Test
- void runTest() {
- System.setIn(new ByteArrayInputStream(("C:\\Users\\SvampX\\IdeaProjects\\SoftServe-1\\resources\\test.txt\n" +
- "C:\\Users\\SvampX\\IdeaProjects\\SoftServe-1\\resources\\test.txt\n").getBytes()));
- Displayer displayer = new Displayer("test");
- displayer.start();
- }
-}
\ No newline at end of file