aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/strings/compare_test.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/strings/compare_test.go b/src/strings/compare_test.go
index 712e5a741e..5d5334461c 100644
--- a/src/strings/compare_test.go
+++ b/src/strings/compare_test.go
@@ -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
}
}