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

Maha ali 101249189 #186

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

@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> item1 = items[0];
DisjointSet.Item<Integer> item = items[1];
DisjointSet.Item<Integer> i3 = items[2];
DisjointSet.Item<Integer> i4 = items[3];
item1 = DisjointSet.union(item1, item);
item1= DisjointSet.union(item1, i3);
item1= DisjointSet.union(i4, item1);
DisjointSet.union(null, item);
DisjointSet.union(item, item);
DisjointSet.find(null);
DisjointSet.union(null, null);
}

@Test
public void testString() {
String Disjoint = "mapTest";
Disjoint.toString();
DisjointSet<String> ds = new DisjointSet();
ds.toString();
StringBuilder builder = new StringBuilder();
builder.append(Disjoint);
builder.append(Disjoint).toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,92 @@
package com.jwetherell.algorithms.data_structures.test;

import static org.junit.Assert.assertTrue;

import static org.junit.Assert.*;

import org.junit.Test;

import com.jwetherell.algorithms.data_structures.List;
import com.jwetherell.algorithms.data_structures.SkipListMap;
import com.jwetherell.algorithms.data_structures.test.common.JavaMapTest;
import com.jwetherell.algorithms.data_structures.test.common.MapTest;
import com.jwetherell.algorithms.data_structures.test.common.Utils;
import com.jwetherell.algorithms.data_structures.test.common.Utils.TestData;

public class SkipListMapTests {
SkipListMap<String, Integer> map = new SkipListMap<String, Integer>();

@Test
public void testSkipListMap() {
TestData data = Utils.generateTestData(1000);

String mapName = "SkipListMap";
SkipListMap<String,Integer> map = new SkipListMap<String,Integer>();
java.util.Map<String,Integer> jMap = map.toMap();
java.util.Map<String, Integer> jMap = map.toMap();

assertTrue(MapTest.testMap(map, String.class, mapName,
data.unsorted, data.invalid));
data.unsorted, data.invalid));
assertTrue(JavaMapTest.testJavaMap(jMap, Integer.class, mapName,
data.unsorted, data.sorted, data.invalid));
data.unsorted, data.sorted, data.invalid));



}

@Test
public void getTest() {
Integer value = 1;
String key = "SkipListMap";
SkipListMap<String, Integer> expected = new SkipListMap<String, Integer>();
expected.put(key, value);
map.put(key, value);
assertTrue(map.contains(key));
assertTrue(map.get(key)!= null);
assertNull(map.get("NotKey"));
}

@Test
public void clearListTest() {
List.ArrayList<Integer> mapList = new List.ArrayList<Integer>();
java.util.Map<String, Integer> jMap = map.toMap();

mapList.add(201);
mapList.clear();
map.clear();
jMap.clear();
}

@Test
public void validate() {
List.ArrayList<Integer> mapList = new List.ArrayList<Integer>();
String test = "Work";
java.util.Map<String, Integer> jMap = map.toMap();
StringBuilder builder = new StringBuilder();
builder.append(test);
assertNotNull(jMap.toString());
assertNotNull(map.toString());


}

@Test
public void toStringtest() {

map.put("map", 1234)
String expected= "1234";

assertNotNull(map.toString());

}

@Test

public void testValidate() {
SkipListMap<String, String> mapTest = new SkipListMap<String, String>();
String key = "book";
String val = null;
mapTest.put(key, val);
assertTrue(!mapTest.validate());

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,60 @@
import com.jwetherell.algorithms.data_structures.test.common.SuffixTreeTest;

public class SuffixTrieTests {
SuffixTrie<String> tries = new SuffixTrie<String>("test");

@Test
public void testSuffixTrie() {
String bookkeeper = "bookkeeper";
SuffixTrie<String> trie = new SuffixTrie<String>(bookkeeper);
assertTrue(SuffixTreeTest.suffixTreeTest(trie, bookkeeper));

}

@Test
public void testAdd() {
String course = "Advanced Software Testing";
assertTrue(tries.add(course));

}

@Test
public void testGetSuffix() {
Set<String> getTrie = tries.getSuffixes();
assertNotNull(getTrie);

}

@Test
public void stringTest() {
assertNotNull(tries.toString());
}

@Test
public void getSuffix() {
StringBuilder builder = new StringBuilder();
Set<String> set = new TreeSet<String>();

assertTrue(set.add(builder.toString()));

}


@Test
public void testSuffixTrieAdd() {
String software = "software";
SuffixTrie<String> trie = new SuffixTrie<String>(software);
trie.add(software);
assertTrue(SuffixTreeTest.suffixTreeTest(trie, software));
}

@Test
public void testSuffixTrieGetSuffixes() {
String testing = "testing";
SuffixTrie<String> trie = new SuffixTrie<String>(testing);
Set<String> trieSet = trie.getSuffixes();
String trieString = trie.toString();
assertTrue(SuffixTreeTest.suffixTreeTest(trie, testing));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,65 @@

public class TrieMapTests {

TrieMap<String,Integer> map = new TrieMap<String,Integer>();

@Test
public void testTrieMap() {
TestData data = Utils.generateTestData(1000);

String mapName = "TrieMap";
TrieMap<String,Integer> map = new TrieMap<String,Integer>();
String mapName = "TrieMap";
java.util.Map<String,Integer> jMap = map.toMap();

assertTrue(MapTest.testMap(map, String.class, mapName,
data.unsorted, data.invalid));
assertTrue(JavaMapTest.testJavaMap(jMap, String.class, mapName,
data.unsorted, data.sorted, data.invalid));
}

@Test
public void getTest() {
TrieMap<String,Integer> actual = new TrieMap<String,Integer>();
String key = "TrieMap";
Integer value = 10;
actual.put(key, value);
assertTrue(actual.get(key)!=null);
assertTrue(actual.get("null")==null);

}

@Test
public void clearTest() {
java.util.Map<String,Integer> jMap = map.toMap();
List.ArrayList<Integer> mapList = new List.ArrayList<Integer>();
mapList.clear();

jMap.clear();

}

@Test
public void toStringTest() {
TrieMap<String,Integer> actual = new TrieMap<String,Integer>();
java.util.Map<String,Integer> jMap = map.toMap();
actual.put("Map", 1);
map.put("Map", 1);
StringBuilder builder = new StringBuilder();
builder.append(map.toString());
assertEquals(map.toString(), actual.toString());
assertNotNull(jMap.toString());

}

@Test

public void testValidate() {

TrieMap<String,String> validateTest = new TrieMap<String,String>();
String key = "book";
String val = null;
map_test.put(key, val);
assertTrue(!map_test.validate());

} data.unsorted, data.sorted, data.invalid));
}
}