Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fmhr committed Sep 19, 2023
1 parent a54da57 commit 9e0e5de
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# *プロトタイプ
# fj
fj コマンドはAtCoder Heuristic Contestの問題を解くことを助けるツールです。 このコマンドは、テストの実行を自動化します。
# Features
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type config struct {
Reactive bool `toml:"Reactive"`
TesterPath string `toml:"TesterPath"`
VisPath string `toml:"VisPath"`
GenPath string `toml:"GenPath"`
InfilePath string `toml:"InfilePath"`
OutfilePath string `toml:"OutfilePath"`
Jobs int `toml:"Jobs"`
Expand Down
58 changes: 58 additions & 0 deletions gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fj

import (
"fmt"
"log"
"os"
"os/exec"
"sync"
)

func Gen(cnf *config, seed int) {
if cnf.GenPath == "" {
log.Fatal("GenPath is not set. please set GenPath: {} in fj_config.toml")
}
err := gen(cnf, seed)
if err != nil {
log.Println(err)
}
}

var genMutex sync.Mutex

// seedを書き込んだd.txtをgenにすとin/0000.txtが生成される
func gen(cnf *config, seed int) error {
genMutex.Lock()
defer genMutex.Unlock()
_, err := os.Stat(cnf.GenPath)
if err != nil {
return fmt.Errorf("gen not found: %s", cnf.GenPath)
}
// seedを書き込んだd.txtをgenによませるとin/0000.txtが生成される
filename := fmt.Sprintf("%d.txt", seed)
err = writeIntToFile(seed, filename)
// d.txtを削除
defer os.Remove(filename)
if err != nil {
return fmt.Errorf("failed to write seed to file: %s", err)
}
// genを実行
cmd := fmt.Sprintf("%s %s", cnf.GenPath, filename)
err = exec.Command("sh", "-c", cmd).Run()
if err != nil {
return fmt.Errorf("failed to run gen: %s", err)
}
// in/0000.txtをin/{seed}.txtにリネーム
err = os.Rename("in/0000.txt", fmt.Sprintf("in/%04d.txt", seed))
if err != nil {
return fmt.Errorf("failed to rename file: %s", err)
}
// cnf.InfilePathを更新
cnf.InfilePath = "in/" + fmt.Sprintf("%04d.txt", seed)
return nil
}

func writeIntToFile(n int, filename string) error {
data := fmt.Sprintf("%d", n)
return os.WriteFile(filename, []byte(data), 0644)
}
4 changes: 3 additions & 1 deletion script.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func init() {
}

func Fj() {
mode := flag.String("mode", "help", "Chose mode [init(generage fj_config.toml), run(execute cmd), gcloud(TODO))")
mode := flag.String("mode", "help", "Chose mode [init(generage fj_config.toml), run(execute cmd), gen(need -seed option) gcloud(TODO))")
seed := flag.Int("seed", 0, "Seed for testcase seed. If unset, the default is 0 (0000.txt)run 0 seeds(0000.txt). If -end is set, thid value is ignored.")
start := flag.Int("start", 0, "Specifies the starting seed number. Default is 0.")
end := flag.Int("end", 0, "If set, run for seeds in the range: [start, end).")
Expand Down Expand Up @@ -66,6 +66,8 @@ func Fj() {
case "init":
// 設定ファイルの生成
GenerateConfig()
case "gen":
Gen(cnf, *seed)
case "gcloud":
// TODO
gcloud()
Expand Down

0 comments on commit 9e0e5de

Please sign in to comment.