Last active
August 29, 2015 14:01
-
-
Save up1/60da6e893be3e7715c97 to your computer and use it in GitHub Desktop.
Go :: coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package size | |
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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Size(a int) string { | |
GoCover.Count[0] = 1 | |
switch { | |
case a < 0: | |
GoCover.Count[2] = 1 | |
return "negative" | |
case a == 0: | |
GoCover.Count[3] = 1 | |
return "zero" | |
case a < 10: | |
GoCover.Count[4] = 1 | |
return "small" | |
case a < 100: | |
GoCover.Count[5] = 1 | |
return "big" | |
case a < 1000: | |
GoCover.Count[6] = 1 | |
return "huge" | |
} | |
GoCover.Count[1] = 1 | |
return "enormous" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package size | |
import "testing" | |
type Test struct { | |
in int | |
out string | |
} | |
var tests = []Test{ | |
{-1, "negative"}, | |
{5, "small"}, | |
} | |
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment