diff --git a/playground/codecoverage/size.go b/playground/codecoverage/size.go new file mode 100644 index 0000000..ec52f77 --- /dev/null +++ b/playground/codecoverage/size.go @@ -0,0 +1,17 @@ +package codecoverage + +func Size(a int) string { + switch { + case a < 0: + return "negative" + case a == 0: + return "zero" + case a < 10: + return "small" + case a < 100: + return "big" + case a < 1000: + return "huge" + } + return "enormous" +} diff --git a/playground/codecoverage/size_test.go b/playground/codecoverage/size_test.go new file mode 100644 index 0000000..8fbdca2 --- /dev/null +++ b/playground/codecoverage/size_test.go @@ -0,0 +1,26 @@ +package codecoverage + +import "testing" + +type Test struct { + in int + out string +} + +var tests = []Test{ + {-1, "negative"}, + {0, "zero"}, + {5, "small"}, + {99, "big"}, + {100, "huge"}, + {10001, "enormous"}, +} + +func TestSize(t *testing.T) { + for i, test := range tests { + size := Size(test.in) + if size != test.out { + t.Errorf("#%d: Size(%d)=%s; want %s", i, test.in, size, test.out) + } + } +}