Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(773)

Unified Diff: src/pkg/sort/search_test.go

Issue 3025042: code review 3025042: sort: simplify semantics of Search. (Closed)
Patch Set: code review 3025042: sort: simplify semantics of Search. Created 14 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/sort/search.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/sort/search_test.go
===================================================================
--- a/src/pkg/sort/search_test.go
+++ b/src/pkg/sort/search_test.go
@@ -9,7 +9,7 @@
func f(a []int, x int) func(int) bool {
return func(i int) bool {
- return a[i] <= x
+ return a[i] < x
}
}
@@ -23,25 +23,26 @@
i int
}{
{"empty", 0, nil, 0},
- {"1 1", 1, func(i int) bool { return i <= 1 }, 0},
+ {"1 1", 1, func(i int) bool { return i < 1 }, 1},
{"1 false", 1, func(i int) bool { return false }, 0},
- {"1 true", 1, func(i int) bool { return true }, 0},
- {"1e9 991", 1e9, func(i int) bool { return i <= 991 }, 991},
+ {"1 true", 1, func(i int) bool { return true }, 1},
+ {"1e9 991", 1e9, func(i int) bool { return i < 991 }, 991},
{"1e9 false", 1e9, func(i int) bool { return false }, 0},
- {"1e9 true", 1e9, func(i int) bool { return true }, 1e9 - 1},
+ {"1e9 true", 1e9, func(i int) bool { return true }, 1e9},
{"data -20", len(data), f(data, -20), 0},
{"data -10", len(data), f(data, -10), 0},
- {"data -9", len(data), f(data, -9), 0},
- {"data -6", len(data), f(data, -6), 0},
+ {"data -9", len(data), f(data, -9), 1},
+ {"data -6", len(data), f(data, -6), 1},
{"data -5", len(data), f(data, -5), 1},
{"data 3", len(data), f(data, 3), 5},
- {"data 99", len(data), f(data, 99), 8},
- {"data 100", len(data), f(data, 100), 11},
- {"data 101", len(data), f(data, 101), 11},
+ {"data 11", len(data), f(data, 11), 8},
+ {"data 99", len(data), f(data, 99), 9},
+ {"data 100", len(data), f(data, 100), 9},
+ {"data 101", len(data), f(data, 101), 12},
{"data 10000", len(data), f(data, 10000), 13},
- {"data 10001", len(data), f(data, 10001), 13},
- {"descending a", 7, func(i int) bool { return []int{99, 99, 59, 42, 7, 0, -1, -1}[i] >= 7 }, 4},
- {"descending 7", 1e9, func(i int) bool { return 1e9-i >= 7 }, 1e9 - 7},
+ {"data 10001", len(data), f(data, 10001), 14},
+ {"descending a", 7, func(i int) bool { return []int{99, 99, 59, 42, 7, 0, -1, -1}[i] > 7 }, 4},
+ {"descending 7", 1e9, func(i int) bool { return 1e9-i > 7 }, 1e9 - 7},
}
@@ -78,7 +79,7 @@
max := log2(n)
for x := 0; x < n; x += step {
count := 0
- i := Search(n, func(i int) bool { count++; return i <= x })
+ i := Search(n, func(i int) bool { count++; return i < x })
if i != x {
t.Errorf("n = %d: expected index %d; got %d", n, x, i)
}
@@ -103,7 +104,7 @@
i int
}{
{"SearchInts", SearchInts(data, 11), 8},
- {"SearchFloats", SearchFloats(fdata, 2.1), 3},
+ {"SearchFloats", SearchFloats(fdata, 2.1), 4},
{"SearchStrings", SearchStrings(sdata, ""), 0},
{"IntArray.Search", IntArray(data).Search(0), 2},
{"FloatArray.Search", FloatArray(fdata).Search(2.0), 3},
« no previous file with comments | « src/pkg/sort/search.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b