]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.10] strings: do much less redundant testing in TestCompareStrings
authorIan Lance Taylor <iant@golang.org>
Sun, 1 Jul 2018 22:01:09 +0000 (15:01 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 16 Jul 2018 23:14:19 +0000 (23:14 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ralph Corderoy <ralph@inputplus.co.uk>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
(cherry picked from commit 869884daead156d0e5a4093d91968ed172d4d2d0)
Reviewed-on: https://go-review.googlesource.com/124115
Reviewed-by: Bill O'Farrell <billotosyr@gmail.com>
src/strings/compare_test.go

index 712e5a741eae2878e33de6d488a9bf25f5efb0fe..5d5334461c31060797832344f940d1645c781836 100644 (file)
@@ -66,6 +66,7 @@ func TestCompareStrings(t *testing.T) {
        n := lengths[len(lengths)-1]
        a := make([]byte, n+1)
        b := make([]byte, n+1)
+       lastLen := 0
        for _, len := range lengths {
                // randomish but deterministic data. No 0 or 255.
                for i := 0; i < len; i++ {
@@ -78,21 +79,22 @@ func TestCompareStrings(t *testing.T) {
                        b[i] = 9
                }
 
-               cmp := Compare(string(a[:len]), string(b[:len]))
+               sa, sb := string(a), string(b)
+               cmp := Compare(sa[:len], sb[:len])
                if cmp != 0 {
                        t.Errorf(`CompareIdentical(%d) = %d`, len, cmp)
                }
                if len > 0 {
-                       cmp = Compare(string(a[:len-1]), string(b[:len]))
+                       cmp = Compare(sa[:len-1], sb[:len])
                        if cmp != -1 {
                                t.Errorf(`CompareAshorter(%d) = %d`, len, cmp)
                        }
-                       cmp = Compare(string(a[:len]), string(b[:len-1]))
+                       cmp = Compare(sa[:len], sb[:len-1])
                        if cmp != 1 {
                                t.Errorf(`CompareBshorter(%d) = %d`, len, cmp)
                        }
                }
-               for k := 0; k < len; k++ {
+               for k := lastLen; k < len; k++ {
                        b[k] = a[k] - 1
                        cmp = Compare(string(a[:len]), string(b[:len]))
                        if cmp != 1 {
@@ -105,5 +107,6 @@ func TestCompareStrings(t *testing.T) {
                        }
                        b[k] = a[k]
                }
+               lastLen = len
        }
 }