Skip to content

Commit

Permalink
这里Maps章节
Browse files Browse the repository at this point in the history
  • Loading branch information
william's mac committed Nov 19, 2019
1 parent b7bbc53 commit 18302de
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 302 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
5. [数组Array和切片Slices](arrays-and-slices.md) - 学习数组(Array),切片(Slice),`len`函数,可变数量参数(varargs),`range`函数和测试覆盖率(Test Coverage)。
6. [结构体struct、方法method和接口interface](structs-methods-and-interfaces.md) - 学习结构体`struct`, 方法methods, 接口`interface`和表驱动测试.
7. [指针Pointers和错误errors](pointers-and-errors.md) - 学习指针和错误。
8. [Maps](maps.md) - Learn about storing values in the map data structure.
8. [字典Maps](maps.md) - 学习如何在字典数据结构中存储值。
9. [Dependency Injection](dependency-injection.md) - Learn about dependency injection, how it relates to using interfaces and a primer on io.
10. [Mocking](mocking.md) - Take some existing untested code and use DI with mocking to test it.
11. [Concurrency](concurrency.md) - Learn how to write concurrent code to make your software faster.
Expand Down
377 changes: 127 additions & 250 deletions maps.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions maps/v1/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ func TestSearch(t *testing.T) {
dictionary := Dictionary{"test": "this is just a test"}

got := dictionary.Search("test")
want := "this is just a test"
expected := "this is just a test"

assertStrings(t, got, want)
assertStrings(t, got, expected)
}

