-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtle_test.go
More file actions
80 lines (65 loc) · 1.29 KB
/
tle_test.go
File metadata and controls
80 lines (65 loc) · 1.29 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package gpelements
import (
"bufio"
"fmt"
"os"
"strings"
"testing"
)
func TestTLEMany(t *testing.T) {
in, err := os.Open("data/test.tle")
if err != nil {
t.Fatal(err)
}
defer in.Close() // Ignore error.
r := bufio.NewReader(in)
f := func(lines []string) error {
e, err := ParseTLE(lines[0], lines[1], lines[2])
if err != nil {
return err
}
check := make([]string, 3)
check[0], check[1], check[2], err = e.MarshalTLE()
if err != nil {
return err
}
for i, line := range lines {
if i == 0 {
var (
x = strings.TrimSpace(line)
y = strings.TrimSpace(check[i])
)
if strings.HasPrefix(x, "0 ") {
x = x[2:]
}
if strings.HasPrefix(y, "0 ") {
y = y[2:]
}
if x != y {
return fmt.Errorf("different\n'%s'\n'%s'\n\n", line, check[i])
}
continue
}
if !sameTLELine(line, check[i]) {
return fmt.Errorf("different\n'%s'\n'%s'\n\n", line, check[i])
}
}
return nil
}
if err := DoTLEs(r, 3, f); err != nil {
t.Fatal(err)
}
}
func BenchmarkTLEParse(b *testing.B) {
tle := testTLE
lines := strings.SplitN(tle, "\n", 3)
if len(lines) != 3 {
b.Fatal(len(lines))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := ParseTLE(lines[0], lines[1], lines[2]); err != nil {
b.Fatal(err)
}
}
}