summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-09-23 14:26:34 -0400
committerBen Burwell <ben@benburwell.com>2019-09-23 14:26:34 -0400
commitf312016e0b70f38b48e509472680bbf6cde64179 (patch)
tree086fa9961c091dae5fb00d684965d47db8ce1d9a
parent5d3f80f17a10fcfd6b5fd4fb4a2d42afaf7dc789 (diff)
Simplify
-rw-r--r--caesar_test.go18
-rw-r--r--client/client_test.go9
-rw-r--r--custom_test.go4
-rw-r--r--run_test.go17
4 files changed, 21 insertions, 27 deletions
diff --git a/caesar_test.go b/caesar_test.go
index 674870c..43bdc1e 100644
--- a/caesar_test.go
+++ b/caesar_test.go
@@ -12,7 +12,7 @@ func TestEncode(t *testing.T) {
}
}
-func TestLong(t *testing.T) {
+func TestRepeatedEncode(t *testing.T) {
if testing.Short() {
t.Skip()
}
@@ -29,7 +29,7 @@ func TestLong(t *testing.T) {
}
}
-func TestEncoderTable(t *testing.T) {
+func TestEncodeTable(t *testing.T) {
tests := []struct {
in string
out string
@@ -47,6 +47,20 @@ func TestEncoderTable(t *testing.T) {
}
}
+func TestCoder(t *testing.T) {
+ coder := Coder{Key: 1, Ranges: []RuneRange{{'a', 'z'}}}
+ t.Run("Encode", func(t *testing.T) {
+ if coder.Encode("abc") != "bcd" {
+ t.Fail()
+ }
+ })
+ t.Run("Decode", func(t *testing.T) {
+ if coder.Decode("bcd") != "abc" {
+ t.Fail()
+ }
+ })
+}
+
func BenchmarkEncode(b *testing.B) {
for i := 0; i < b.N; i++ {
Encode("attack at dawn")
diff --git a/client/client_test.go b/client/client_test.go
index b6af2b9..a724857 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -9,13 +9,12 @@ import (
)
func TestEncode(t *testing.T) {
- var hf http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("response"))
- }
- server := httptest.NewServer(hf)
+ }))
defer server.Close()
- c := CaesarClient{Endpoint: server.URL} // HL
- r, err := c.EncodeMessage(strings.NewReader("secret message"))
+ client := CaesarClient{Endpoint: server.URL} // HL
+ r, err := client.EncodeMessage(strings.NewReader("secret message"))
if err != nil {
t.Errorf("should not have gotten error: %v", err)
}
diff --git a/custom_test.go b/custom_test.go
index e73d4d7..2556716 100644
--- a/custom_test.go
+++ b/custom_test.go
@@ -9,9 +9,7 @@ import (
"testing"
)
-var (
- customTests string
-)
+var customTests string
func TestMain(m *testing.M) {
flag.StringVar(&customTests, "custom", "", "input file for custom test cases")
diff --git a/run_test.go b/run_test.go
deleted file mode 100644
index 79a5a55..0000000
--- a/run_test.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package caesar
-
-import "testing"
-
-func TestCoder(t *testing.T) {
- coder := Coder{Key: 1, Ranges: []RuneRange{{'a', 'z'}}}
- t.Run("Encode", func(t *testing.T) {
- if coder.Encode("abc") != "bcd" {
- t.Fail()
- }
- })
- t.Run("Decode", func(t *testing.T) {
- if coder.Decode("bcd") != "abc" {
- t.Fail()
- }
- })
-}