summaryrefslogtreecommitdiff
path: root/pare-gt/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-02-20 11:25:05 +0000
committerNick White <git@njw.name>2020-02-20 11:36:28 +0000
commit62512ca0abb651780a01ba535bdc31f6930d4300 (patch)
tree03c9703d7daa8bd8c38a269ca53b425ed178363c /pare-gt/main.go
parent8c8590498bbc826599a13f3329d45d2bf968214c (diff)
[pare-gt] Add some tests, and make deterministic
These tests have uncovered at least 2 bugs that haven't yet been squashed: - 1% selection hangs - 20% selection only takes as many as 10%
Diffstat (limited to 'pare-gt/main.go')
-rw-r--r--pare-gt/main.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/pare-gt/main.go b/pare-gt/main.go
index c645480..0a8b067 100644
--- a/pare-gt/main.go
+++ b/pare-gt/main.go
@@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"strings"
+ "sort"
)
const usage = `Usage: pare-gt [-n num] gtdir movedir
@@ -65,13 +66,20 @@ func inStrSlice(sl []string, s string) bool {
// total of perctosample% are sampled.
func samplePrefixes(perctosample int, prefixes Prefixes) (filestomove []string) {
var total, sample int
- for _, v := range prefixes {
+ var keys []string
+ for i, v := range prefixes {
total += len(v)
+ // needed for determinism
+ sort.Strings(prefixes[i])
+ keys = append(keys, i)
}
sample = total / perctosample
- for _, prefix := range prefixes {
+ // This ensures the map is looped over deterministically
+ sort.Strings(keys)
+ for _, key := range keys {
+ prefix := prefixes[key]
len := len(prefix)
if len == 1 {
continue