package redhat import ( "reflect" "testing" ) func TestFileAnalyser_Output(t *testing.T) { type args struct { topLines int } tests := []struct { name string fileAnalyser *FileAnalyser args args want []string }{ { name: "should reverse and only return top 10 items, as well as transform to output style", fileAnalyser: &FileAnalyser{ file: nil, dataRows: []dataRow{ { word: "and", count: 9, }, { word: "hello", count: 9, }, { word: "Go", count: 7, }, { word: "me", count: 7, }, { word: "the", count: 6, }, { word: "of", count: 6, }, { word: "shape", count: 5, }, { word: "libraries", count: 4, }, { word: "future", count: 3, }, { word: "Some", count: 2, }, { word: "Help", count: 1, }, }, }, args: args{ topLines: 10, }, want: []string{ "2 Some", "3 future", "4 libraries", "5 shape", "6 of", "6 the", "7 me", "7 Go", "9 hello", "9 and", }, }, { name: "should reverse and return all items when total items count is less than 10", fileAnalyser: &FileAnalyser{ file: nil, dataRows: []dataRow{ { word: "the", count: 205, }, { word: "of", count: 16, }, { word: "shape", count: 5, }, { word: "libraries", count: 4, }, { word: "future", count: 3, }, { word: "Some", count: 2, }, { word: "Help", count: 1, }, }, }, args: args{ topLines: 10, }, want: []string{ " 1 Help", " 2 Some", " 3 future", " 4 libraries", " 5 shape", " 16 of", "205 the", }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.fileAnalyser.Output(tt.args.topLines); !reflect.DeepEqual(got, tt.want) { t.Errorf("FileAnalyser.Output() = %v, want %v", got, tt.want) } }) } }