fast-replace/go-fast-replace/internal/replace/bm_test.go

30 lines
643 B
Go

package replace
import (
"testing"
"internal/corpus"
"internal/pairs"
"internal/replace"
)
func TestBoyerMooreReplace(t *testing.T) {
var corpus string = "abcdefghi012345jklmnopqrst"
var pairs = []string{"012345", "ABCDEF"}
var want string = "abcdefghiABCDEFjklmnopqrst"
got := replace.BoyerMooreReplace(corpus, pairs)
if want != got {
t.Error("Replacement was wrong.")
}
}
func BenchmarkBoyerMooreReplace(b *testing.B) {
var amount int = 1000
var corpus string = corpus.MakeCorpus(amount)
var pairs []string = pairs.MakePairs(amount)
for n := 0; n < b.N; n++ {
replace.BoyerMooreReplace(corpus, pairs)
}
}