Skip to content

Commit 1b4da39

Browse files
author
Justin Wetherell
committed
Changed the testing of the data structures to use JUnit
1 parent 422a3f1 commit 1b4da39

37 files changed

+2386
-4262
lines changed

src/com/jwetherell/algorithms/DataStructures.java

Lines changed: 0 additions & 4042 deletions
This file was deleted.

src/com/jwetherell/algorithms/DataStructuresTiming.java

Lines changed: 1720 additions & 0 deletions
Large diffs are not rendered by default.

src/com/jwetherell/algorithms/data_structures/BinaryHeap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public interface BinaryHeap<T extends Comparable<T>> extends IHeap<T> {
2424

2525
public enum HeapType {
2626
Tree, Array
27-
};
27+
}
2828

2929
public enum Type {
3030
MIN, MAX
31-
};
31+
}
3232

3333
/**
3434
* Get the heap in array form.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.jwetherell.algorithms.data_structures;
2+
3+
import java.util.Set;
4+
5+
/**
6+
* In computer science, a suffix tree (also called PAT tree or, in an earlier form, position tree) is a compressed trie
7+
* containing all the suffixes of the given text as their keys and positions in the text as their values. Suffix trees
8+
* allow particularly fast implementations of many important string operations.
9+
*
10+
* http://en.wikipedia.org/wiki/Suffix_tree
11+
*
12+
* @author Justin Wetherell <[email protected]>
13+
*/
14+
public interface ISuffixTree<C extends CharSequence> {
15+
16+
/**
17+
* Does the sub-sequence exist in the suffix tree.
18+
*
19+
* @param sub-sequence to locate in the tree.
20+
* @return True if the sub-sequence exist in the tree.
21+
*/
22+
public boolean doesSubStringExist(C sub);
23+
24+
/**
25+
* Get all the suffixes in the tree.
26+
*
27+
* @return set of suffixes in the tree.
28+
*/
29+
public Set<String> getSuffixes();
30+
}

src/com/jwetherell/algorithms/data_structures/SuffixTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Justin Wetherell <[email protected]>
2020
*/
21-
public class SuffixTree<C extends CharSequence> {
21+
public class SuffixTree<C extends CharSequence> implements ISuffixTree<C> {
2222

2323
private static final char DEFAULT_END_SEQ_CHAR = '$';
2424

src/com/jwetherell/algorithms/data_structures/SuffixTrie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @author Justin Wetherell <[email protected]>
1717
*/
18-
public class SuffixTrie<C extends CharSequence> {
18+
public class SuffixTrie<C extends CharSequence> implements ISuffixTree<C> {
1919

2020
private Trie<C> tree = null;
2121

src/com/jwetherell/algorithms/data_structures/test/AVLTreeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public void testAVLTree() {
2727
assertTrue(TreeTest.testTree(bst, Type.Integer, bstName,
2828
data.unsorted, data.invalid));
2929
assertTrue(JavaCollectionTest.testCollection(bstCollection, Type.Integer, bstName,
30-
data.unsorted, data.sorted));
30+
data.unsorted, data.sorted, data.invalid));
3131
}
3232
}

src/com/jwetherell/algorithms/data_structures/test/AllTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
SkipListTests.class,
2929
SplayTreeTests.class,
3030
StackTests.class,
31+
SuffixTreeTests.class,
32+
SuffixTrieTests.class,
33+
TreapTests.class,
34+
TreeMapTests.class,
35+
TrieTests.class,
36+
TrieMapTests.class
3137
}
3238
)
3339

src/com/jwetherell/algorithms/data_structures/test/BTreeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public void testBTree() {
2525

2626
assertTrue(TreeTest.testTree(bst, Type.Integer, bstName, data.unsorted, data.invalid));
2727
assertTrue(JavaCollectionTest.testCollection(bstCollection, Type.Integer, bstName,
28-
data.unsorted, data.sorted));
28+
data.unsorted, data.sorted, data.invalid));
2929
}
3030
}

src/com/jwetherell/algorithms/data_structures/test/BinaryHeapTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.jwetherell.algorithms.data_structures.test;
22

