Skip to content

Commit

Permalink
Merge branch 'main' of github.com:semilin/genkey
Browse files Browse the repository at this point in the history
  • Loading branch information
semilin committed Mar 30, 2024
2 parents 2b0a047 + 82252b6 commit 54f1bf4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 14 additions & 4 deletions layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,13 +31,23 @@ 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) {
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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 54f1bf4

Please sign in to comment.