aboutsummaryrefslogtreecommitdiff
path: root/content/cover
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2013-12-03 07:58:53 +1100
committerAndrew Gerrand <adg@golang.org>2013-12-03 07:58:53 +1100
commit1601cf2af6ed6496b7fa481b640779cf49a492ca (patch)
treeaa4ed6dc0e3a21edc636222bea6a3401524fef8c /content/cover
parentdf10efcca47e7360ce74f0ed32282991c8be150f (diff)
go.blog/cover: new article about test coverage
R=adg https://golang.org/cl/14566048
Diffstat (limited to 'content/cover')
-rw-r--r--content/cover/count.pngbin0 -> 59978 bytes
-rw-r--r--content/cover/pkg.cover49
-rw-r--r--content/cover/pkg.go17
-rw-r--r--content/cover/pkg_test.go22
-rw-r--r--content/cover/set.pngbin0 -> 43274 bytes
5 files changed, 88 insertions, 0 deletions
diff --git a/content/cover/count.png b/content/cover/count.png
new file mode 100644
index 0000000..2c66956
--- /dev/null
+++ b/content/cover/count.png
Binary files differ
diff --git a/content/cover/pkg.cover b/content/cover/pkg.cover
new file mode 100644
index 0000000..03a8cbc
--- /dev/null
+++ b/content/cover/pkg.cover
@@ -0,0 +1,49 @@
+package main
+
+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"
+}
+
+var GoCover = struct {
+ Count [7]uint32
+ Pos [3 * 7]uint32
+ NumStmt [7]uint16
+} {
+ Pos: [3 * 7]uint32{
+ 3, 4, 0x90019, // [0]
+ 16, 16, 0x130002, // [1]
+ 5, 6, 0x140002, // [2]
+ 7, 8, 0x100002, // [3]
+ 9, 10, 0x110002, // [4]
+ 11, 12, 0xf0002, // [5]
+ 13, 14, 0x100002, // [6]
+ },
+ NumStmt: [7]uint16{
+ 1, // 0
+ 1, // 1
+ 1, // 2
+ 1, // 3
+ 1, // 4
+ 1, // 5
+ 1, // 6
+ },
+}
diff --git a/content/cover/pkg.go b/content/cover/pkg.go
new file mode 100644
index 0000000..6e67107
--- /dev/null
+++ b/content/cover/pkg.go
@@ -0,0 +1,17 @@
+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"
+}
diff --git a/content/cover/pkg_test.go b/content/cover/pkg_test.go
new file mode 100644
index 0000000..8bf4b0c
--- /dev/null
+++ b/content/cover/pkg_test.go
@@ -0,0 +1,22 @@
+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)
+ }
+ }
+}
diff --git a/content/cover/set.png b/content/cover/set.png
new file mode 100644
index 0000000..d4cfca2
--- /dev/null
+++ b/content/cover/set.png
Binary files differ