Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment has a DNA_Strand.h. file that contains the declaration of a set

ID: 3742039 • Letter: T

Question

This assignment has a DNA_Strand.h. file that contains the declaration of a set of functions to manipulate static arrays representing DNA. There is another initial test program: DNAtest.cpp. The assignment is to add code to the DNAtest.cpp file to fully test the DNA_Strand class to ensure it works as expected. The task is to only test the DNA_Strand class, not to implement the DNA_Strand class. All the functions that need to be tested are fully described in the DNA_Strand.h file.

DNA_Strand.h.

DNAtest.cpp.

The DNA Strand class: This class is a simplification of the chemical process, but provides an example of the DNA manipulation using simple arrays. The provided class uses a static array containing character, such as the letters ‘A', ‘C','T', and 'G", to represent the sequence of nucleotides within a DNA strand (though not limited to only the letters*A','C','T', and 'G') Sample representation of a DNA molecule Note that the array may be larger than the strand that we are representing, and thus there may be unused array elements after the nucleotides within the strand [this is known as a partially-filled array; in this example we have an array that can hold 23 characters which is currently only holding 20 characters, the question marks indicate unused array elements whose values we don't know or care about] Cleavage by a restriction enzyme will simply mean removing a specified sequence from our DNA strand. Cleaving requires a target nucleotide pattern. The sequence to be removed will be the nucleotides that reside between matching pairs of the target pattern. A cleave will remove all nucleotides beginning after the first occurrence of the target pattern and continue through the end of the second (matching) target pattern. The class provides 2 functions cleave and cleaveAl, which will implement cleaving in 2 different forms. The cleave method will cleave only the first such sequence while cleaveAll method will remove all such sequences between matching pairs within the DNA strand. Thus, for example, if we invoke cleave("TTG") on the above DNA strand, we would remove the first set of highlighted characters and the resultant DNA strand will be Notice how the data was shifted down to fill the hole created by the deleted sequence. In comparison, if we invoke cleaveAll("TTG") on the original DNA strand above, we would remove both sets of highlighted characters and the resultant DNA strand will be A CTT G G G T T G C C? The nucleotides in our DNA are character values, so the class uses an array of type char. The array is of size MAX_DNA (a constant variable set to 50 -a value too small for real DNA but it makes our testing easier) and so we will be limited to holding DNA with a maximum number of nucleotides of MAX_DNA. The class also has a private instance variable called mySize which will keep track of the size of the strand (i.e., how many elements we are actually using of the partially-filled array)

Explanation / Answer

#include <iostream>

#include <stdexcept>

#include "DNA_Strand.h"

int main()

{

//default constructor test

DNA_Strand dna_1;

if(dna_1==NULL){

std::cout << "Default Constructor test FAIL" << std::endl;

}

elseif(dna_1.size()==0){

std::cout << "Default Constructor test PASSED" << std::endl;

}

else{

std::cout << "Default Constructor test FAIL" << std::endl;

}

//String argument constructor test

DNA_Strand dna_2("ABCCTG");

if(dna_2==NULL){

std::cout << "String argument Constructor test FAIL" << std::endl;

}

elseif(dna_2.size()==6){

std::cout << "String argument Constructor test PASSED" << std::endl;

}

else{

std::cout << "String argument Constructor test FAIL" << std::endl;

}

//toString test

if(strcmp(dna_2.toString(),"ABCCTG")==0){

std::cout << "toString test PASSED" << std::endl;

}

else{

std::cout << "toString test FAIL" << std::endl;

}

//set Test

try {

dna_2.set('R',2);

if(strcmp(dna_2.toString(),"ABRCTG")==0){

std::cout << "set test PASSED" << std::endl;

}

else{

std::cout << "set test FAIL" << std::endl;

}

}

catch (std::out_of_range& excpt) {

std::cout << "set test FAIL" << std::endl;

}

catch (...) {

std::cout << "set test FAIL" << std::endl;

}

try {

dna_2.set('U',20);

std::cout << "set test FAIL" << std::endl;

}

catch (std::out_of_range& excpt) {

std::cout << "Exception was properly thrown and caught :: "

<< "set test PASSED"<< std::endl;

}

catch (...) {

std::cout << "EXCEPTION ERROR -- set test FAILED threw the wrong exception."

<< std::endl;

}

//get test

try {

char c=dna_2.get(2);

if(c=='R'){

std::cout << "get test PASSED" << std::endl;

}

else{

std::cout << "get test FAIL" << std::endl;

}

}

catch (std::out_of_range& excpt) {

std::cout << "get test FAIL" << std::endl;

}

catch (...) {

std::cout << "get test FAIL" << std::endl;

}

try {

char c=dna_2.get(20);

std::cout << "get test FAIL" << std::endl;

}

catch (std::out_of_range& excpt) {

std::cout << "Exception was properly thrown and caught :: "

<< "get test PASSED"<< std::endl;

}

catch (...) {

std::cout << "EXCEPTION ERROR -- get test FAILED threw the wrong exception."

<< std::endl;

}

//isEqual Test

DNA_Strand dna_3("ABRCTG");

if(dna_2.isEqual(dna_3)){

std::cout << "isEqual test PASSED" << std::endl;

}

else{

std::cout << "isEqual test FAIL" << std::endl;

}

if(!dna_2.isEqual(dna_1)){

std::cout << "isEqual test PASSED" << std::endl;

}

else{

std::cout << "isEqual test FAIL" << std::endl;

}

//Search Test

DNA_Strand dna_4("RCT");

DNA_Strand dna_5("QFD");

if(dna_2.search(dna_4)==2){

std::cout << "search test PASSED" << std::endl;

}

else{

std::cout << "search test FAIL" << std::endl;

}

if(dna_2.search(dna_5)==-1){

std::cout << "search test PASSED" << std::endl;

}

else{

std::cout << "search test FAIL" << std::endl;

}

//search with start position specified test

if(dna_2.search(dna_4,0)==2){

std::cout << "search test PASSED" << std::endl;

}

else{

std::cout << "search test FAIL" << std::endl;

}

if(dna_2.search(dna_5,0)==-1){

std::cout << "search test PASSED" << std::endl;

}

else{

std::cout << "search test FAIL" << std::endl;

}

if(dna_2.search(dna_4,3)==-1){

std::cout << "search test PASSED" << std::endl;

}

else{

std::cout << "search test FAIL" << std::endl;

}

//cleave Test

DNA_Strand dna_6("ACTTGACCTTGA");

DNA_Strand dna_7("TTG");

dna_6.cleave(dna_7);

if(strcmp(dna_6.toString(),"ACTTGA")==0){

std::cout << "cleave test PASSED" << std::endl;

}

else{

std::cout << "cleave test FAIL" << std::endl;

}

dna_6.cleave(dna_5);

if(strcmp(dna_6.toString(),"ACTTGA")==0){

std::cout << "cleave test PASSED" << std::endl;

}

else{

std::cout << "cleave test FAIL" << std::endl;

}

//cleave with start position specified test

DNA_Strand dna_8("ACTTGACCTTGA");

DNA_Strand dna_9("TTG");

int val= dna_8.cleave(dna_9,7);

if(val==-1){

std::cout << "cleave test PASSED" << std::endl;

}

else{

std::cout << "cleave test FAIL" << std::endl;

}

int val1=dna_8.cleave(dna_9,0);

if(val1==5){

std::cout << "cleave test PASSED" << std::endl;

}

else{

std::cout << "cleave test FAIL" << std::endl;

}

DNA_Strand dna_10("ACTTGACCTTGA");

DNA_Strand dna_11("TQR");

int pos=dna_10.cleave(dna_11,1);

if(pos==-1){

std::cout << "cleave test PASSED" << std::endl;

}

else{

std::cout << "cleave test FAIL" << std::endl;

}

//cleaveall test

DNA_Strand dna_12("ACTTGACCTTGA");

DNA_Strand dna_13("TQR");

dna_12.cleaveAll(dna_13);

if(strcmp(dna_12.toString(),"ACTTGACCTTGA")==0){

std::cout << "cleaveAll test PASSED" << std::endl;

}

else{

std::cout << "cleaveAll test FAIL" << std::endl;

}

DNA_Strand dna_14("ACTTGACCTTGA");

DNA_Strand dna_15("TTG");

dna_14.cleaveAll(dna_15);

if(strcmp(dna_14.toString(),"ACTTGA")==0){

std::cout << "cleaveAll test PASSED" << std::endl;

}

else{

std::cout << "cleaveAll test FAIL" << std::endl;

}

DNA_Strand dna_16("ACTTGATTGGGTTGCTTGCC");

DNA_Strand dna_17("TTG");

dna_16.cleaveAll(dna_17);

if(strcmp(dna_16.toString(),"ACTTGGGTTGCC")==0){

std::cout << "cleaveAll test PASSED" << std::endl;

}

else{

std::cout << "cleaveAll test FAIL" << std::endl;

}

//countEnzyme test

if(dna_17.countEnzyme('T')==2){

std::cout << "countEnzyme test PASSED" << std::endl;

}

else{

std::cout << "countEnzyme test FAILED" << std::endl;

}

if(dna_17.countEnzyme('A')==0){

std::cout << "countEnzyme test PASSED" << std::endl;

}

else{

std::cout << "countEnzyme test FAILED" << std::endl;

}

return 0;

}