-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (42 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"github.com/Jumpaku/tokiope/internal/cmd/testcases"
"log"
"math"
"math/big"
"math/rand"
"os"
"github.com/Jumpaku/tokiope/internal/console"
)
func main() {
console.PanicIf(len(os.Args) != 2, "positional argument <output_path> is required")
outputPath := os.Args[1]
out, err := os.Create(os.Args[1])
console.PanicIfError(err, "failed to create output file: %s", outputPath)
defer out.Close()
nanos := []int64{0, math.MinInt64, math.MinInt64 + 1, math.MaxInt64 - 1, math.MaxInt64, 1, -1, 1_000_000_000, -1_000_000_000, 1_000_000_001, -1_000_000_001, 999_999_999, -999_999_999}
r := rand.New(rand.NewSource(1))
order := int64(10)
for i := 0; i < 18; i++ {
sign := r.Int63n(2)*2 - 1
nanos = append(nanos, sign*r.Int63n(order))
order *= 10
}
fmt.Fprintln(out, len(nanos)*len(nanos))
for _, sut := range nanos {
for _, in := range nanos {
sutSec, sutNano, ok := testcases.Decompose(big.NewInt(sut))
if !ok {
log.Panicf("%+v", sut)
}
inSec, inNano, ok := testcases.Decompose(big.NewInt(in))
if !ok {
log.Panicf("%+v", in)
}
wantSec, wantNano, _ := testcases.Decompose((&big.Int{}).Add(big.NewInt(sut), big.NewInt(in)))
fmt.Fprintf(out, "%d %d %d %d %d %d\n", sutSec, sutNano, inSec, inNano, wantSec, wantNano)
}
}
log.Println("func (Duration) Add testcases successfully generated in " + outputPath)
}