t.Errorf("Expected annotations to be %v, got %v",seq.annotations,newSeq.annotations)
}
}
// TestBioSequence_Id tests the Id method of the BioSequence struct.
//
// It initializes a BioSequence with an ID using the constructor and then
// verifies that the Id method returns the expected ID.
// The expected ID is "ABC123".
// The method takes no parameters and returns a string.
funcTestBioSequence_Id(t*testing.T){
// Initialize BioSequence with an ID using the constructor
bioSeq:=NewBioSequence("ABC123",[]byte(""),"")
// Test case: ID is returned correctly
expected:="ABC123"
result:=bioSeq.Id()
ifresult!=expected{
t.Errorf("Expected ID to be %s, but got %s",expected,result)
}
}
// TestBioSequenceDefinition tests the Definition() method of the BioSequence struct.
//
// This function verifies the behavior of the Definition() method in two test cases:
// 1. Empty definition: It creates a BioSequence object with an empty definition and verifies that the Definition() method returns an empty string.
// 2. Non-empty definition: It creates a BioSequence object with a non-empty definition and verifies that the Definition() method returns the expected definition.
funcTestBioSequenceDefinition(t*testing.T){
// Test case 1: Empty definition
seq1:=NewBioSequence("",[]byte{},"")
expected1:=""
ifgot1:=seq1.Definition();got1!=expected1{
t.Errorf("Expected %q, but got %q",expected1,got1)
}
// Test case 2: Non-empty definition
seq2:=NewBioSequence("",[]byte{},"This is a definition")
expected2:="This is a definition"
ifgot2:=seq2.Definition();got2!=expected2{
t.Errorf("Expected %q, but got %q",expected2,got2)
}
}
// TestBioSequenceSequence tests the Sequence() method of the BioSequence struct.
//
// It verifies the behavior of the Sequence() method under two scenarios:
// - Test case 1: Empty sequence
// - Test case 2: Non-empty sequence
//
// Parameter(s):
// - t: The testing object provided by the testing framework.
// It is used to report errors if the test fails.
//
// Return type(s):
// None.
funcTestBioSequenceSequence(t*testing.T){
// Test case 1: Empty sequence
seq:=NewBioSequence("",[]byte{},"")
expected:=[]byte{}
actual:=seq.Sequence()
if!bytes.EqualFold(actual,expected){
t.Errorf("Expected %v, but got %v",expected,actual)
}
// Test case 2: Non-empty sequence
seq=NewBioSequence("",[]byte("atcg"),"")
expected=[]byte("atcg")
actual=seq.Sequence()
if!bytes.EqualFold(actual,expected){
t.Errorf("Expected %v, but got %v",expected,actual)
}
}
// TestBioSequence_String tests the String method of the BioSequence struct.
//
// It includes two test cases:
//
// 1. Test case 1: Empty sequence
// - Creates an empty BioSequence instance.
// - Expects an empty string as the result of calling the String method on the BioSequence instance.
//
// 2. Test case 2: Non-empty sequence
// - Creates a BioSequence instance with the sequence "acgt".
// - Expects the sequence "acgt" as the result of calling the String method on the BioSequence instance.
//
// No parameters are required.
// No return types are specified.
funcTestBioSequence_String(t*testing.T){
// Test case 1: Empty sequence
seq1:=&BioSequence{}
expected1:=""
ifgot1:=seq1.String();got1!=expected1{
t.Errorf("Test case 1 failed: expected %s, got %s",expected1,got1)
}
// Test case 2: Non-empty sequence
seq2:=&BioSequence{sequence:[]byte("acgt")}
expected2:="acgt"
ifgot2:=seq2.String();got2!=expected2{
t.Errorf("Test case 2 failed: expected %s, got %s",expected2,got2)
}
}
// TestBioSequence_Len tests the Len method of the BioSequence struct.
//
// It verifies the behavior of the method by performing multiple test cases.
// Each test case creates a BioSequence instance with a specific sequence and
// compares the actual length returned by the Len method with the expected
// length.
//
// Test 1: Empty sequence
// - Create a BioSequence instance with an empty sequence.
// - The expected length is 0.
// - Check if the actual length returned by the Len method matches the expected
// length. If not, report an error.
//
// Test 2: Sequence with 5 characters
// - Create a BioSequence instance with a sequence of 5 characters.
// - The expected length is 5.
// - Check if the actual length returned by the Len method matches the expected
// length. If not, report an error.
//
// Test 3: Sequence with 10 characters
// - Create a BioSequence instance with a sequence of 10 characters.
// - The expected length is 10.
// - Check if the actual length returned by the Len method matches the expected
// length. If not, report an error.
funcTestBioSequence_Len(t*testing.T){
// Test 1: Empty sequence
s1:=NewBioSequence("",nil,"")
expected1:=0
iflen:=s1.Len();len!=expected1{
t.Errorf("Expected length: %d, but got: %d",expected1,len)
}
// Test 2: Sequence with 5 characters
s2:=NewBioSequence("",[]byte("ATCGT"),"")
expected2:=5
iflen:=s2.Len();len!=expected2{
t.Errorf("Expected length: %d, but got: %d",expected2,len)
}
// Test 3: Sequence with 10 characters
s3:=NewBioSequence("",[]byte("AGCTAGCTAG"),"")
expected3:=10
iflen:=s3.Len();len!=expected3{
t.Errorf("Expected length: %d, but got: %d",expected3,len)
// TestBioSequence_Composition tests the Composition method of the BioSequence struct.
//
// It tests the method with three different test cases:
// 1. Empty sequence: It checks if the Composition method returns the expected composition when the sequence is empty.
// 2. Sequence with valid nucleotides: It checks if the Composition method returns the expected composition when the sequence contains valid nucleotides.
// 3. Sequence with invalid nucleotides: It checks if the Composition method returns the expected composition when the sequence contains invalid nucleotides.
//
// The expected composition for each test case is defined in a map where the keys are the nucleotides and the values are the expected counts.
// The Composition method is expected to return a map with the actual nucleotide counts.
//
// Parameters:
// - t: The testing.T object used for reporting test failures and logging.