Skip to content

Commit

Permalink
moved from junit-3.8.1 to junit-4, added log4j.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Wagner committed Jan 31, 2012
1 parent 9d4ec89 commit 64bbd9a
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test_src"/>
<classpathentry kind="lib" path="lib/junit-3.8.1.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.9.jar"/>
<classpathentry kind="lib" path="lib/cpsuite-1.2.5.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
14 changes: 8 additions & 6 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,20 @@

<!-- JUnit testing framework -->
<target name="junit" depends="compile">
<java fork="yes" classname="junit.textui.TestRunner"
taskname="junit" failonerror="true">

<arg value="org.arabidopsis.interval.AllTests"/>
<junit printsummary="withOutAndErr" haltonfailure="yes">
<classpath>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
<path location="${build}"/>
<path location="."/>
</classpath>
<assertions><enable/></assertions>
</java>
<batchtest fork="yes">
<fileset dir="${test.src}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>


Expand Down
Binary file added lib/cpsuite-1.2.5.jar
Binary file not shown.
Binary file removed lib/junit-3.8.1.jar
Binary file not shown.
Binary file added lib/junit-4.11-SNAPSHOT.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# minimal log4j configuration
# almost equivalent to BasicConfigurator.configure()

log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%r %p [%t] %c - %m%n
88 changes: 5 additions & 83 deletions test_src/org/arabidopsis/interval/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,11 @@

/**
*
* Suite of all tests. Uses some Junit magic.
* Suite of all tests.
*
*
* @param
* @return
* @exception
* @see
*/

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.runner.LoadingTestCollector;
import junit.runner.TestCollector;


public class AllTests extends TestCase {
public AllTests(String name) {
super(name);
}


/**
*
* Returns a suite of all the tests we can find.
*
*
*/
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite();

List<Class<? extends TestCase>> allTestClasses = getAllTestClasses();
for(int i = 0 ; i < allTestClasses.size(); i++) {
suite.addTestSuite(allTestClasses.get(i));
}

return suite;
}



/**
*
* Adds all the tests we can find (excluding ourselves, of course) in
* the CLASSPATH.
*
*
* @param
* @return
* @exception
* @see
*/
private static List<Class<? extends TestCase>> getAllTestClasses() throws ClassNotFoundException {
final TestCollector collector = new LoadingTestCollector();
@SuppressWarnings("unchecked")
final java.util.Enumeration<String> e = collector.collectTests();
final List<Class<? extends TestCase>> testClasses = new ArrayList<Class<? extends TestCase>>();
while (e.hasMoreElements()) {
final String className = e.nextElement();
final Class<? extends TestCase> c = Class.forName(className).asSubclass(TestCase.class);
// don't add ourself
if (isSelfClass(c) || isClassNotInMyPackage(c)) {
continue;
}
testClasses.add(c);
}
return testClasses;
}


// Returns true if the given class is ourself.
private static boolean isSelfClass(Class<?> c) {
return c.equals(AllTests.class);
}


// Returns true if the class c is not within the same package
// hierarchy as ourselves.
private static boolean isClassNotInMyPackage(Class<?> c) {
return (! c.getPackage().getName().startsWith
(AllTests.class.getPackage().getName()));
}

}
import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class AllTests {}
15 changes: 12 additions & 3 deletions test_src/org/arabidopsis/interval/FlankingFinderTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package org.arabidopsis.interval;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;


