|
| 1 | +package core |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +func TestSortTree(t *testing.T) { |
| 9 | + testTree := &File{"b", 260, []*File{ |
| 10 | + &File{"c", 100, []*File{}}, |
| 11 | + &File{"d", 160, []*File{ |
| 12 | + &File{"e", 50, []*File{}}, |
| 13 | + &File{"f", 30, []*File{}}, |
| 14 | + &File{"g", 80, []*File{ |
| 15 | + &File{"i", 30, []*File{}}, |
| 16 | + &File{"j", 50, []*File{}}, |
| 17 | + }}, |
| 18 | + }}, |
| 19 | + }} |
| 20 | + expected := &File{"b", 260, []*File{ |
| 21 | + &File{"d", 160, []*File{ |
| 22 | + &File{"g", 80, []*File{ |
| 23 | + &File{"j", 50, []*File{}}, |
| 24 | + &File{"i", 30, []*File{}}, |
| 25 | + }}, |
| 26 | + &File{"e", 50, []*File{}}, |
| 27 | + &File{"f", 30, []*File{}}, |
| 28 | + }}, |
| 29 | + &File{"c", 100, []*File{}}, |
| 30 | + }} |
| 31 | + SortDesc(testTree) |
| 32 | + if !reflect.DeepEqual(testTree, expected) { |
| 33 | + t.Errorf("tree not sorted correctly\ntree %v\nnot as expected %v", testTree, expected) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +func TestPruneTree(t *testing.T) { |
| 38 | + testTree := &File{"b", 260, []*File{ |
| 39 | + &File{"c", 100, []*File{}}, |
| 40 | + &File{"d", 160, []*File{ |
| 41 | + &File{"e", 50, []*File{}}, |
| 42 | + &File{"f", 30, []*File{}}, |
| 43 | + &File{"g", 80, []*File{ |
| 44 | + &File{"i", 50, []*File{}}, |
| 45 | + &File{"j", 30, []*File{}}, |
| 46 | + }}, |
| 47 | + }}, |
| 48 | + }} |
| 49 | + expected := &File{"b", 260, []*File{ |
| 50 | + &File{"c", 100, []*File{}}, |
| 51 | + &File{"d", 160, []*File{ |
| 52 | + &File{"g", 80, []*File{}}, |
| 53 | + }}, |
| 54 | + }} |
| 55 | + PruneTree(testTree, 60) |
| 56 | + if !reflect.DeepEqual(testTree, expected) { |
| 57 | + t.Errorf("tree not pruned correctly\ntree %v\nnot as expected %v", testTree, expected) |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments