From d4195aa90954af43a390d06972764cfac71d45e1 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Fri, 5 Jan 2024 14:03:49 -0800 Subject: [PATCH] added some more test coverage to fold subpackage. --- fold/fold_test.go | 11 +++++++++++ fold/seqfold_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 fold/seqfold_test.go diff --git a/fold/fold_test.go b/fold/fold_test.go index 8be9275f8..786d0a9a9 100644 --- a/fold/fold_test.go +++ b/fold/fold_test.go @@ -1,6 +1,7 @@ package fold import ( + "fmt" "math" "strings" "testing" @@ -201,3 +202,13 @@ func TestFold(t *testing.T) { assert.InDelta(t, struc.energy, -4.2, 0.2) }) } +func TestZuker_ErrorCreatingFoldingContext(t *testing.T) { + seq := "ATGGATTTAGATAGATADFQ#(RSDOFIA)" + temp := 4000.0 + + expectedErr := fmt.Errorf("error creating folding context: the sequence ATGGATTTAGATAGATADFQ#(RSDOFIA) is not RNA or DNA") + + _, err := Zuker(seq, temp) + require.Error(t, err) + assert.Equal(t, expectedErr.Error(), err.Error()) +} diff --git a/fold/seqfold_test.go b/fold/seqfold_test.go new file mode 100644 index 000000000..e14a20a10 --- /dev/null +++ b/fold/seqfold_test.go @@ -0,0 +1,43 @@ +package fold + +import ( + "fmt" + "math" + "testing" +) + +func TestResult_MinimumFreeEnergy_LengthZero(t *testing.T) { + result := Result{} // Create a Result instance with empty structs + + expectedEnergy := math.Inf(1) + actualEnergy := result.MinimumFreeEnergy() + + if actualEnergy != expectedEnergy { + t.Errorf("expected energy to be %f, but got %f", expectedEnergy, actualEnergy) + } +} + +func TestResult_DotBracket_LengthZero(t *testing.T) { + result := Result{} // Create a Result instance with empty structs + + expectedDotBracket := "" + actualDotBracket := result.DotBracket() + + if actualDotBracket != expectedDotBracket { + t.Errorf("expected dot bracket to be %s, but got %s", expectedDotBracket, actualDotBracket) + } +} + +func TestNewFoldingContext_InvalidSequence(t *testing.T) { + seq := "XYZ" + temp := 37.0 + + _, err := newFoldingContext(seq, temp) + if err == nil { + t.Errorf("expected error, but got nil") + } + expectedError := fmt.Errorf("the sequence %s is not RNA or DNA", seq) + if err.Error() != expectedError.Error() { + t.Errorf("expected error message to be %q, but got %q", expectedError.Error(), err.Error()) + } +}