public class FlankingFinderTest extends TestCase {
public class FlankingFinderTest {
private FlankingFinder<String> finder;


@Before
public void setUp() {
this.finder = new FlankingFinder<String>();
}


@Test
public void testEmptyCase() {
assertEquals(new ArrayList<String>(),
this.finder.flankingLeft(42, 1));
Expand All @@ -24,6 +28,7 @@ public void testEmptyCase() {
}


@Test
public void testNoFinding() {
this.finder.add("hello", 10, 20);
assertEquals(new ArrayList<String>(),
Expand All @@ -33,6 +38,7 @@ public void testNoFinding() {
}


@Test
public void testSimpleFinding() {
this.finder.add("hello", 10, 20);
List<String> expected = new ArrayList<String>();
Expand All @@ -44,6 +50,7 @@ public void testSimpleFinding() {
}


@Test
public void testSomeSimpleCases() {
this.finder.add("At1g01030.1", 11649, 13611);
this.finder.add("At1g01040.1", 23146, 31164);
Expand Down Expand Up @@ -75,6 +82,7 @@ public void testSomeSimpleCases() {



@Test
public void testFlankingLeftWithDuplicates() {
int bignumber = 1000;
for (int i = 0; i < bignumber; i++) {
Expand All @@ -90,6 +98,7 @@ public void testFlankingLeftWithDuplicates() {



@Test
public void testFlankingRightWithDuplicates() {
int bignumber = 1000;
for (int i = 0; i < bignumber; i++) {
Expand Down
28 changes: 26 additions & 2 deletions test_src/org/arabidopsis/interval/IntervalTreeTest.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,78 @@
package org.arabidopsis.interval;

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

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class IntervalTreeTest extends TestCase {
public class IntervalTreeTest {
private IntervalTree tree;

@Before
public void setUp() {
this.tree = new IntervalTree();
}

@After
public void tearDown() {
this.tree = null;
}


@Test
public void testEmptyCase() {
assertEquals(null, this.tree.search(new Interval(0, 42)));
}


@Test
public void testSimpleOverlapCaseOnEqual() {
tree.insert(new Interval(1, 5));
assertEquals(new Interval(1, 5), this.searchInterval(1, 5));
}


@Test
public void testSimpleOverlapCaseOnLeft() {
tree.insert(new Interval(1, 5));
assertEquals(new Interval(1, 5), this.searchInterval(0, 3));
}


@Test
public void testSimpleOverlapCaseOnRight() {
tree.insert(new Interval(1, 5));
assertEquals(new Interval(1, 5), this.searchInterval(3, 6));
}

@Test
public void testSimpleOverlapCaseOnEnclosed() {
tree.insert(new Interval(1, 5));
assertEquals(new Interval(1, 5), this.searchInterval(2, 3));
}


@Test
public void testSimpleOverlapCaseOnSurrounding() {
tree.insert(new Interval(1, 5));
assertEquals(new Interval(1, 5), this.searchInterval(0, 6));
}


@Test
public void testSimpleUnsuccessfulMatchOnRight() {
tree.insert(new Interval(1, 5));
assertEquals(null, this.searchInterval(6, 10));
}


@Test
public void testSimpleUnsuccessfulMatchOnLeft() {
tree.insert(new Interval(2, 5));
assertEquals(null, this.searchInterval(0, 1));
Expand Down Expand Up @@ -97,6 +112,7 @@ private void prepareTestCaseTree() {
// Just a quick function to make sure that the checkValidity
// function is up and running. isValid() should ALWAYS be true,
// unless I screwed up with the implementation somehow.
@Test
public void testValidityOfTestCaseTree() {
assertTrue(tree.isValid());
prepareTestCaseTree();
Expand All @@ -106,6 +122,7 @@ public void testValidityOfTestCaseTree() {


// check to see that duplicate intervals work out ok structurally.
@Test
public void testExpectedSizeWithDuplicates() {
prepareTestCaseTree();
int n = tree.size();
Expand All @@ -120,6 +137,7 @@ public void testExpectedSizeWithDuplicates() {



@Test
public void testWithPreparedTree() {
prepareTestCaseTree();
assertEquals(new Interval(0, 3), searchInterval(-1, 4));
Expand All @@ -129,6 +147,7 @@ public void testWithPreparedTree() {
}


@Test
public void testMultipleSearch() {
prepareTestCaseTree();
final List<Interval> expected = new ArrayList<Interval>();
Expand All @@ -139,13 +158,15 @@ public void testMultipleSearch() {
}


@Test
public void testUnsuccessfulMultipleSearch() {
prepareTestCaseTree();
final List<Interval> expected = new ArrayList<Interval>();
assertEquals(expected, searchAllIntervals(11, 14));
}


@Test
public void testSingleMatchWithMultipleSearch() {
prepareTestCaseTree();
final List<Interval> expected = new ArrayList<Interval>();
Expand All @@ -156,6 +177,7 @@ public void testSingleMatchWithMultipleSearch() {


// If we double up each interval, we expect to see the same elements
@Test
public void testSingleMatchWithMultipleSearchAndDuplicates() {
prepareTestCaseTree();
prepareTestCaseTree();
Expand All @@ -170,6 +192,7 @@ public void testSingleMatchWithMultipleSearchAndDuplicates() {



@Test
public void testSearchAllOnWholeResults() {
List<Interval> expected = new ArrayList<Interval>();
int bignumber = 30000;
Expand All @@ -195,6 +218,7 @@ public void testSearchAllOnWholeResults() {



@Test
public void testWithLotsOfOverlapping() {
int bignumber = 1000;
for(int i = 0; i < bignumber; i++) {
Expand Down
Loading

0 comments on commit 64bbd9a

Please sign in to comment.