diff --git a/bwt/bwt.go b/bwt/bwt.go index 577bb485..447443a4 100644 --- a/bwt/bwt.go +++ b/bwt/bwt.go @@ -328,9 +328,9 @@ func (bwt BWT) lookupSkipByOffset(offset int) skipEntry { panic(msg) } - for i := range bwt.firstColumnSkipList { - if bwt.firstColumnSkipList[i].openEndedInterval.start <= offset && offset < bwt.firstColumnSkipList[i].openEndedInterval.end { - return bwt.firstColumnSkipList[i] + for skipIndex := range bwt.firstColumnSkipList { + if bwt.firstColumnSkipList[skipIndex].openEndedInterval.start <= offset && offset < bwt.firstColumnSkipList[skipIndex].openEndedInterval.end { + return bwt.firstColumnSkipList[skipIndex] } } panic("figure out what to do here") diff --git a/bwt/bwt_test.go b/bwt/bwt_test.go index c3fc7c16..cb835c05 100644 --- a/bwt/bwt_test.go +++ b/bwt/bwt_test.go @@ -1,6 +1,7 @@ package bwt import ( + "fmt" "strings" "testing" @@ -323,3 +324,89 @@ func TestBWTReconstruction(t *testing.T) { t.Fail() } } + +func TestBWTStartError(t *testing.T) { + testStr := "banana" + + bwt, err := New(testStr) + if err != nil { + t.Fatal(err) + } + + _, err = bwt.Extract(-1, 6) + if err == nil { + t.Fatal("expected error but got nil") + } +} +func TestBWT_GetFCharPosFromOriginalSequenceCharPos_Panic(t *testing.T) { + testStr := "banana" + bwt, err := New(testStr) + if err != nil { + t.Fatal(err) + } + + // Call the function with an invalid original position + originalPos := -1 + defer func() { + if r := recover(); r == nil { + t.Errorf("Expected panic, but it did not occur") + } + }() + bwt.getFCharPosFromOriginalSequenceCharPos(originalPos) +} +func TestBWT_LFSearch_InvalidChar(t *testing.T) { + testStr := "banana" + bwt, err := New(testStr) + if err != nil { + t.Fatal(err) + } + + pattern := "x" // Invalid character + + result := bwt.lfSearch(pattern) + + if result.start != 0 || result.end != 0 { + t.Fatalf("Expected search range to be (0, 0), but got (%d, %d)", result.start, result.end) + } +} +func TestBWT_LookupSkipByOffset_PanicOffsetExceedsMaxBound(t *testing.T) { + testStr := "banana" + bwt, err := New(testStr) + if err != nil { + t.Fatal(err) + } + + offset := bwt.getLenOfOriginalStringWithNullChar() + defer func() { + if r := recover(); r == nil { + t.Errorf("Expected panic, but it did not occur") + } + }() + bwt.lookupSkipByOffset(offset) +} + +func TestBWT_LookupSkipByOffset_PanicOffsetExceedsMinBound(t *testing.T) { + testStr := "banana" + bwt, err := New(testStr) + if err != nil { + t.Fatal(err) + } + + offset := -1 + defer func() { + if r := recover(); r == nil { + t.Errorf("Expected panic, but it did not occur") + } + }() + bwt.lookupSkipByOffset(offset) +} + +func TestBWTRecovery(t *testing.T) { + // Test panic recovery for bwtRecovery function + err := fmt.Errorf("test error") + operation := "test operation" + defer bwtRecovery(operation, &err) + + panic("test panic") + t.Errorf("Expected panic, but it did not occur") +} diff --git a/bwt/wavelet_test.go b/bwt/wavelet_test.go index ac028988..432f4a85 100644 --- a/bwt/wavelet_test.go +++ b/bwt/wavelet_test.go @@ -260,3 +260,26 @@ func TestWaveletTreeSingleAlpha(t *testing.T) { t.Fatalf("expected Access(%d) to be %d but got %d", 1, 1, s) } } +func TestBuildWaveletTree_ZeroAlpha(t *testing.T) { + bytes := []byte("AAAACCCCTTTTGGGG") + alpha := []charInfo{} + + root := buildWaveletTree(0, alpha, bytes) + + if root != nil { + t.Fatalf("expected root to be nil but got %v", root) + } +} +func TestWaveletTree_LookupCharInfo_Panic(t *testing.T) { + wt := waveletTree{ + alpha: []charInfo{}, + } + + defer func() { + if r := recover(); r == nil { + t.Errorf("expected panic but got nil") + } + }() + + wt.lookupCharInfo('B') +}