Skip to content

Commit d9c17d7

Browse files
committed
Tests enhancement.
1 parent 911ba72 commit d9c17d7

File tree

6 files changed

+69
-12
lines changed

6 files changed

+69
-12
lines changed

biojava-core/src/main/java/org/biojava/nbio/core/search/io/Hsp.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public abstract class Hsp <S extends Sequence<C>, C extends Compound> {
5454
/**
5555
* Experimental.
5656
* Wants to return an hashcode designed to allow conceptual comparisons of search results.
57+
* Wants to implement conceptual comparisons of search results.
5758
* Fields unrelated to search are deliberately not considered.
5859
* @return
5960
*/
@@ -65,6 +66,8 @@ public int hashCode(){
6566
@Override
6667
public boolean equals(Object o){
6768
if (!(o instanceof Hsp)) return false;
69+
Hsp other = (Hsp)o;
70+
//if (this.getRepresentationString()==null || other.getRepresentationString()==null) return false;
6871

6972
return o.hashCode() == this.hashCode();
7073
}
@@ -85,6 +88,8 @@ public SequencePair<S,C> getAlignment(){
8588
}
8689

8790
private Sequence getSequence(String gappedSequenceString){
91+
if (gappedSequenceString == null) return null;
92+
8893
Sequence returnSeq = null;
8994
String sequenceString = gappedSequenceString.replace("-", "");
9095

biojava-core/src/main/java/org/biojava/nbio/core/search/io/Result.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public Result(String program, String version, String reference, String dbFile, H
5050
/**
5151
* Experimental.
5252
* Wants to return an hashcode designed to allow conceptual comparisons of search results.
53+
* Wants to implement conceptual comparisons of search results.
5354
* Fields unrelated to search are deliberately not considered.
5455
* @return
5556
*/

biojava-core/src/test/java/org/biojava/nbio/core/search/io/HspTest.java

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ public class HspTest {
4141
.setHspIdentityString("||||||||| |||||||||||||||||| ||||||||| |||||||||||||||||||||||| |||||||| ||||||||||||||||||||||| ||||||| |||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||| ||||||||| ||||||| |||||||||||||||||||||||| |||||")
4242
.createBlastHsp();
4343

44+
Hsp uncompleteHsp = new BlastHspBuilder()
45+
.setPercentageIdentity(100.00/100)
46+
.setHspAlignLen(48)
47+
.setMismatchCount(0)
48+
.setHspGaps(0)
49+
.setHspQueryFrom(1)
50+
.setHspQueryTo(48)
51+
.setHspHitFrom(344)
52+
.setHspHitTo(391)
53+
.setHspEvalue(4e-19)
54+
.setHspBitScore(95.6)
55+
.createBlastHsp();
56+
4457
public HspTest() {
4558
}
4659

@@ -66,10 +79,34 @@ public void tearDown() {
6679
@Test
6780
public void testHashCode() {
6881
System.out.println("hashCode");
69-
Hsp instance = hspImpl;
70-
int expResult = 879126434;
71-
int result = instance.hashCode();
82+
Hsp instance;
83+
int expResult;
84+
int result;
85+
86+
instance = hspImpl;
87+
expResult = 71782805;
88+
result = instance.hashCode();
89+
assertEquals(expResult, result);
90+
91+
instance = uncompleteHsp;
92+
expResult = 679;
93+
result = instance.hashCode();
7294
assertEquals(expResult, result);
95+
96+
Hsp uncompleteHsp2 = new BlastHspBuilder()
97+
.setPercentageIdentity(100.00/100)
98+
.setHspAlignLen(48)
99+
.setMismatchCount(0)
100+
.setHspGaps(0)
101+
.setHspQueryFrom(1)
102+
.setHspQueryTo(48)
103+
.setHspHitFrom(344)
104+
.setHspHitTo(391)
105+
.setHspEvalue(4e-19)
106+
.setHspBitScore(95.6)
107+
.createBlastHsp();
108+
109+
assertFalse(uncompleteHsp.hashCode() == uncompleteHsp2.hashCode());
73110
}
74111

75112
/**
@@ -78,7 +115,8 @@ public void testHashCode() {
78115
@Test
79116
public void testEquals() {
80117
System.out.println("equals");
81-
Object o = new BlastHspBuilder()
118+
Object o;
119+
o = new BlastHspBuilder()
82120
.setHspNum(1)
83121
.setHspBitScore(377.211)
84122
.setHspEvalue(8.04143e-093)
@@ -98,6 +136,24 @@ public void testEquals() {
98136
Hsp instance = hspImpl;
99137

100138
assertEquals(o, instance);
139+
140+
// example of Hsp retrieved from uncomplete report. The result is null, hance false
141+
// (Those HSP may come from a tabular format, for example)
142+
o = new BlastHspBuilder()
143+
.setPercentageIdentity(100.00/100)
144+
.setHspAlignLen(48)
145+
.setMismatchCount(0)
146+
.setHspGaps(0)
147+
.setHspQueryFrom(1)
148+
.setHspQueryTo(48)
149+
.setHspHitFrom(344)
150+
.setHspHitTo(391)
151+
.setHspEvalue(4e-19)
152+
.setHspBitScore(95.6)
153+
.createBlastHsp();
154+
155+
// At now, check will return false as it could be not determined
156+
assertFalse(uncompleteHsp.equals(o));
101157
}
102158

103159
/**

biojava-core/src/test/java/org/biojava/nbio/core/search/io/SearchIOTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void testConstructorWithFactoryGuess() {
6060
*/
6161
@Test
6262
public void testConstructorWithoutFactoryGuess() {
63-
String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.xml";
63+
String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.blastxml";
6464
URL resourceURL = getClass().getResource(resource);
6565
File file = new File(resourceURL.getFile());
6666

@@ -78,7 +78,7 @@ public void testConstructorWithoutFactoryGuess() {
7878
@Test
7979
public void testConstructorWithEvalueHspFilter() {
8080
//
81-
String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.xml";
81+
String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.blastxml";
8282
URL resourceURL = getClass().getResource(resource);
8383
File file = new File(resourceURL.getFile());
8484

biojava-core/src/test/java/org/biojava/nbio/core/search/io/blast/BlastXMLQueryTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
package org.biojava.nbio.core.search.io.blast;
77

88
import java.io.File;
9-
import java.io.FileOutputStream;
10-
import java.io.IOException;
11-
import java.io.InputStream;
12-
import java.io.OutputStream;
139
import java.net.URL;
14-
import java.util.ArrayList;
1510
import java.util.List;
1611
import org.biojava.nbio.core.search.io.Hit;
1712
import org.biojava.nbio.core.search.io.Hsp;
@@ -67,7 +62,7 @@ public void testSetFile() {
6762
public void testCreateObjects() throws Exception {
6863
System.out.println("createObjects");
6964

70-
String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.xml";
65+
String resource = "/org/biojava/nbio/core/search/io/blast/testBlastReport.blastxml";
7166
URL resourceURL = getClass().getResource(resource);
7267
File file = new File(resourceURL.getFile());
7368

biojava-core/src/test/resources/org/biojava/nbio/core/search/io/blast/testBlastReport.xml renamed to biojava-core/src/test/resources/org/biojava/nbio/core/search/io/blast/testBlastReport.blastxml

File renamed without changes.

0 commit comments

Comments
 (0)