@@ -559,3 +559,30 @@ func TestReadLines(t *testing.T) {
559559 }
560560 }
561561}
562+
563+ func TestGetWidths (t * testing.T ) {
564+ tests := []struct {
565+ wtot int
566+ ratios []int
567+ drawbox bool
568+ exp []int
569+ }{
570+ {0 , []int {1 }, false , []int {0 }},
571+ {0 , []int {1 }, true , []int {0 }},
572+ {0 , []int {1 , 3 , 2 }, false , []int {0 , 0 , 0 }},
573+ {0 , []int {1 , 3 , 2 }, true , []int {0 , 0 , 0 }},
574+ {14 , []int {1 , 3 , 2 }, false , []int {2 , 6 , 4 }},
575+ {16 , []int {1 , 3 , 2 }, true , []int {2 , 6 , 4 }},
576+ {23 , []int {1 , 3 , 2 , 4 }, false , []int {2 , 6 , 4 , 8 }}, // windows end at 2.0, 8.0, 12.0, 20.0 respectively
577+ {24 , []int {1 , 3 , 2 , 4 }, false , []int {2 , 6 , 5 , 8 }}, // windows end at 2.1, 8.4, 12.6, 21.0 respectively
578+ {25 , []int {1 , 3 , 2 , 4 }, false , []int {2 , 7 , 4 , 9 }}, // windows end at 2.2, 8.8, 13.2, 22.0 respectively
579+ {26 , []int {1 , 3 , 2 , 4 }, false , []int {2 , 7 , 5 , 9 }}, // windows end at 2.3, 9.2, 13.8, 23.0 respectively
580+ }
581+
582+ for _ , test := range tests {
583+ widths := getWidths (test .wtot , test .ratios , test .drawbox )
584+ if ! reflect .DeepEqual (widths , test .exp ) {
585+ t .Errorf ("at input (%v, %v, %v) expected %v but got %v" , test .wtot , test .ratios , test .drawbox , test .exp , widths )
586+ }
587+ }
588+ }
0 commit comments