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

Added tests to increase coverage in {DisjointSetTests.java, SkipListMapTests.java, SuffixTrieTests.java, TrieMapTests.java} #184

Open
wants to merge 3 commits into
base: master
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,59 @@ private static final String toString(DisjointSet.Item<Integer>[] items) {
builder.append("}\n");
return builder.toString();
}

//Tests Added
//Author: Abhishek Ahuja

@Test
public void testDisjointSet3() {
final int max = 10;
final int[] array = new int[max];
for (int i=0; i<array.length; i++)
array[i] = i+1;
final DisjointSet.Item<Integer>[] items = new DisjointSet.Item[array.length];
for (int i=0; i<items.length; i++) {
final int v = array[i];
final DisjointSet.Item<Integer> s = DisjointSet.makeSet(v);
items[i] = s;
}
DisjointSet.Item<Integer> i1 = items[0];
DisjointSet.Item<Integer> i2 = items[1];
DisjointSet.Item<Integer> i3 = items[2];
DisjointSet.Item<Integer> i4 = items[3];

//if (xRoot==null && yRoot!=null)
final DisjointSet.Item<Integer> xRootNull = DisjointSet.union(null, i1);
Assert.assertTrue(xRootNull.getValue()==i1.getValue());

// if (yRoot==null && xRoot!=null)
final DisjointSet.Item<Integer> yRootNull = DisjointSet.union(i2, null);
Assert.assertTrue(yRootNull.getValue()==i2.getValue());

//if (xRoot.equals(yRoot))
final DisjointSet.Item<Integer> equalRoots = DisjointSet.union(i2, i2);
Assert.assertTrue(equalRoots.getValue()==i2.getValue());

//if (x == null)
Assert.assertNull(DisjointSet.find(null));

//if (xRoot==null && yRoot==null)
Assert.assertNull(DisjointSet.union(null, null));

DisjointSet.Item<Integer> unequalItem1 = DisjointSet.union(i1, i2);
Assert.assertNotNull(unequalItem1);
//if (xRoot.rank > yRoot.rank)
DisjointSet.Item<Integer> unequalItem2 = DisjointSet.union(i1, i3);
Assert.assertNotNull(unequalItem2);
//if (xRoot.rank < yRoot.rank)
DisjointSet.Item<Integer> unequalItem3 = DisjointSet.union(i4, i1);
Assert.assertNotNull(unequalItem3);

Assert.assertFalse(unequalItem1.equals("False"));

String i2String = i2.toString();
String expectedResult = "parent=1 value=2";
Assert.assertTrue(i2String.equals(expectedResult));

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.jwetherell.algorithms.data_structures.test;

import static org.junit.Assert.assertTrue;
//modified to include all Assert methods directly
//Author: Abhishek Ahuja
import static org.junit.Assert.*;

import org.junit.Test;

Expand All @@ -10,6 +12,11 @@
import com.jwetherell.algorithms.data_structures.test.common.Utils;
import com.jwetherell.algorithms.data_structures.test.common.Utils.TestData;

//added for additional tests
//Author: Abhishek Ahuja
import com.jwetherell.algorithms.data_structures.List;


public class SkipListMapTests {

@Test
Expand All @@ -26,4 +33,47 @@ public void testSkipListMap() {
data.unsorted, data.sorted, data.invalid));
}

}
//Tests added
//Author: Abhishek Ahuja

@Test
public void testPutGet(){
SkipListMap<String,Integer> newMap1 = new SkipListMap<String,Integer>();
SkipListMap<String,Integer> newMap2 = new SkipListMap<String,Integer>();
newMap1.put("Red", 1);
newMap2.put("Red", 1);
assertTrue(newMap1.contains("Red"));
assertNotNull(newMap1.get("Red"));
assertNull(newMap1.get("Blue"));
assertEquals("Red=1",newMap1.toString());
}

@Test
public void testLists(){
List.ArrayList<Integer> newList = new List.ArrayList<Integer>();
SkipListMap<String,Integer> listTest = new SkipListMap<String,Integer>();
java.util.Map<String, Integer> jMap2 = listTest.toMap();
newList.add(1);
newList.clear();
listTest.clear();
jMap2.clear();
assertNotNull(listTest.toString());
assertNotNull(jMap2.toString());
}

@Test
public void testStringBuilder(){
StringBuilder builder = new StringBuilder();
builder.append("Build");
}

@Test
public void testValidate() {
SkipListMap<String,Integer> newMap3 = new SkipListMap<String,Integer>();
newMap3.put("Green", null);
newMap3.validate();
assertTrue(!newMap3.validate());
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.jwetherell.algorithms.data_structures.test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

//importing two additional required utilities
//Author: Abhishek Ahuja
import java.util.Set;
import java.util.TreeSet;

import org.junit.Test;

Expand All @@ -15,4 +20,22 @@ public void testSuffixTrie() {
SuffixTrie<String> trie = new SuffixTrie<String>(bookkeeper);
assertTrue(SuffixTreeTest.suffixTreeTest(trie, bookkeeper));
}

//New Tests Added
//Author: Abhishek Ahuja

@Test
public void testAddGet() {
SuffixTrie<String> testTrie = new SuffixTrie<String>("batman");
String partner = "robin";
assertTrue(testTrie.add(partner));
assertNotNull(testTrie.getSuffixes());
}

@Test
public void testString() {
SuffixTrie<String> testTrie2 = new SuffixTrie<String>("superman");
assertNotNull(testTrie2.toString());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.jwetherell.algorithms.data_structures.test;

import static org.junit.Assert.assertTrue;
//Modified to include all Assert methods directly
//Author: Abhishek Ahuja
import static org.junit.Assert.*;

import org.junit.Test;

Expand All @@ -10,6 +12,10 @@
import com.jwetherell.algorithms.data_structures.test.common.Utils;
import com.jwetherell.algorithms.data_structures.test.common.Utils.TestData;

//Imported
//Author: Abhishek Ahuja
import com.jwetherell.algorithms.data_structures.List;

public class TrieMapTests {

@Test
Expand All @@ -25,4 +31,52 @@ public void testTrieMap() {
assertTrue(JavaMapTest.testJavaMap(jMap, String.class, mapName,
data.unsorted, data.sorted, data.invalid));
}

//Tests Added
//Author: Abhishek Ahuja

@Test
public void testPutGet() {
TrieMap<String,Integer> trieMap1 = new TrieMap<String,Integer>();
TrieMap<String,Integer> trieMap2 = new TrieMap<String,Integer>();
String key = "Green";
Integer value = 1;
trieMap1.put(key,value);
trieMap2.put(key,value);
assertTrue(trieMap1.contains(key));
assertNotNull(trieMap1.get(key));
assertNull(trieMap1.get("Blue"));
assertEquals(trieMap1.toString(),trieMap2.toString());

}

@Test
public void testClear() {

List.ArrayList<Integer> newList = new List.ArrayList<Integer>();
TrieMap<String,Integer> trieMap3 = new TrieMap<String,Integer>();
java.util.Map<String, Integer> jMap1 = trieMap3.toMap();
newList.add(1);
newList.clear();
trieMap3.clear();
jMap1.clear();
assertNotNull(jMap1.toString());

}

@Test
public void toStringTest() {
StringBuilder builder = new StringBuilder();
builder.append("Build");
}

@Test
public void testValidate() {
TrieMap<String,String> trieMap4 = new TrieMap<String,String>();
String key = "abc";
String val = null;
trieMap4.put(key, val);
assertTrue(!trieMap4.validate());
}

}