From de24f6eba967a244120548c9f40f05a9aed823d4 Mon Sep 17 00:00:00 2001 From: Salma Date: Tue, 5 Mar 2024 02:01:50 +0530 Subject: [PATCH] test(challenge1): Enhance test coverage for stats --- challenge1/stats_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge1/stats_test.go diff --git a/challenge1/stats_test.go b/challenge1/stats_test.go new file mode 100644 index 0000000..78f9e15 --- /dev/null +++ b/challenge1/stats_test.go @@ -0,0 +1,27 @@ + +package main + +import "testing" + +func TestFormatStats(t *testing.T) { + cases := []struct { + Description string + InputStats stats + InputFilename string + Want string + }{ + {"Empty", stats{bytes: 0, words: 0, lines: 0, chars: 0}, "", "0\t0\t0\t"}, + {"Default", stats{bytes: 11, words: 2, lines: 1, chars: 0}, "filename", "1\t2\t11\tfilename"}, + {"Chars", stats{bytes: 0, words: 0, lines: 0, chars: 100}, "filename", "100\tfilename"}, + } + + for _, test := range cases { + t.Run(test.Description, func(t *testing.T) { + got := formatStats(true, true, true, true, test.InputStats, test.InputFilename) + + if got != test.Want { + t.Errorf("got %v, want %v", got, test.Want) + } + }) + } +}