Commit a7f4030f authored by Lenovo's avatar Lenovo

final step with junit tester

parent facfc59b
......@@ -4,7 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="2698c064-0a25-4fa9-b373-a085833ed750" name="Changes" comment="third step" />
<list default="true" id="2698c064-0a25-4fa9-b373-a085833ed750" name="Changes" comment="fourth step with main tester">
<change afterPath="$PROJECT_DIR$/src/test/java/ParallelSummersTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......@@ -23,6 +26,9 @@
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
</component>
<component name="ProjectId" id="2YDqGbLJfns60iFSnvDoXlK7JEf" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
......@@ -36,6 +42,67 @@
"SHARE_PROJECT_CONFIGURATION_FILES": "true"
}
}]]></component>
<component name="RunManager" selected="JUnit.ParallelSummersTest.testSixteenThread">
<configuration name="ParallelSummersTest.testEightThread" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ExecutorServiceHW" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="ParallelSummersTest" />
<option name="METHOD_NAME" value="testEightThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ParallelSummersTest.testFourThread" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ExecutorServiceHW" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="ParallelSummersTest" />
<option name="METHOD_NAME" value="testFourThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ParallelSummersTest.testSingleThread" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ExecutorServiceHW" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="ParallelSummersTest" />
<option name="METHOD_NAME" value="testSingleThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ParallelSummersTest.testSixteenThread" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ExecutorServiceHW" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="ParallelSummersTest" />
<option name="METHOD_NAME" value="testSixteenThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ParallelSummersTest.testTwoThread" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ExecutorServiceHW" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="ParallelSummersTest" />
<option name="METHOD_NAME" value="testTwoThread" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.ParallelSummersTest.testSixteenThread" />
<item itemvalue="JUnit.ParallelSummersTest.testEightThread" />
<item itemvalue="JUnit.ParallelSummersTest.testFourThread" />
<item itemvalue="JUnit.ParallelSummersTest.testTwoThread" />
<item itemvalue="JUnit.ParallelSummersTest.testSingleThread" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
......@@ -66,7 +133,14 @@
<option name="project" value="LOCAL" />
<updated>1700071001900</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="fourth step with main tester">
<created>1700071261635</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1700071261635</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
......@@ -84,6 +158,7 @@
<MESSAGE value="first step" />
<MESSAGE value="second step" />
<MESSAGE value="third step" />
<option name="LAST_COMMIT_MESSAGE" value="third step" />
<MESSAGE value="fourth step with main tester" />
<option name="LAST_COMMIT_MESSAGE" value="fourth step with main tester" />
</component>
</project>
\ No newline at end of file
import static org.junit.jupiter.api.Assertions.*;
import org.example.SequentialSummer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.example.data.TestData;
import org.example.parallelsummers.ParallelSummer0;
import org.example.parallelsummers.ParallelSummer1;
import org.example.parallelsummers.ParallelSummer2;
import org.example.parallelsummers.ParallelSummer3;
import org.example.parallelsummers.ParallelSummer4;
import java.util.Arrays;
import java.util.List;
class ParallelSummersTest {
/*
The ParallelSummersTest class is designed to assess the performance of other classes
that compute the count of prime numbers within a specified range.
The range starts from a variable named start and ends at a variable named end.
The data array contains the numbers within this range,
and the result variable stores the count of prime numbers calculated sequentially
*/
private static int start;
private static int end;
private static int[] data;
private static long result;
/*
The function initialize is designed to identify the range and sequentially compute the result.
*/
@BeforeAll
public static void initialize() {
start = 0;
end = 20;
data = TestData.createData(start, end);
result = SequentialSummer.sum(SequentialSummer.allPrimes(data));
}
/*
The testAll function is designed to compare the results of calculating the number of primes with five different parallel methods.
Each method requires a data array that contains a range of numbers and the number of threads to be used.
*/
private static void testAll(int threadCount) {
assertEquals(result, ParallelSummer0.sum(data, threadCount));
assertEquals(result, ParallelSummer1.sum(data, threadCount));
assertEquals(result, ParallelSummer2.sum(data, threadCount));
assertEquals(result, ParallelSummer3.sum(data, threadCount));
assertEquals(result, ParallelSummer4.sum(data, threadCount));
System.out.println(result);
}
/*
Invoke the testSingleThread function to call the testAll function using a single thread,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void testSingleThread() {
long start = System.currentTimeMillis();
testAll(1);
long end = System.currentTimeMillis();
System.out.println("1 Thread takes " + (end-start)/1000 + " seconds");
}
/*
Invoke the testTwoThread function to call the testAll function using two threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void testTwoThread() {
long start = System.currentTimeMillis();
testAll(2);
long end = System.currentTimeMillis();
System.out.println("2 Threads take " + (end-start)/1000 + " seconds");
}
/*
Invoke the testFourThread function to call the testAll function using four threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void testFourThread() {
long start = System.currentTimeMillis();
testAll(4);
long end = System.currentTimeMillis();
System.out.println("4 Threads take " + (end-start)/1000 + " seconds");
}
/*
Invoke the testEightThread function to call the testAll function using eight threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void testEightThread() {
long start = System.currentTimeMillis();
testAll(8);
long end = System.currentTimeMillis();
System.out.println("8 Threads take " + (end-start)/1000 + " seconds");
}
/*
Invoke the testSixteenThread function to call the testAll function using sixteen threads,
and then print the total duration in seconds it takes to execute the tasks in parallel.
*/
@Test
void testSixteenThread() {
long start = System.currentTimeMillis();
testAll(16);
long end = System.currentTimeMillis();
System.out.println("16 Threads take " + (end-start)/1000 + " seconds");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment