handle scratch images (closes #76)
This commit is contained in:
parent
d78b6cdc44
commit
1650839e49
@ -91,7 +91,12 @@ func Efficiency(trees []*FileTree) (float64, EfficiencySlice) {
|
|||||||
minimumPathSizes += value.minDiscoveredSize
|
minimumPathSizes += value.minDiscoveredSize
|
||||||
discoveredPathSizes += value.CumulativeSize
|
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)
|
sort.Sort(inefficientMatches)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEfficencyMap(t *testing.T) {
|
func TestEfficency(t *testing.T) {
|
||||||
trees := make([]*FileTree, 3)
|
trees := make([]*FileTree, 3)
|
||||||
for idx := range trees {
|
for idx := range trees {
|
||||||
trees[idx] = NewFileTree()
|
trees[idx] = NewFileTree()
|
||||||
@ -32,7 +32,7 @@ func TestEfficencyMap(t *testing.T) {
|
|||||||
for _, match := range actualMatches {
|
for _, match := range actualMatches {
|
||||||
t.Logf(" match: %+v", match)
|
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 {
|
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)
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user