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

Implementing removeGroup function

parent 2c805c0a
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="Counters for contain and removing"> <list default="true" id="3f4b2924-17d7-4794-bacf-d51c4f0be8bb" name="Changes" comment="Implementing removeGroup function">
<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/RWLockList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/RWLockList.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/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" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -45,6 +47,8 @@ ...@@ -45,6 +47,8 @@
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"ASKED_ADD_EXTERNAL_FILES": "true", "ASKED_ADD_EXTERNAL_FILES": "true",
"JUnit.SyncListTest.executor": "Run",
"JUnit.SyncListTest.testRemoveGroup.executor": "Run",
"JUnit.SyncListTest.testRun.executor": "Run", "JUnit.SyncListTest.testRun.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
...@@ -56,7 +60,7 @@ ...@@ -56,7 +60,7 @@
"project.structure.side.proportion": "0.0" "project.structure.side.proportion": "0.0"
} }
}]]></component> }]]></component>
<component name="RunManager" selected="JUnit.SyncListTest.testRun"> <component name="RunManager" selected="JUnit.SyncListTest">
<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" />
<option name="PACKAGE_NAME" value="" /> <option name="PACKAGE_NAME" value="" />
...@@ -86,6 +90,16 @@ ...@@ -86,6 +90,16 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="SyncListTest.testRemoveGroup" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="SortLinkedList" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="SyncListTest" />
<option name="METHOD_NAME" value="testRemoveGroup" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="SyncListTest.testRun" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="SyncListTest.testRun" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="SortLinkedList" /> <module name="SortLinkedList" />
<option name="PACKAGE_NAME" value="" /> <option name="PACKAGE_NAME" value="" />
...@@ -98,11 +112,11 @@ ...@@ -98,11 +112,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.SyncListTest" />
<item itemvalue="JUnit.SyncListTest.testRemoveGroup" />
<item itemvalue="JUnit.SyncListTest.testRun" /> <item itemvalue="JUnit.SyncListTest.testRun" />
<item itemvalue="JUnit.SyncListTest.testRandSeq" /> <item itemvalue="JUnit.SyncListTest.testRandSeq" />
<item itemvalue="JUnit.SyncListTest.testAddList" /> <item itemvalue="JUnit.SyncListTest.testAddList" />
<item itemvalue="JUnit.SyncListTest" />
<item itemvalue="JUnit.SyncListTest.testRun" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
...@@ -146,7 +160,15 @@ ...@@ -146,7 +160,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1762796431078</updated> <updated>1762796431078</updated>
</task> </task>
<option name="localTasksCounter" value="5" /> <task id="LOCAL-00005" summary="Implementing removeGroup function">
<option name="closed" value="true" />
<created>1762799420648</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1762799420648</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
...@@ -165,6 +187,18 @@ ...@@ -165,6 +187,18 @@
<MESSAGE value="Concurrent Sorted Linked List Implementations" /> <MESSAGE value="Concurrent Sorted Linked List Implementations" />
<MESSAGE value="List length, sorting in Adding implementations." /> <MESSAGE value="List length, sorting in Adding implementations." />
<MESSAGE value="Counters for contain and removing" /> <MESSAGE value="Counters for contain and removing" />
<option name="LAST_COMMIT_MESSAGE" value="Counters for contain and removing" /> <MESSAGE value="Implementing removeGroup function" />
<option name="LAST_COMMIT_MESSAGE" value="Implementing removeGroup function" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/RWLockList.java</url>
<line>84</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -98,13 +98,9 @@ public class RWLockList extends SortList { ...@@ -98,13 +98,9 @@ public class RWLockList extends SortList {
} }
} }
if (internalSuccess > 0) { this.removeSuccess+=internalSuccess;
removeSuccess+=internalSuccess; this.removeFailure+=items.size() - internalSuccess;
} else {
if (!items.isEmpty()) {
removeFailure+=items.size() - internalSuccess;
}
}
} finally { } finally {
lock.writeLock().unlock(); lock.writeLock().unlock();
} }
......
import java.util.Collection;
public abstract class SortList { public abstract class SortList {
public Entry head; public Entry head;
......
import junit.framework.TestCase; import junit.framework.TestCase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
public class SyncListTest extends TestCase { public class SyncListTest extends TestCase {
...@@ -150,5 +152,47 @@ public class SyncListTest extends TestCase { ...@@ -150,5 +152,47 @@ public class SyncListTest extends TestCase {
public void testRemoveGroup(){ public void testRemoveGroup(){
System.out.println("\n--- TESTING removeGroup ---");
// We test RWLockList as requested by the assignment
SortList list = new RWLockList();
list.add(10);
list.add(5);
list.add(20);
list.add(15);
list.add(30);
System.out.println("List before removeGroup:");
list.printList();
assertEquals(5L, list.length); // Check initial length
Collection<Integer> itemsToRemove = Arrays.asList(5, 12, 15, 25);
int removedCount = ((RWLockList) list).removeGroup(itemsToRemove);
System.out.println("\nList after removeGroup:");
list.printList();
assertEquals("Should have removed 2 items", 2, removedCount);
assertEquals("List length should be 3", 3L, list.length);
assertTrue("List should still be sorted", list.checkSorted());
assertFalse("Item 5 should be removed", list.contain(5));
assertFalse("Item 15 should be removed", list.contain(15));
assertTrue("Item 10 should still be present", list.contain(10));
assertTrue("Item 20 should still be present", list.contain(20));
assertTrue("Item 30 should still be present", list.contain(30));
assertEquals("Remove success count should be 2", 2, list.removeSuccess);
assertEquals("Remove failure count should be 2", 2, list.removeFailure);
System.out.println("\nremoveGroup test passed.");
} }
} }
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