Skip to content

Commit

Permalink
complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Dec 23, 2024
1 parent 4576231 commit b086818
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 82 deletions.
1 change: 1 addition & 0 deletions flx.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func FindBestMatch(imatch *[]Result, strInfo map[int][]int, heatmap []int, great
FindBestMatch(&elemGroup, clonedStrInfo, clonedHeatmap, &val, query, queryLen, qIndex+1, matchCache)

for _, elem := range elemGroup {
// XXX: Not sure why it has empty result.
if reflect.DeepEqual(elem, Result{}) {
continue
}
Expand Down
170 changes: 88 additions & 82 deletions test/flx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,112 +10,118 @@
package flx_test

import (
//"reflect"
//"slices"
"reflect"
"slices"
"testing"

"github.com/the-flx/flx.go"
)

/* Test */

// func TestWord1(t *testing.T) {
// ch := 'c'
// result := flx.Word(&ch)
// if result == true {
// return
// }
// t.Errorf("Test `Word` 1: %v", result)
// }
//
// func TestWord2(t *testing.T) {
// ch := ' '
// result := flx.Word(&ch)
// if result == false {
// return
// }
// t.Errorf("Test `Word` 2: %v", result)
// }
//
// func TestIncVec1(t *testing.T) {
// vec := []int{1, 2, 3}
// inc := 1
// beg := 0
// end := 3
// result := flx.IncVec(vec, &inc, &beg, &end)
// if !reflect.DeepEqual(result, []int{2, 3, 4}) {
// t.Errorf("Test `IncVec` 2: %v", result)
// }
// }
//
// func TestGetHashMapForString1(t *testing.T) {
// result := flx.GetHashForString("switch-to-buffer")
// if !reflect.DeepEqual(result, map[int][]int{
// 114: {15},
// 101: {14},
// 102: {12, 13},
// 117: {11},
// 98: {10},
// 45: {6, 9},
// 111: {8},
// 116: {3, 7},
// 104: {5},
// 99: {4},
// 105: {2},
// 119: {1},
// 115: {0},
// }) {
// t.Errorf("Test `GetHashForString` 1: %v", result)
// }
// }
func TestWord1(t *testing.T) {
ch := 'c'
result := flx.Word(&ch)
if result == true {
return
}
t.Errorf("Test `Word` 1: %v", result)
}

// func TestSlice1(t *testing.T) {
// slice := []int{1, 2, 3, 4}
// result := slices.Delete(slice, 0, 2)
// if !reflect.DeepEqual(result, []int{3, 4}) {
// t.Errorf("Test `Slice` 1: %v", result)
// }
// }
//
// func TestGetHeatmapStr1(t *testing.T) {
// result := flx.GetHeatmapStr("switch-to-buffer", nil)
// if !reflect.DeepEqual(result, []int{82, -4, -5, -6, -7, -8, -9, 79, -7, -8, 76, -10, -11, -12, -13, -13}) {
// t.Errorf("Test `TestGetHeatmapStr` 1: %v", result)
// }
// }
func TestWord2(t *testing.T) {
ch := ' '
result := flx.Word(&ch)
if result == false {
return
}
t.Errorf("Test `Word` 2: %v", result)
}

// func TestBiggerSublist1(t *testing.T) {
// result := flx.BiggerSublist([]int{1, 2, 3, 4}, nil)
// if !reflect.DeepEqual(result, []int{1, 2, 3, 4}) {
// t.Errorf("Test `BiggerSublit` 1: %v", result)
// }
// }
//
// func TestBiggerSublist2(t *testing.T) {
// val := 2
// result := flx.BiggerSublist([]int{1, 2, 3, 4}, &val)
// if !reflect.DeepEqual(result, []int{ 3, 4}) {
// t.Errorf("Test `BiggerSublit` 2: %v", result)
// }
// }
func TestIncVec1(t *testing.T) {
vec := []int{1, 2, 3}
inc := 1
beg := 0
end := 3
result := flx.IncVec(vec, &inc, &beg, &end)
if !reflect.DeepEqual(result, []int{2, 3, 4}) {
t.Errorf("Test `IncVec` 2: %v", result)
}
}

func TestGetHashMapForString1(t *testing.T) {
result := flx.GetHashForString("switch-to-buffer")
if !reflect.DeepEqual(result, map[int][]int{
114: {15},
101: {14},
102: {12, 13},
117: {11},
98: {10},
45: {6, 9},
111: {8},
116: {3, 7},
104: {5},
99: {4},
105: {2},
119: {1},
115: {0},
}) {
t.Errorf("Test `GetHashForString` 1: %v", result)
}
}

func TestSlice1(t *testing.T) {
slice := []int{1, 2, 3, 4}
result := slices.Delete(slice, 0, 2)
if !reflect.DeepEqual(result, []int{3, 4}) {
t.Errorf("Test `Slice` 1: %v", result)
}
}

func TestGetHeatmapStr1(t *testing.T) {
result := flx.GetHeatmapStr("switch-to-buffer", nil)
if !reflect.DeepEqual(result, []int{82, -4, -5, -6, -7, -8, -9, 79, -7, -8, 76, -10, -11, -12, -13, -13}) {
t.Errorf("Test `TestGetHeatmapStr` 1: %v", result)
}
}

func TestBiggerSublist1(t *testing.T) {
result := flx.BiggerSublist([]int{1, 2, 3, 4}, nil)
if !reflect.DeepEqual(result, []int{1, 2, 3, 4}) {
t.Errorf("Test `BiggerSublit` 1: %v", result)
}
}

func TestBiggerSublist2(t *testing.T) {
val := 2
result := flx.BiggerSublist([]int{1, 2, 3, 4}, &val)
if !reflect.DeepEqual(result, []int{3, 4}) {
t.Errorf("Test `BiggerSublit` 2: %v", result)
}
}

func TestScore1(t *testing.T) {
result := flx.Score("switch-to-buffer", "stb")
if result.Score != 237 {
if !reflect.DeepEqual(result.Indices, []int{0, 7, 10}) ||
result.Score != 237 ||
result.Tail != 0 {
t.Errorf("Test `Score` 1: %v", result)
}
}

func TestScore2(t *testing.T) {
result := flx.Score("TestSomeFunctionExterme", "met")
if result.Score != 57 {
if !reflect.DeepEqual(result.Indices, []int{6, 16, 18}) ||
result.Score != 57 ||
result.Tail != 0 {
t.Errorf("Test `Score` 2: %v", result)
}
}

func TestScore3(t *testing.T) {
result := flx.Score("MetaX_Version", "met")
if result.Score != 211 {
if !reflect.DeepEqual(result.Indices, []int{0, 1, 2}) ||
result.Score != 211 ||
result.Tail != 2 {
t.Errorf("Test `Score` 3: %v", result)
}
}

0 comments on commit b086818

Please sign in to comment.