1
2
3
4
5
6 package main
7
8 import "testing"
9
10
11 func lenChan_ssa(v chan int) int {
12 return len(v)
13 }
14
15
16 func capChan_ssa(v chan int) int {
17 return cap(v)
18 }
19
20 func testLenChan(t *testing.T) {
21
22 v := make(chan int, 10)
23 v <- 1
24 v <- 1
25 v <- 1
26
27 if want, got := 3, lenChan_ssa(v); got != want {
28 t.Errorf("expected len(chan) = %d, got %d", want, got)
29 }
30 }
31
32 func testLenNilChan(t *testing.T) {
33
34 var v chan int
35 if want, got := 0, lenChan_ssa(v); got != want {
36 t.Errorf("expected len(nil) = %d, got %d", want, got)
37 }
38 }
39
40 func testCapChan(t *testing.T) {
41
42 v := make(chan int, 25)
43
44 if want, got := 25, capChan_ssa(v); got != want {
45 t.Errorf("expected cap(chan) = %d, got %d", want, got)
46 }
47 }
48
49 func testCapNilChan(t *testing.T) {
50
51 var v chan int
52 if want, got := 0, capChan_ssa(v); got != want {
53 t.Errorf("expected cap(nil) = %d, got %d", want, got)
54 }
55 }
56
57 func TestChan(t *testing.T) {
58 testLenChan(t)
59 testLenNilChan(t)
60
61 testCapChan(t)
62 testCapNilChan(t)
63 }
64
View as plain text