Commit ef78506d authored by saad.aswad's avatar saad.aswad

Counters for contain and removing

parent d8f16659
...@@ -6,10 +6,7 @@ ...@@ -6,10 +6,7 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="List length, sorting in Adding implementations."> <list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="List length, sorting in Adding implementations.">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/LockList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/LockList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/RWLockList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/RWLockList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/SortList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/SortList.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/SortList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/SortList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/SyncList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/SyncList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/SyncListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/SyncListTest.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/test/java/SyncListTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/SyncListTest.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -46,20 +43,20 @@ ...@@ -46,20 +43,20 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"ASKED_ADD_EXTERNAL_FILES": "true", &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
"JUnit.SyncListTest.testRun.executor": "Run", &quot;JUnit.SyncListTest.testRun.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"SHARE_PROJECT_CONFIGURATION_FILES": "true", &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
"git-widget-placeholder": "task2", &quot;git-widget-placeholder&quot;: &quot;task2&quot;,
"kotlin-language-version-configured": "true", &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
"project.structure.last.edited": "Modules", &quot;project.structure.last.edited&quot;: &quot;Modules&quot;,
"project.structure.proportion": "0.0", &quot;project.structure.proportion&quot;: &quot;0.0&quot;,
"project.structure.side.proportion": "0.0" &quot;project.structure.side.proportion&quot;: &quot;0.0&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="JUnit.SyncListTest.testRun"> <component name="RunManager" selected="JUnit.SyncListTest.testRun">
<configuration name="SyncListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="SyncListTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="SortLinkedList" /> <module name="SortLinkedList" />
......
...@@ -3,10 +3,21 @@ public abstract class SortList { ...@@ -3,10 +3,21 @@ public abstract class SortList {
public Entry head; public Entry head;
public long length; public long length;
public long conatinSuccess;
public long conatinFailure;
public long removeSuccess;
public long removeFailure;
public SortList() { public SortList() {
this.head = new Entry(Integer.MIN_VALUE); this.head = new Entry(Integer.MIN_VALUE);
this.head.next =new Entry(Integer.MAX_VALUE); this.head.next =new Entry(Integer.MAX_VALUE);
this.length = 2; this.length = 2;
this.conatinSuccess=0;
this.conatinFailure=0;
this.removeFailure=0;
this.removeSuccess=0;
} }
public abstract boolean add(Integer obj); public abstract boolean add(Integer obj);
......
...@@ -32,6 +32,7 @@ public class SyncListTest extends TestCase { ...@@ -32,6 +32,7 @@ public class SyncListTest extends TestCase {
List<Thread> addThreads = new ArrayList<>(); List<Thread> addThreads = new ArrayList<>();
List<Thread> containThreads = new ArrayList<>(); List<Thread> containThreads = new ArrayList<>();
List<Thread> removeThreads = new ArrayList<>(); List<Thread> removeThreads = new ArrayList<>();
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
AddThread addThread = new AddThread(seq, randLen / 8, list); AddThread addThread = new AddThread(seq, randLen / 8, list);
ContainThread containThread = new ContainThread(seq, randLen / 8, list); ContainThread containThread = new ContainThread(seq, randLen / 8, list);
...@@ -44,6 +45,9 @@ public class SyncListTest extends TestCase { ...@@ -44,6 +45,9 @@ public class SyncListTest extends TestCase {
removeThreads.add(threadR); removeThreads.add(threadR);
} }
// Add phase.
long startA = System.currentTimeMillis(); long startA = System.currentTimeMillis();
addThreads.stream().forEach(e -> e.start() ); addThreads.stream().forEach(e -> e.start() );
...@@ -59,13 +63,14 @@ public class SyncListTest extends TestCase { ...@@ -59,13 +63,14 @@ public class SyncListTest extends TestCase {
System.out.println("ADD "+label+" execution task: "+endA+" ms"); System.out.println("ADD "+label+" execution task: "+endA+" ms");
long listLengthAfterAdds = list.length; long listLengthAfterAdds = list.length;
System.out.println("Length of the list after adding: "+listLengthAfterAdds); System.out.println("Length of the list after adding: "+listLengthAfterAdds);
String listIsSorted = list.checkSorted() ? "The List is sorted" : "The list is not sorted"; String listIsSorted = list.checkSorted() ? "The List is sorted" : "The list is not sorted";
System.out.println(listIsSorted); System.out.println(listIsSorted);
// Contain phase.
long startC = System.currentTimeMillis(); long startC = System.currentTimeMillis();
containThreads.stream().forEach(e -> e.start() ); containThreads.stream().forEach(e -> e.start() );
...@@ -83,6 +88,8 @@ public class SyncListTest extends TestCase { ...@@ -83,6 +88,8 @@ public class SyncListTest extends TestCase {
System.out.println("Counter of Failure contain operations: "+list.conatinFailure); System.out.println("Counter of Failure contain operations: "+list.conatinFailure);
// Remove phase.
long startR = System.currentTimeMillis(); long startR = System.currentTimeMillis();
removeThreads.stream().forEach(e -> e.start() ); removeThreads.stream().forEach(e -> e.start() );
...@@ -97,6 +104,16 @@ public class SyncListTest extends TestCase { ...@@ -97,6 +104,16 @@ public class SyncListTest extends TestCase {
System.out.println("\nRemove "+label+" execution task: "+endR+" ms"); System.out.println("\nRemove "+label+" execution task: "+endR+" ms");
long listLengthAfterRemove = list.length;
System.out.println("Length of the list after removing: "+listLengthAfterRemove);
listIsSorted = list.checkSorted() ? "The List is sorted" : "The list is not sorted";
System.out.println(listIsSorted);
System.out.println("Counter of Success remove operations: "+list.removeSuccess);
System.out.println("Counter of Failure reomve operations: "+list.removeFailure);
} }
public void testRun(){ public void testRun(){
......
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