Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Additional testcases #340

Merged
merged 7 commits into from
Jan 11, 2023
10 changes: 7 additions & 3 deletions src/main/java/DNAnalyzer/core/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ public static void printProteinList(final List<String> proteinList, final String
* "https://www.sciencedirect.com/topics/biochemistry-genetics-and-molecular-biology/gc-content"
*/
public static float getGCContent(String dna) {
float gcContent=0;
if(dna.length()==0)
return gcContent;

dna = dna.toLowerCase();
float gcLen = (float) calculateLengthOfCG(dna);
float gcContent = gcLen / dna.length();
gcContent = gcLen / dna.length();

return gcContent;
}
Expand Down Expand Up @@ -143,8 +147,8 @@ public static boolean isRandomDNA(final String dna) {
/**
* Checks if the differnce between two numbers is less or equal to 2
*
* @param aNumber one number to calculate the difference
* @param anotherNumber the other number to calculate the difference
* @param maxPercent one number to calculate the difference
* @param minPercent the other number to calculate the difference
* @return Whether the difference is less or equal to 2
* @category Properties
*/
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/DNAnalyzer/ProteinFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
import DNAnalyzer.utils.protein.ProteinFinder;

class ProteinFinderTest {
Path testFile = Path.of("C:\\Users\\garyg\\Documents\\projects\\DNAnalyzer\\assets\\dna\\random\\dnalong.fa");
Path projectPath = Path.of("");
Path dnaLongTestInput = projectPath.resolve("assets/dna/random/dnalong.fa");

@Test
void testGetProtein() {
try {
List<String> inputLines = Files.readAllLines(dnaLongTestInput);
List<String> expected = new ArrayList<String>();
List<String> expected = new ArrayList<>();
expected.add("AATTCCCTACAACGGATGCGCCGCTGATAGACTCGGGTTCTGGCGTCCGAGTGAAGATGATAA");
expected.add(
"AACCAATCTCATGATCACCAGTTCTGACGTTACAGTATTTTCGGTTGAGCAGGCCCCATGGGGCCCCCGCATGCCGAATTACGATATGATGCCCACTATCCTGTGTCTTCCAACCTTATGACTGACTTGTATGCGCTGCGAGGTCCCTCGATAGATTTGCTCCCACCCGTCCCGGAAACCATATCGACGACTTGTAGGTCTCTAA");
Expand Down
99 changes: 99 additions & 0 deletions src/test/java/DNAnalyzer/core/PropertiesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package DNAnalyzer.core;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.jupiter.api.Assertions.*;

class PropertiesTest {

Path projectPath = Path.of("");
Path dnaLongTestInput = projectPath.resolve("assets/dna/random/dnalong.fa");

String dnaString="";
@BeforeEach
void setUp() {
try {
List<String> inputLines = Files.readAllLines(dnaLongTestInput);
dnaString = inputLines.get(0);
} catch (IOException ex) {
Logger.getLogger(PropertiesTest.class.getName()).log(Level.SEVERE, null, ex);
}
}

@Test
void shouldGetGCContent() {
double expected = 0.5000109;
float actual = Properties.getGCContent(dnaString);
assertEquals(expected, actual,0.01);

}

@Test
void shouldGetGCContentAsZero() {
// List<String> inputLines = Files.readAllLines(dnaLongTestInput);
String testEmptyString = "";
double expected = 0;
float actual = Properties.getGCContent(testEmptyString);
assertEquals(expected, actual);
}

@Test
void sholudCalculateLengthOfCG() {
int expected = 50001033;
int actual = Properties.calculateLengthOfCG(dnaString);
assertEquals(expected, actual);
}

@Test
void sholudCalculateLengthOfCGAsZero() {
String testEmptyString = "";
int expected = 0;
int actual = Properties.calculateLengthOfCG(testEmptyString);
assertEquals(expected, actual);
}
@Test
void shouldLetterIsCorGReturnTrue() {
boolean actual = Properties.letterIsCorG('c');
assertTrue(actual);
}

@Test
void shouldLetterIsCorGReturnFalse() {
boolean actual = Properties.letterIsCorG('b');
assertFalse(actual);
}

@Test
void shouldIsRandomDNAReturnTrue() {
boolean actual = Properties.isRandomDNA(dnaString);
assertTrue(actual);
}

// @Test
// void shouldIsRandomDNAReturnFalse() {
// String testEmptyString = "";
// boolean actual = Properties.isRandomDNA(testEmptyString);
// assertFalse(actual);
// }

@Test
void shouldIsDifferenceLessOrEqualTo2ReturnTrue() {
boolean actual = Properties.isDifferenceLessOrEqualTo2(10,9);
assertTrue(actual);
}

@Test
void shouldIsDifferenceLessOrEqualTo2ReturnFalse() {
boolean actual = Properties.isDifferenceLessOrEqualTo2(10,1);
assertFalse(actual);
}

}
64 changes: 64 additions & 0 deletions src/test/java/DNAnalyzer/utils/core/DNAToolsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package DNAnalyzer.utils.core;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.jupiter.api.Assertions.*;

class DNAToolsTest {

DNATools dnaTools;
String dnaString;
Path projectPath = Path.of("");
Path dnaLongTestInput = projectPath.resolve("assets/dna/random/dnalong.fa");

@BeforeEach
void setUp() {
try {
List<String> inputLines = Files.readAllLines(dnaLongTestInput);
dnaString = inputLines.get(0);

} catch (IOException ex) {
Logger.getLogger(DNAToolsTest.class.getName()).log(Level.SEVERE, null, ex);
}
}

@Test
void shouldIsValidThrowException() {
dnaTools = new DNATools("");
var expected = "Invalid characters present in DNA sequence.";
Exception exception = assertThrows(IllegalArgumentException.class, ()->dnaTools.isValid() );
assertEquals(expected, exception.getMessage());
}

@Test
void shouldIsValidNotThrowException() {
dnaTools = new DNATools("atgc");
assertDoesNotThrow(()->dnaTools.isValid() );
}

@Test
void shouldReplaceDNAString() {
var expected = "AAAacggctcaaaacca";
dnaTools = new DNATools("gagacggctcaaaacca");
var newDnaTools = dnaTools.replace("gag", "AAA");
var actual = newDnaTools.getDna();
assertEquals(expected,actual);
}

@Test
void shouldReverseDNAString() {
var expected = "cagag";
dnaTools = new DNATools("gagac");
var newDnaTools = dnaTools.reverse();
var actual = newDnaTools.getDna();
assertEquals(expected,actual);
}
}
29 changes: 29 additions & 0 deletions src/test/java/DNAnalyzer/utils/core/ReadingFramesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package DNAnalyzer.utils.core;

import DNAnalyzer.data.codon.CodonFrame;
import org.junit.jupiter.api.BeforeEach;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;


class ReadingFramesTest {

ReadingFrames readingFrames;
Path projectPath = Path.of("");
Path dnaLongTestInput = projectPath.resolve("assets/dna/random/dnalong.fa");

@BeforeEach
void setUp() {
try {
List<String> inputLines = Files.readAllLines(dnaLongTestInput);
readingFrames= new ReadingFrames(new CodonFrame(inputLines.get(0), (short) 1, 2, 100));

} catch (IOException e) {
throw new RuntimeException(e);
}
}

}
31 changes: 31 additions & 0 deletions src/test/java/DNAnalyzer/utils/protein/ProteinAnalysisTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package DNAnalyzer.utils.protein;

import org.junit.jupiter.api.BeforeEach;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


class ProteinAnalysisTest {

Path projectPath = Path.of("");
Path dnaLongTestInput = projectPath.resolve("assets/dna/random/dnalong.fa");

String dnaString="";

@BeforeEach
void setUp() {
try {
List<String> inputLines = Files.readAllLines(dnaLongTestInput);
dnaString = inputLines.get(0);
} catch (IOException ex) {
Logger.getLogger(ProteinAnalysisTest.class.getName()).log(Level.SEVERE, null, ex);
}

}

}