From 806a69dfeffe64568ad8c3b3627b6c2e050b1e7a Mon Sep 17 00:00:00 2001 From: semi Date: Fri, 16 Feb 2024 17:14:46 -0800 Subject: [PATCH 1/2] make LoadLayoutDir take path arg and fix tests --- layout.go | 8 ++++---- layout_test.go | 8 ++++---- main.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/layout.go b/layout.go index d52cf0a..feff5f5 100644 --- a/layout.go +++ b/layout.go @@ -220,15 +220,15 @@ func LoadLayout(f string) Layout { return l } -func LoadLayoutDir() { - dir, err := os.Open(Config.Paths.Layouts) +func LoadLayoutDir(path string) { + dir, err := os.Open(path) if err != nil { - fmt.Printf("Layouts directory could not be opened at %s\n", Config.Paths.Layouts) + fmt.Printf("Layouts directory could not be opened at %s\n", path) panic(err) } files, _ := dir.Readdirnames(0) for _, f := range files { - l := LoadLayout(filepath.Join(Config.Paths.Layouts, f)) + l := LoadLayout(filepath.Join(path, f)) if l.Name == "" { continue } diff --git a/layout_test.go b/layout_test.go index 170c076..92220e2 100644 --- a/layout_test.go +++ b/layout_test.go @@ -5,9 +5,9 @@ import ( ) func init() { - Data = LoadData() + Data = LoadData("./corpora/tr.json") Layouts = make(map[string]Layout) - LoadLayoutDir() + LoadLayoutDir("./layouts") } // input layout must be 3x10 @@ -36,8 +36,8 @@ func TestSFBs(t *testing.T) { func TestTrigrams(t *testing.T) { mtgap := Layouts["mtgap30"] m := mirror(mtgap) - r1 := FastTrigrams(mtgap, 0) - r2 := FastTrigrams(m, 0) + r1 := FastTrigrams(&mtgap, 0) + r2 := FastTrigrams(&m, 0) alt1 := r1.Alternates alt2 := r2.Alternates lir1 := r1.LeftInwardRolls diff --git a/main.go b/main.go index 5cbdd26..a86b1e0 100644 --- a/main.go +++ b/main.go @@ -341,7 +341,7 @@ func main() { Data = LoadData(filepath.Join(Config.Paths.Corpora, Config.Corpus) + ".json") Layouts = make(map[string]Layout) - LoadLayoutDir() + LoadLayoutDir(Config.Paths.Layouts) for _, l := range Layouts { if len(l.Name) > LongestLayoutName { From 769effd3878f4c07f018c037361aefadb74cc4e2 Mon Sep 17 00:00:00 2001 From: semi Date: Fri, 16 Feb 2024 17:24:26 -0800 Subject: [PATCH 2/2] add intra-sfb tests --- layout_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/layout_test.go b/layout_test.go index 92220e2..3030fb4 100644 --- a/layout_test.go +++ b/layout_test.go @@ -31,6 +31,16 @@ func TestSFBs(t *testing.T) { if r1 != r2 { t.Errorf("Original layout has %.1f SFB; Mirrored has %.1f", r1, r2) } + for x := 0; x < 10; x++ { + Swap(&m, Pos{x, 0}, Pos{x, 2}) + Swap(&m, Pos{x, 0}, Pos{x, 1}) + } + + m = CopyLayout(mtgap) + r2 = SFBs(m, false) + if r1 != r2 { + t.Errorf("Original layout has %.1f SFB; Intra-finger swapped has %.1f", r1, r2) + } } func TestTrigrams(t *testing.T) {