added efficiency test
This commit is contained in:
parent
8c5dd1dabe
commit
dc519adc19
@ -1,49 +1,46 @@
|
||||
package filetree
|
||||
|
||||
// TODO: rewrite this to be weighted by file size
|
||||
import (
|
||||
"archive/tar"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// func TestEfficencyMap(t *testing.T) {
|
||||
// trees := make([]*FileTree, 3)
|
||||
// for ix, _ := range trees {
|
||||
// tree := NewFileTree()
|
||||
// tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||
// tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||
// trees[ix] = tree
|
||||
// }
|
||||
// var expectedMap = map[string]int{
|
||||
// "/etc/nginx/nginx.conf": 3,
|
||||
// "/etc/nginx/public": 3,
|
||||
// }
|
||||
// actualMap := EfficiencyMap(trees)
|
||||
// if !reflect.DeepEqual(expectedMap, actualMap) {
|
||||
// t.Fatalf("Expected %v but go %v", expectedMap, actualMap)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func TestEfficiencyScore(t *testing.T) {
|
||||
// trees := make([]*FileTree, 3)
|
||||
// for ix, _ := range trees {
|
||||
// tree := NewFileTree()
|
||||
// tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||
// tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||
// trees[ix] = tree
|
||||
// }
|
||||
// expected := 2.0 / 6.0
|
||||
// actual := CalculateEfficiency(trees)
|
||||
// if math.Abs(expected-actual) > 0.0001 {
|
||||
// t.Fatalf("Expected %f but got %f", expected, actual)
|
||||
// }
|
||||
//
|
||||
// trees = make([]*FileTree, 1)
|
||||
// for ix, _ := range trees {
|
||||
// tree := NewFileTree()
|
||||
// tree.AddPath("/etc/nginx/nginx.conf", FileInfo{})
|
||||
// tree.AddPath("/etc/nginx/public", FileInfo{})
|
||||
// trees[ix] = tree
|
||||
// }
|
||||
// expected = 1.0
|
||||
// actual = CalculateEfficiency(trees)
|
||||
// if math.Abs(expected-actual) > 0.0001 {
|
||||
// t.Fatalf("Expected %f but got %f", expected, actual)
|
||||
// }
|
||||
// }
|
||||
func TestEfficencyMap(t *testing.T) {
|
||||
trees := make([]*FileTree, 3)
|
||||
for idx := range trees {
|
||||
trees[idx] = NewFileTree()
|
||||
}
|
||||
|
||||
trees[0].AddPath("/etc/nginx/nginx.conf", FileInfo{TarHeader: tar.Header{Size: 2000}})
|
||||
trees[0].AddPath("/etc/nginx/public", FileInfo{TarHeader: tar.Header{Size: 3000}})
|
||||
|
||||
trees[1].AddPath("/etc/nginx/nginx.conf", FileInfo{TarHeader: tar.Header{Size: 5000}})
|
||||
trees[1].AddPath("/etc/athing", FileInfo{TarHeader: tar.Header{Size: 10000}})
|
||||
|
||||
trees[2].AddPath("/etc/.wh.nginx", *BlankFileChangeInfo("/etc/.wh.nginx"))
|
||||
|
||||
var expectedScore = 0.75
|
||||
var expectedMatches = EfficiencySlice{
|
||||
&EfficiencyData{Path: "/etc/nginx/nginx.conf", CumulativeSize: 7000},
|
||||
}
|
||||
actualScore, actualMatches := Efficiency(trees)
|
||||
|
||||
if expectedScore != actualScore {
|
||||
t.Errorf("Expected score of %v but go %v", expectedScore, actualScore)
|
||||
}
|
||||
|
||||
if len(actualMatches) != len(expectedMatches) {
|
||||
for _, match := range actualMatches {
|
||||
t.Logf(" match: %+v", match)
|
||||
}
|
||||
t.Fatalf("Expected to find %d inefficient path, but found %d", len(expectedMatches), len(actualMatches))
|
||||
}
|
||||
|
||||
if expectedMatches[0].Path != actualMatches[0].Path {
|
||||
t.Errorf("Expected path of %s but go %s", expectedMatches[0].Path, actualMatches[0].Path)
|
||||
}
|
||||
|
||||
if expectedMatches[0].CumulativeSize != actualMatches[0].CumulativeSize {
|
||||
t.Errorf("Expected cumulative size of %v but go %v", expectedMatches[0].CumulativeSize, actualMatches[0].CumulativeSize)
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,13 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/jroimartin/gocui"
|
||||
"github.com/lunixbochs/vtclean"
|
||||
"github.com/wagoodman/dive/filetree"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DetailsView holds the UI objects and data models for populating the lower-left pane. Specifically the pane that
|
||||
|
Loading…
x
Reference in New Issue
Block a user