-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# *プロトタイプ | ||
# fj | ||
fj コマンドはAtCoder Heuristic Contestの問題を解くことを助けるツールです。 このコマンドは、テストの実行を自動化します。 | ||
# Features | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters