Skip to content

Commit 869884d

Browse files
strings: do much less redundant testing in TestCompareStrings
On the OpenBSD builder this reduces the test time from 213 seconds to 60 seconds, without loss of testing. Not sure why the test is so much slower on OpenBSD, so not closing the issues. Updates #26155 Updates #26174 Change-Id: I13b58bbe3b209e591c308765077d2342943a3d2a Reviewed-on: https://go-review.googlesource.com/121820 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ralph Corderoy <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 5110d19 commit 869884d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/strings/compare_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func TestCompareStrings(t *testing.T) {
6666
n := lengths[len(lengths)-1]
6767
a := make([]byte, n+1)
6868
b := make([]byte, n+1)
69+
lastLen := 0
6970
for _, len := range lengths {
7071
// randomish but deterministic data. No 0 or 255.
7172
for i := 0; i < len; i++ {
@@ -78,21 +79,22 @@ func TestCompareStrings(t *testing.T) {
7879
b[i] = 9
7980
}
8081

81-
cmp := Compare(string(a[:len]), string(b[:len]))
82+
sa, sb := string(a), string(b)
83+
cmp := Compare(sa[:len], sb[:len])
8284
if cmp != 0 {
8385
t.Errorf(`CompareIdentical(%d) = %d`, len, cmp)
8486
}
8587
if len > 0 {
86-
cmp = Compare(string(a[:len-1]), string(b[:len]))
88+
cmp = Compare(sa[:len-1], sb[:len])
8789
if cmp != -1 {
8890
t.Errorf(`CompareAshorter(%d) = %d`, len, cmp)
8991
}
90-
cmp = Compare(string(a[:len]), string(b[:len-1]))
92+
cmp = Compare(sa[:len], sb[:len-1])
9193
if cmp != 1 {
9294
t.Errorf(`CompareBshorter(%d) = %d`, len, cmp)
9395
}
9496
}
95-
for k := 0; k < len; k++ {
97+
for k := lastLen; k < len; k++ {
9698
b[k] = a[k] - 1
9799
cmp = Compare(string(a[:len]), string(b[:len]))
98100
if cmp != 1 {
@@ -105,5 +107,6 @@ func TestCompareStrings(t *testing.T) {
105107
}
106108
b[k] = a[k]
107109
}
110+
lastLen = len
108111
}
109112
}

0 commit comments

Comments
 (0)