handle scratch images (closes #76)

This commit is contained in:
Alex Goodman 2018-12-08 12:54:58 -05:00
parent d78b6cdc44
commit 1650839e49
No known key found for this signature in database
GPG Key ID: 743640FAA11698A1
2 changed files with 30 additions and 3 deletions

View File

@ -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)

View File

@ -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))
}
}