summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@gmail.com>2018-11-06 21:36:44 -0500
committerAlex Goodman <wagoodman@gmail.com>2018-11-06 21:36:44 -0500
commitdc519adc1955c9dec8dae834eb636e39430c4493 (patch)
tree91d5baa30a40e4745040a31dac103a6bb936ff5a
parent8c5dd1dabeb189c17ec960bdb9aeab4789591ff1 (diff)
added efficiency testv0.2.0
-rw-r--r--filetree/efficiency_test.go91
-rw-r--r--ui/detailsview.go5
2 files changed, 47 insertions, 49 deletions
diff --git a/filetree/efficiency_test.go b/filetree/efficiency_test.go
index fea9236..4988053 100644
--- a/filetree/efficiency_test.go
+++ b/filetree/efficiency_test.go
@@ -1,49 +1,46 @@
package filetree
-// TODO: rewrite this to be weighted by file size
-
-// 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)
-// }
-// }
+import (
+ "archive/tar"
+ "testing"
+)
+
+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)
+ }
+}
diff --git a/ui/detailsview.go b/ui/detailsview.go
index 3728c59..0fd16f0 100644
--- a/ui/detailsview.go
+++ b/ui/detailsview.go
@@ -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