mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-25 06:16:03 +03:00
Practice code coverage
Signed-off-by: Bruce <weichou1229@gmail.com>
This commit is contained in:
parent
01aad3573b
commit
b97231eecb
17
playground/codecoverage/size.go
Normal file
17
playground/codecoverage/size.go
Normal file
@ -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"
|
||||||
|
}
|
26
playground/codecoverage/size_test.go
Normal file
26
playground/codecoverage/size_test.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user