Untitled
Anonymous
plain_text
02/26/2026 2:23 AM
8.2 KB
11
Indexable
import student.TestCase;
import student.testingsupport.annotations.ScoringWeight;
/**
* @author CS3114/5040 staff
* @version Spring 2026
*/
public class DNAProjTest extends TestCase {
private DNA it;
/**
* Sets up the tests that follow. In general, used for initialization
*/
public void setUp() {
it = new DNADB();
}
/**
* Test output formatting
*/
/**
public void testSampleInput() {
assertFuzzyEquals(
"Sequence |ACGT| inserted",
it.insert("ACGT"));
assertFuzzyEquals(
"Sequence |ACGT| already exists",
it.insert("ACGT"));
assertFuzzyEquals(
"Sequence |ACGT| removed",
it.remove("ACGT"));
assertFuzzyEquals(
"Sequence |AAAA| inserted",
it.insert("AAAA"));
assertFuzzyEquals(
"Sequence |AA| inserted",
it.insert("AA"));
assertFuzzyEquals(
"Sequence |ACG| does not exist",
it.remove("ACG"));
assertFuzzyEquals(
"tree dump:\r\n"
+ "I\r\n"
+ " I\r\n"
+ " I\r\n"
+ " AAAA\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " AA\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E",
it.print());
assertFuzzyEquals(
"tree dump with lengths:\r\n"
+ "I\r\n"
+ " I\r\n"
+ " I\r\n"
+ " AAAA 4\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " AA 2\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E",
it.printLengths());
assertFuzzyEquals(
"tree dump with stats:\r\n"
+ "I\r\n"
+ " I\r\n"
+ " I\r\n"
+ " AAAA A:100.00 C:0.00 G:0.00 T:0.00\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " AA A:100.00 C:0.00 G:0.00 T:0.00\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E\r\n"
+ " E",
it.printStats());
assertFuzzyEquals(
"AAAA\r\n"
+ "# of nodes visited: 4",
it.search("AAAA$"));
assertFuzzyEquals(
"AAAA\r\n"
+ "AA\r\n"
+ "# of nodes visited: 8",
it.search("AA"));
assertFuzzyEquals(
"No sequence found\r\n"
+ "# of nodes visited: 3",
it.search("ACGT$"));
}
**/
/**
* Example tests for bad input error formatting
*/
@ScoringWeight(10.0)
public void testBadInput() {
assertFuzzyEquals(
"Bad input: Sequence may not be null\r\n",
it.insert(null));
assertFuzzyEquals(
"Bad input: Sequence may not be empty\r\n",
it.insert(""));
assertFuzzyEquals(
"Bad Input Sequence |AXA|\r\n",
it.insert("AXA"));
}
/**
* Tests that remove() correctly handles an empty string input.
* Verifies that the proper bad input message is returned
* when attempting to remove an empty DNA sequence.
*/
public void testRemoveBad() {
assertFuzzyEquals(
"Bad input: Sequence may not be empty\r\n",
it.remove(""));
}
/**
* Tests that search() correctly handles invalid characters.
* Ensures that a sequence containing non-DNA characters
* returns the proper formatted bad input error message.
*/
public void testSearchBad() {
assertFuzzyEquals(
"Bad Input Sequence |XYZ|\r\n",
it.search("XYZ"));
}
/**
* Tests that print() returns output containing the expected
* tree dump header. This verifies that the method does not
* return null and includes the required formatting string.
*/
public void testPrint() {
assertTrue(it.print().contains("tree dump"));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests to increase mutation tests
public void testInsertValid() {
assertFuzzyEquals(
"Sequence |AAAA| inserted",
it.insert("AAAA"));
}
public void testRemoveValidNotFound() {
assertFuzzyEquals(
"Sequence |TTT| does not exist",
it.remove("TTT"));
}
public void testSearchValidNotFound() {
assertFuzzyEquals(
"No sequence found\r\n# of nodes visited: 1",
it.search("ACGT$"));
}
public void testLongSequence() {
assertFuzzyEquals(
"Sequence |ACGTACGTACGT| inserted",
it.insert("ACGTACGTACGT"));
}
public void testPrintLengths() {
assertTrue(it.printLengths().contains("tree dump with lengths"));
}
public void testPrintStats() {
assertTrue(it.printStats().contains("tree dump with stats"));
}
public void testMoreBadInput(){
assertFuzzyEquals("Bad Input Sequence |A A|\r\n", it.insert("A A"));
assertFuzzyEquals("Bad Input Sequence |A |\r\n", it.insert("A "));
assertFuzzyEquals("Bad Input Sequence |A$|\r\n", it.insert("A$"));
assertFuzzyEquals("Bad input sequence |A$A|\r\n", it.search("A$A"));
}
public void testSearchEmptyPrefixValid() {
assertFuzzyEquals(
"No sequence found\r\n# of nodes visited: 1",
it.search(""));
}
}Editor is loading...
Leave a Comment