summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@gmail.com>2018-12-08 12:54:58 -0500
committerAlex Goodman <wagoodman@gmail.com>2018-12-08 12:54:58 -0500
commit1650839e497d3cf7a35a228917aa894913aa9b9b (patch)
tree41cd725103404b72c4b773c5ad16128e2b810b4d
parentd78b6cdc44ec621fd95933ed0b6fe6a188f93f31 (diff)
handle scratch images (closes #76)
-rw-r--r--filetree/efficiency.go7
-rw-r--r--filetree/efficiency_test.go26
2 files changed, 30 insertions, 3 deletions
diff --git a/filetree/efficiency.go b/filetree/efficiency.go
index b521bff..68ed320 100644
--- a/filetree/efficiency.go
+++ b/filetree/efficiency.go
@@ -91,7 +91,12 @@ func Efficiency(trees []*FileTree) (float64, EfficiencySlice) {
minimumPathSizes += value.minDiscoveredSize
discoveredPathSizes += value.CumulativeSize
}
- score := float64(minimumPathSizes) / float64(discoveredPathSizes)
+ var score float64
+ if discoveredPathSizes == 0 {
+ score = 1.0
+ } else {
+ score = float64(minimumPathSizes) / float64(discoveredPathSizes)
+ }
sort.Sort(inefficientMatches)
diff --git a/filetree/efficiency_test.go b/filetree/efficiency_test.go
index 3ec779f..e461201 100644
--- a/filetree/efficiency_test.go
+++ b/filetree/efficiency_test.go
@@ -4,7 +4,7 @@ import (
"testing"
)
-func TestEfficencyMap(t *testing.T) {
+func TestEfficency(t *testing.T) {
trees := make([]*FileTree, 3)
for idx := range trees {
trees[idx] = NewFileTree()
@@ -32,7 +32,7 @@ func TestEfficencyMap(t *testing.T) {
for _, match := range actualMatches {
t.Logf(" match: %+v", match)
}
- t.Fatalf("Expected to find %d inefficient path, but found %d", len(expectedMatches), len(actualMatches))
+ t.Fatalf("Expected to find %d inefficient paths, but found %d", len(expectedMatches), len(actualMatches))
}
if expectedMatches[0].Path != actualMatches[0].Path {
@@ -43,3 +43,25 @@ func TestEfficencyMap(t *testing.T) {
t.Errorf("Expected cumulative size of %v but go %v", expectedMatches[0].CumulativeSize, actualMatches[0].CumulativeSize)
}
}
+
+func TestEfficency_ScratchImage(t *testing.T) {
+ trees := make([]*FileTree, 3)
+ for idx := range trees {
+ trees[idx] = NewFileTree()
+ }
+
+ trees[0].AddPath("/nothing", FileInfo{Size: 0})
+
+ var expectedScore = 1.0
+ var expectedMatches = EfficiencySlice{}
+ actualScore, actualMatches := Efficiency(trees)
+
+ if expectedScore != actualScore {
+ t.Errorf("Expected score of %v but go %v", expectedScore, actualScore)
+ }
+
+ if len(actualMatches) > 0 {
+ t.Fatalf("Expected to find %d inefficient paths, but found %d", len(expectedMatches), len(actualMatches))
+ }
+
+}