Skip to content

Commit

Permalink
Added a method to check that two elements are in the same cell of a p…
Browse files Browse the repository at this point in the history
…artition

Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
gilleain authored and egonw committed Nov 29, 2012
1 parent 22c75eb commit 8726639
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/org/openscience/cdk/group/Partition.java
Expand Up @@ -423,6 +423,25 @@ public int compare(SortedSet<Integer> cellA, SortedSet<Integer> cellB) {

});
}


/**
* Check that two elements are in the same cell of the partition.
*
* @param elementI an element in the partition
* @param elementJ an element in the partition
* @return true if both elements are in the same cell
*/
@TestMethod("inSameCellTest")
public boolean inSameCell(int elementI, int elementJ) {
for (int cellIndex = 0; cellIndex < size(); cellIndex++) {
SortedSet<Integer> cell = getCell(cellIndex);
if (cell.contains(elementI) && cell.contains(elementJ)) {
return true;
}
}
return false;
}

/**
* @inheritDoc
Expand Down
6 changes: 6 additions & 0 deletions src/test/org/openscience/cdk/group/PartitionTest.java
Expand Up @@ -302,5 +302,11 @@ public void orderTest() {
Assert.assertTrue(cell0.first() < cell1.first());
Assert.assertTrue(cell0.last() < cell1.last());
}

@Test
public void inSameCellTest() {
Partition p = new Partition(new int[][]{{0, 2}, {1, 3}});
Assert.assertTrue(p.inSameCell(1, 3));
}

}

0 comments on commit 8726639

Please sign in to comment.