Skip to content

Commit 8039b12

Browse files
committed
Connect word importer to typing game
1 parent 55849c7 commit 8039b12

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

kadai3-1/lfcd85/cmd/main.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ package main
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/gopherdojo/dojo5/kadai3-1/lfcd85/typinggame"
8+
"github.com/gopherdojo/dojo5/kadai3-1/lfcd85/words"
79
)
810

911
func main() {
10-
// create words from input file (abstracted by io.Reader if possible)
11-
12-
// start time counting by time.After or context.WithTimeout
13-
14-
// output word to stdout
15-
// get one line from stdin
16-
// judge whether two words are the same
17-
// if so, add count of correct answers
18-
19-
// when time limit has come, show the count of correct answers
12+
path := "./testdata/go_standard_library.txt" // FIXME: move to options
13+
words, err := words.Import(path)
14+
if err != nil {
15+
fmt.Println("error:", err)
16+
return
17+
}
18+
g := typinggame.Game{
19+
Words: words,
20+
TimeLimit: 30 * time.Second,
21+
}
2022

21-
if err := typinggame.Execute(); err != nil {
23+
if err := typinggame.Execute(g); err != nil {
2224
fmt.Println("error:", err)
2325
return
2426
}

kadai3-1/lfcd85/typinggame/typinggame.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ package typinggame
22

33
import (
44
"fmt"
5+
"time"
56
)
67

7-
func Execute() error {
8-
fmt.Println("hello, typing game")
8+
type Words []string
9+
10+
type Game struct {
11+
Words Words
12+
TimeLimit time.Duration
13+
}
14+
15+
func Execute(g Game) error {
16+
fmt.Println(g.Words)
17+
fmt.Println(g.TimeLimit)
918
return nil
1019
}

kadai3-1/lfcd85/typinggame/typinggame_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ package typinggame_test
22

33
import (
44
"testing"
5+
"time"
56

67
"github.com/gopherdojo/dojo5/kadai3-1/lfcd85/typinggame"
78
)
89

910
func TestExecute(t *testing.T) {
10-
if err := typinggame.Execute(); err != nil {
11-
t.Errorf("error: %v", err)
11+
g := typinggame.Game{
12+
typinggame.Words{"hoge", "fuga", "piyo"},
13+
30 * time.Second,
14+
}
15+
16+
if err := typinggame.Execute(g); err != nil {
17+
t.Errorf("failed to execute new game: %v", err)
1218
}
1319
}

0 commit comments

Comments
 (0)