-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_test.go
72 lines (65 loc) · 1.96 KB
/
strings_test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package rel
import (
"fmt"
"testing"
)
// tests for string conversion
// including String, GoString, and benchmarks
func TestGoString(t *testing.T) {
out := `rel.New([]struct {
PNO int
PName string
Color string
Weight float64
City string
}{
{1, "Nut", "Red", 12, "London", },
{2, "Bolt", "Green", 17, "Paris", },
{3, "Screw", "Blue", 17, "Oslo", },
{4, "Screw", "Red", 14, "London", },
{5, "Cam", "Blue", 12, "Paris", },
{6, "Cog", "Red", 19, "London", },
})`
if in := fmt.Sprintf("%#v", parts()); in != out {
t.Errorf("String(Parts) = %q, want %q", in, out)
}
}
func TestString(t *testing.T) {
out := ` +------+--------+--------+---------+---------+
| PNO | PName | Color | Weight | City |
+------+--------+--------+---------+---------+
| 1 | Nut | Red | 12 | London |
| 2 | Bolt | Green | 17 | Paris |
| 3 | Screw | Blue | 17 | Oslo |
| 4 | Screw | Red | 14 | London |
| 5 | Cam | Blue | 12 | Paris |
| 6 | Cog | Red | 19 | London |
+------+--------+--------+---------+---------+`
if in := stringTabTable(parts()); in != out {
t.Errorf("String(Parts) = %v, want %v", in, out)
}
}
func BenchmarkSimpleStringTiny(b *testing.B) {
// test the time it takes to turn a relation into a string
exRel := New(exampleRelSlice2(10), [][]string{[]string{"foo"}})
b.ResetTimer()
for i := 0; i < b.N; i++ {
fmt.Sprintf("%v", exRel)
}
}
func BenchmarkSimpleStringSmall(b *testing.B) {
// test the time it takes to turn a relation into a string
exRel := New(exampleRelSlice2(1000), [][]string{[]string{"foo"}})
b.ResetTimer()
for i := 0; i < b.N; i++ {
fmt.Sprintf("%v", exRel)
}
}
func BenchmarkSimpleStringMedium(b *testing.B) {
// test the time it takes to turn a relation into a string
exRel := New(exampleRelSlice2(100000), [][]string{[]string{"foo"}})
b.ResetTimer()
for i := 0; i < b.N; i++ {
fmt.Sprintf("%v", exRel)
}
}