Skip to content

Commit

Permalink
added test for printLFDebug.
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyStiles committed Jan 24, 2024
1 parent ed783a8 commit 4d85fb7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions search/bwt/bwt_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package bwt

import (
"bytes"
"io"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -535,3 +538,42 @@ func TestBWTRecovery(t *testing.T) {
func doPanic() {
panic("test panic")
}
func TestPrintLFDebug(t *testing.T) {
bwt, err := New("banana")
if err != nil {
t.Fatal(err)
}

searchRange := interval{start: 2, end: 5}
iteration := 1

expectedOutput := "BWT Debug Begin Iteration: 1" + "\n"
expectedOutput += "annb$aa" + "\n"
expectedOutput += "$aaabnn" + "\n"
expectedOutput += "__^^^X" + "\n"
expectedOutput += "anb$a" + "\n"
// $aaabnn
// __^^^X
// anb$a`

// Redirect stdout to capture the output
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

printLFDebug(bwt, searchRange, iteration)

// Reset stdout
w.Close()
os.Stdout = old

// Read the captured output
var buf bytes.Buffer
io.Copy(&buf, r)

Check failure on line 572 in search/bwt/bwt_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `io.Copy` is not checked (errcheck)

// Compare the output with the expected value
actualOutput := buf.String()
if actualOutput != expectedOutput {
t.Errorf("Unexpected output:\nExpected:\n%s\nActual:\n%s", expectedOutput, actualOutput)
}
}

0 comments on commit 4d85fb7

Please sign in to comment.