3-
import static org.junit.Assert.*;
3+
import static org.junit.Assert.assertTrue;
44

55
import java.util.Collection;
66

@@ -17,23 +17,23 @@ public class BinaryHeapTests {
1717

1818
@Test
1919
public void testMinHeap() {
20-
TestData data = Utils.generateTestData(1000);
20+
TestData data = Utils.generateTestData(100);
2121

2222
String aNameMin = "Min-Heap [array]";
2323
BinaryHeap.BinaryHeapArray<Integer> aHeapMin = new BinaryHeap.BinaryHeapArray<Integer>(BinaryHeap.Type.MIN);
2424
Collection<Integer> aCollectionMin = aHeapMin.toCollection();
25-
assertTrue(HeapTest.testHeap(aHeapMin, aNameMin, BinaryHeap.Type.MIN,
25+
assertTrue(HeapTest.testHeap(BinaryHeap.Type.MIN, aHeapMin, Type.Integer, aNameMin,
2626
data.unsorted, data.sorted, data.invalid));
2727
assertTrue(JavaCollectionTest.testCollection(aCollectionMin, Type.Integer, aNameMin,
28-
data.unsorted, data.sorted));
28+
data.unsorted, data.sorted, data.invalid));
2929

3030
String tNameMin = "Min-Heap [tree]";
3131
BinaryHeap.BinaryHeapTree<Integer> tHeapMin = new BinaryHeap.BinaryHeapTree<Integer>(BinaryHeap.Type.MIN);
3232
Collection<Integer> tCollectionMin = tHeapMin.toCollection();
33-
assertTrue(HeapTest.testHeap(tHeapMin, tNameMin, BinaryHeap.Type.MIN,
33+
assertTrue(HeapTest.testHeap(BinaryHeap.Type.MIN, tHeapMin, Type.Integer, tNameMin,
3434
data.unsorted, data.sorted, data.invalid));
3535
assertTrue(JavaCollectionTest.testCollection(tCollectionMin, Type.Integer, tNameMin,
36-
data.unsorted, data.sorted));
36+
data.unsorted, data.sorted, data.invalid));
3737
}
3838

3939
@Test
@@ -43,17 +43,17 @@ public void testMaxHeap() {
4343
String aNameMax = "Max-Heap [array]";
4444
BinaryHeap.BinaryHeapArray<Integer> aHeapMax = new BinaryHeap.BinaryHeapArray<Integer>(BinaryHeap.Type.MAX);
4545
Collection<Integer> aCollectionMax = aHeapMax.toCollection();
46-
assertTrue(HeapTest.testHeap(aHeapMax, aNameMax, BinaryHeap.Type.MAX,
46+
assertTrue(HeapTest.testHeap(BinaryHeap.Type.MAX, aHeapMax, Type.Integer, aNameMax,
4747
data.unsorted, data.sorted, data.invalid));
4848
assertTrue(JavaCollectionTest.testCollection(aCollectionMax, Type.Integer, aNameMax,
49-
data.unsorted, data.sorted));
49+
data.unsorted, data.sorted, data.invalid));
5050

5151
String lNameMax = "Max-Heap [tree]";
5252
BinaryHeap.BinaryHeapTree<Integer> tHeapMax = new BinaryHeap.BinaryHeapTree<Integer>(BinaryHeap.Type.MAX);
5353
Collection<Integer> tCollectionMax = tHeapMax.toCollection();
54-
assertTrue(HeapTest.testHeap(tHeapMax, lNameMax, BinaryHeap.Type.MAX,
54+
assertTrue(HeapTest.testHeap(BinaryHeap.Type.MAX, tHeapMax, Type.Integer, lNameMax,
5555
data.unsorted, data.sorted, data.invalid));
5656
assertTrue(JavaCollectionTest.testCollection(tCollectionMax, Type.Integer, lNameMax,
57-
data.unsorted, data.sorted));
57+
data.unsorted, data.sorted, data.invalid));
5858
}
5959
}

0 commit comments

Comments
 (0)