Permalink
Browse files

Finally correct junit annotations, and sort test

  • Loading branch information...
1 parent 7e370a2 commit fba5ff5a2328ec5e28a6d92a5759a1bed118de44 @gilleain gilleain committed with egonw Jun 15, 2010
Showing with 38 additions and 4 deletions.
  1. +38 −4 src/test/org/openscience/cdk/signature/OrbitTest.java
@@ -27,7 +27,7 @@
import junit.framework.Assert;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -37,10 +37,12 @@
*/
public class OrbitTest {
- private static Orbit orbit;
+ private Orbit orbit;
- @BeforeClass
- public static void setUp() {
+ private Orbit unsortedOrbit;
+
+ @Before
+ public void setUp() {
// make a test orbit instance, with a nonsense
// string label, and some number of 'indices'
@@ -51,6 +53,16 @@ public static void setUp() {
for (int atomIndex : atomIndices) {
orbit.addAtom(atomIndex);
}
+
+ // also make an unsorted orbit
+ String unsortedOrbitLabel = "UNSORTED_ORBIT";
+ int unsortedHeight = 2;
+ unsortedOrbit = new Orbit(unsortedOrbitLabel, unsortedHeight);
+ int[] unsortedAtomIndices = new int[] {3, 1, 0, 2};
+ for (int atomIndex : unsortedAtomIndices) {
+ unsortedOrbit.addAtom(atomIndex);
+ }
+
}
@Test
@@ -61,6 +73,7 @@ public void testClone() {
List<Integer> clonedIndices = new ArrayList<Integer>();
for (int i : clonedOrbit) { clonedIndices.add(i); }
Assert.assertEquals(indices, clonedIndices);
+ Assert.assertEquals(orbit.getLabel(), clonedOrbit.getLabel());
}
@Test
@@ -77,6 +90,27 @@ public void isEmptyTest() {
Assert.assertTrue("Orbit should now be empty", orbit.isEmpty());
}
+ private boolean isSorted(Orbit orbit) {
+ int prev = -1;
+ for (int index : orbit) {
+ if (prev == -1 || index > prev) {
+ prev = index;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Test
+ public void sortTest() {
+ Assert.assertFalse(
+ "Unsorted orbit is actually sorted", isSorted(unsortedOrbit));
+ unsortedOrbit.sort();
+ Assert.assertTrue(
+ "Orbit is not sorted after sort called", isSorted(unsortedOrbit));
+ }
+
@Test
public void containsTest() {
for (int index : orbit) {

0 comments on commit fba5ff5

Please sign in to comment.