Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored + code coverage added #2

Open
wants to merge 1 commit into
base: primes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>SoftServe-1</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Displayer extends Thread {

public Displayer(String name) {
super(name);

}

private String readFromFile(String fileName) {
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public static void main(String[] args) {
for (int i = 0; i <futures.size() ; i++) {
try {
futures.get(i).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ public PrimeNumberCounter(int id, List<Integer> task, List<Integer> primes, bool
this.isSynchronized = isSynchronized;
}

public PrimeNumberCounter(int id, int number, List<Integer> 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++) {
Expand Down Expand Up @@ -60,8 +54,4 @@ public void run() {
if (!isSynchronized)
saveAllPrimes(localPrimes);
}

public void setNumber(int number) {
this.number = number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ public PrimeNumberCounterCallable(int id, List<Integer> task, List<Integer> prim
this.isSynchronized = isSynchronized;
}

public PrimeNumberCounterCallable(int id, int number, List<Integer> primes) {
this.id = id;
this.number = number;
this.primes = primes;
}

public PrimeNumberCounterCallable(int id, int startNumber, int endNumber, List<Integer> 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++) {
Expand All @@ -59,10 +46,6 @@ private void saveAllPrimes(List<Integer> localPrimes) {
}
}

public void setNumber(int number) {
this.number = number;
}

@Override
public Integer call() throws Exception {
for (int i = 0; i < task.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ private List<List<Integer>> 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) {

Expand Down
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions src/test/java/SequencesTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/test/java/resources/test.txt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions src/test/java/sequences/hierarchy/DisplayerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sequences.hierarchy;

import static org.junit.jupiter.api.Assertions.*;

class DisplayerTest {



}
1 change: 1 addition & 0 deletions target/site/jacoco/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ru"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="jacoco-resources/report.gif" type="image/gif"/><title>SoftServe-1</title><script type="text/javascript" src="jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb', 'coveragetable'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="jacoco-sessions.html" class="el_session">Sessions</a></span><span class="el_report">SoftServe-1</span></div><h1>SoftServe-1</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td><td class="sortable ctr1" id="l" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="m" onclick="toggleSort(this)">Classes</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">1 095 of 1 095</td><td class="ctr2">0 %</td><td class="bar">76 of 76</td><td class="ctr2">0 %</td><td class="ctr1">76</td><td class="ctr2">76</td><td class="ctr1">238</td><td class="ctr2">238</td><td class="ctr1">38</td><td class="ctr2">38</td><td class="ctr1">11</td><td class="ctr2">11</td></tr></tfoot><tbody><tr><td id="a4"><a href="threads/index.html" class="el_package">threads</a></td><td class="bar" id="b0"><img src="jacoco-resources/redbar.gif" width="120" height="10" title="535" alt="535"/></td><td class="ctr2" id="c0">0 %</td><td class="bar" id="d0"><img src="jacoco-resources/redbar.gif" width="120" height="10" title="46" alt="46"/></td><td class="ctr2" id="e0">0 %</td><td class="ctr1" id="f0">37</td><td class="ctr2" id="g0">37</td><td class="ctr1" id="h0">121</td><td class="ctr2" id="i0">121</td><td class="ctr1" id="j0">14</td><td class="ctr2" id="k0">14</td><td class="ctr1" id="l0">4</td><td class="ctr2" id="m0">4</td></tr><tr><td id="a1"><a href="sequences.hierarchy/index.html" class="el_package">sequences.hierarchy</a></td><td class="bar" id="b1"><img src="jacoco-resources/redbar.gif" width="75" height="10" title="337" alt="337"/></td><td class="ctr2" id="c1">0 %</td><td class="bar" id="d1"><img src="jacoco-resources/redbar.gif" width="46" height="10" title="18" alt="18"/></td><td class="ctr2" id="e1">0 %</td><td class="ctr1" id="f1">20</td><td class="ctr2" id="g1">20</td><td class="ctr1" id="h1">81</td><td class="ctr2" id="i1">81</td><td class="ctr1" id="j1">11</td><td class="ctr2" id="k1">11</td><td class="ctr1" id="l1">3</td><td class="ctr2" id="m1">3</td></tr><tr><td id="a3"><a href="sequences.karprabin.impl/index.html" class="el_package">sequences.karprabin.impl</a></td><td class="bar" id="b2"><img src="jacoco-resources/redbar.gif" width="29" height="10" title="130" alt="130"/></td><td class="ctr2" id="c2">0 %</td><td class="bar" id="d2"><img src="jacoco-resources/redbar.gif" width="20" height="10" title="8" alt="8"/></td><td class="ctr2" id="e2">0 %</td><td class="ctr1" id="f2">9</td><td class="ctr2" id="g2">9</td><td class="ctr1" id="h2">15</td><td class="ctr2" id="i2">15</td><td class="ctr1" id="j3">5</td><td class="ctr2" id="k3">5</td><td class="ctr1" id="l3">1</td><td class="ctr2" id="m3">1</td></tr><tr><td id="a2"><a href="sequences.karprabin.data/index.html" class="el_package">sequences.karprabin.data</a></td><td class="bar" id="b3"><img src="jacoco-resources/redbar.gif" width="11" height="10" title="52" alt="52"/></td><td class="ctr2" id="c3">0 %</td><td class="bar" id="d3"><img src="jacoco-resources/redbar.gif" width="5" height="10" title="2" alt="2"/></td><td class="ctr2" id="e3">0 %</td><td class="ctr1" id="f3">7</td><td class="ctr2" id="g3">7</td><td class="ctr1" id="h4">10</td><td class="ctr2" id="i4">10</td><td class="ctr1" id="j2">6</td><td class="ctr2" id="k2">6</td><td class="ctr1" id="l2">2</td><td class="ctr2" id="m2">2</td></tr><tr><td id="a0"><a href="default/index.html" class="el_package">default</a></td><td class="bar" id="b4"><img src="jacoco-resources/redbar.gif" width="9" height="10" title="41" alt="41"/></td><td class="ctr2" id="c4">0 %</td><td class="bar" id="d4"><img src="jacoco-resources/redbar.gif" width="5" height="10" title="2" alt="2"/></td><td class="ctr2" id="e4">0 %</td><td class="ctr1" id="f4">3</td><td class="ctr2" id="g4">3</td><td class="ctr1" id="h3">11</td><td class="ctr2" id="i3">11</td><td class="ctr1" id="j4">2</td><td class="ctr2" id="k4">2</td><td class="ctr1" id="l4">1</td><td class="ctr2" id="m4">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.5.201910111838</span></div></body></html>
14 changes: 0 additions & 14 deletions test/sequences/hierarchy/DisplayerTest.java

This file was deleted.