func assertStrings(t *testing.T, got, want string) {
func assertStrings(t *testing.T, got, expected string) {
t.Helper()

if got != want {
t.Errorf("got %q want %q", got, want)
if got != expected {
t.Errorf("got %q expected %q", got, expected)
}
}
16 changes: 8 additions & 8 deletions maps/v2/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ func TestSearch(t *testing.T) {

t.Run("known word", func(t *testing.T) {
got, _ := dictionary.Search("test")
want := "this is just a test"
expected := "this is just a test"

assertStrings(t, got, want)
assertStrings(t, got, expected)
})

t.Run("unknown word", func(t *testing.T) {
Expand All @@ -21,18 +21,18 @@ func TestSearch(t *testing.T) {
})
}

func assertStrings(t *testing.T, got, want string) {
func assertStrings(t *testing.T, got, expected string) {
t.Helper()

if got != want {
t.Errorf("got %q want %q", got, want)
if got != expected {
t.Errorf("got %q expected %q", got, expected)
}
}

func assertError(t *testing.T, got, want error) {
func assertError(t *testing.T, got, expected error) {
t.Helper()

if got != want {
t.Errorf("got error %q want %q", got, want)
if got != expected {
t.Errorf("got error %q expected %q", got, expected)
}
}
18 changes: 9 additions & 9 deletions maps/v3/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ func TestSearch(t *testing.T) {

t.Run("known word", func(t *testing.T) {
got, _ := dictionary.Search("test")
want := "this is just a test"
expected := "this is just a test"

assertStrings(t, got, want)
assertStrings(t, got, expected)
})

t.Run("unknown word", func(t *testing.T) {
Expand All @@ -31,19 +31,19 @@ func TestAdd(t *testing.T) {
assertDefinition(t, dictionary, word, definition)
}

func assertStrings(t *testing.T, got, want string) {
func assertStrings(t *testing.T, got, expected string) {
t.Helper()

if got != want {
t.Errorf("got %q want %q", got, want)
if got != expected {
t.Errorf("got %q expected %q", got, expected)
}
}

func assertError(t *testing.T, got, want error) {
func assertError(t *testing.T, got, expected error) {
t.Helper()

if got != want {
t.Errorf("got error %q want %q", got, want)
if got != expected {
t.Errorf("got error %q expected %q", got, expected)
}
}

Expand All @@ -56,6 +56,6 @@ func assertDefinition(t *testing.T, dictionary Dictionary, word, definition stri
}

if definition != got {
t.Errorf("got %q want %q", got, definition)
t.Errorf("got %q expected %q", got, definition)
}
}
18 changes: 9 additions & 9 deletions maps/v4/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ func TestSearch(t *testing.T) {

t.Run("known word", func(t *testing.T) {
got, _ := dictionary.Search("test")
want := "this is just a test"
expected := "this is just a test"

assertStrings(t, got, want)
assertStrings(t, got, expected)
})

t.Run("unknown word", func(t *testing.T) {
Expand Down Expand Up @@ -44,19 +44,19 @@ func TestAdd(t *testing.T) {
})
}

func assertStrings(t *testing.T, got, want string) {
func assertStrings(t *testing.T, got, expected string) {
t.Helper()

if got != want {
t.Errorf("got %q want %q", got, want)
if got != expected {
t.Errorf("got %q expected %q", got, expected)
}
}

func assertError(t *testing.T, got, want error) {
func assertError(t *testing.T, got, expected error) {
t.Helper()

if got != want {
t.Errorf("got error %q want %q", got, want)
if got != expected {
t.Errorf("got error %q expected %q", got, expected)
}
}

Expand All @@ -69,6 +69,6 @@ func assertDefinition(t *testing.T, dictionary Dictionary, word, definition stri
}

if definition != got {
t.Errorf("got %q want %q", got, definition)
t.Errorf("got %q expected %q", got, definition)
}
}
2 changes: 1 addition & 1 deletion maps/v5/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ func assertDefinition(t *testing.T, dictionary Dictionary, word, definition stri
}

if definition != got {
t.Errorf("got %q want %q", got, definition)
t.Errorf("got %q expected %q", got, definition)
}
}
18 changes: 9 additions & 9 deletions maps/v6/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ func TestSearch(t *testing.T) {

t.Run("known word", func(t *testing.T) {
got, _ := dictionary.Search("test")
want := "this is just a test"
expected := "this is just a test"

assertStrings(t, got, want)
assertStrings(t, got, expected)
})

t.Run("unknown word", func(t *testing.T) {
Expand Down Expand Up @@ -67,19 +67,19 @@ func TestUpdate(t *testing.T) {
})
}

func assertStrings(t *testing.T, got, want string) {
func assertStrings(t *testing.T, got, expected string) {
t.Helper()

if got != want {
t.Errorf("got %q want %q", got, want)
if got != expected {
t.Errorf("got %q expected %q", got, expected)
}
}

func assertError(t *testing.T, got, want error) {
func assertError(t *testing.T, got, expected error) {
t.Helper()

if got != want {
t.Errorf("got error %q want %q", got, want)
if got != expected {
t.Errorf("got error %q expected %q", got, expected)
}
}

Expand All @@ -92,6 +92,6 @@ func assertDefinition(t *testing.T, dictionary Dictionary, word, definition stri
}

if definition != got {
t.Errorf("got %q want %q", got, definition)
t.Errorf("got %q expected %q", got, definition)
}
}
18 changes: 9 additions & 9 deletions maps/v7/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ func TestSearch(t *testing.T) {

t.Run("known word", func(t *testing.T) {
got, _ := dictionary.Search("test")
want := "this is just a test"
expected := "this is just a test"

assertStrings(t, got, want)
assertStrings(t, got, expected)
})

t.Run("unknown word", func(t *testing.T) {
Expand Down Expand Up @@ -79,19 +79,19 @@ func TestDelete(t *testing.T) {
}
}

func assertStrings(t *testing.T, got, want string) {
func assertStrings(t *testing.T, got, expected string) {
t.Helper()

if got != want {
t.Errorf("got %q want %q", got, want)
if got != expected {
t.Errorf("got %q expected %q", got, expected)
}
}

func assertError(t *testing.T, got, want error) {
func assertError(t *testing.T, got, expected error) {
t.Helper()

if got != want {
t.Errorf("got error %q want %q", got, want)
if got != expected {
t.Errorf("got error %q expected %q", got, expected)
}
}

Expand All @@ -104,6 +104,6 @@ func assertDefinition(t *testing.T, dictionary Dictionary, word, definition stri
}

if definition != got {
t.Errorf("got %q want %q", got, definition)
t.Errorf("got %q expected %q", got, definition)
}
}
2 changes: 1 addition & 1 deletion pointers-and-errors.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 指针(Point)和错误(Error)
# 指针(Pointer)和错误(Error)

**[本章代码](https://github.com/spring2go/learn-go-with-tests/tree/master/pointers)**

Expand Down

0 comments on commit 18302de

Please sign in to comment.