summaryrefslogtreecommitdiff
path: root/go/secret-handshake/secret_handshake_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-25 12:34:26 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-25 12:34:26 +0200
commitc460ce761cb29d8d04f302dc6fd62fd0c170bfab (patch)
treee9e2d4d01c8cf06d6e0bcb331179e6f2e90bb349 /go/secret-handshake/secret_handshake_test.go
parentff662e72997f80c940ddb6f08b032a05f8f4f285 (diff)
Handshake
Diffstat (limited to 'go/secret-handshake/secret_handshake_test.go')
-rw-r--r--go/secret-handshake/secret_handshake_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/go/secret-handshake/secret_handshake_test.go b/go/secret-handshake/secret_handshake_test.go
new file mode 100644
index 0000000..65fd058
--- /dev/null
+++ b/go/secret-handshake/secret_handshake_test.go
@@ -0,0 +1,43 @@
+package secret
+
+import (
+ "reflect"
+ "testing"
+)
+
+var tests = []struct {
+ code int
+ h []string
+}{
+ {1, []string{"wink"}},
+ {2, []string{"double blink"}},
+ {4, []string{"close your eyes"}},
+ {8, []string{"jump"}},
+ {3, []string{"wink", "double blink"}},
+ {19, []string{"double blink", "wink"}},
+ {31, []string{"jump", "close your eyes", "double blink", "wink"}},
+ {0, nil},
+ {-1, nil},
+ {32, nil},
+ {33, []string{"wink"}},
+}
+
+func TestHandshake(t *testing.T) {
+ for _, test := range tests {
+ h := Handshake(test.code)
+ // use len() to allow either nil or empty list, because
+ // they are not equal by DeepEqual
+ if len(h) == 0 && len(test.h) == 0 {
+ continue
+ }
+ if !reflect.DeepEqual(h, test.h) {
+ t.Fatalf("Handshake(%d) = %v, want %v.", test.code, h, test.h)
+ }
+ }
+}
+
+func BenchmarkHandshake(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ Handshake(31)
+ }
+}