Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改 maps.md 中的几处错误 #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions zh-CN/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,17 @@ func TestCheckWebsites(t *testing.T) {
"waat://furhurterwe.geds",
}

actualResults := CheckWebsites(mockWebsiteChecker, websites)
want := map[string]bool{
"http://google.com": true,
"http://blog.gypsydave5.com": true,
"waat://furhurterwe.geds": false,
}

want := len(websites)
got := len(actualResults)
if want != got {
t.Fatalf("Wanted %v, got %v", want, got)
}

expectedResults := map[string]bool{
"http://google.com": true,
"http://blog.gypsydave5.com": true,
"waat://furhurterwe.geds": false,
}
got := CheckWebsites(mockWebsiteChecker, websites)

if !reflect.DeepEqual(expectedResults, actualResults) {
t.Fatalf("Wanted %v, got %v", expectedResults, actualResults)
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("Wanted %v, got %v", want, got)
}
}
```
该功能在生产环境中被用于检查数百个网站。但是你的同事开始抱怨它速度很慢,所以他们请你帮忙为程序提速。
Expand Down
8 changes: 4 additions & 4 deletions zh-CN/maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func TestUpdate(t *testing.T) {
}
```

`Update` 与 `Create` 密切相关,这是下一个需要我们实现的方法。
`Update` 与 `Add` 密切相关,这是下一个需要我们实现的方法。

## 尝试运行测试

Expand All @@ -476,15 +476,15 @@ dictionary_test.go:55: got 'this is just a test' want 'new definition'

## 编写足够的代码使测试通过

当我们用 `Create` 解决问题时就明白了如何处理这个问题。所以让我们实现一个与 `Create` 非常相似的方法。
当我们用 `Add` 解决问题时就明白了如何处理这个问题。所以让我们实现一个与 `Add` 非常相似的方法。

```go
func (d Dictionary) Update(word, definition string) {
d[word] = definition
}
```

我们不需要对此进行重构,因为更改很简单。但是,我们现在遇到与 `Create` 相同的问题。如果我们传入一个新单词,`Update` 会将它添加到字典中。
我们不需要对此进行重构,因为更改很简单。但是,我们现在遇到与 `Add` 相同的问题。如果我们传入一个新单词,`Update` 会将它添加到字典中。

## 首先编写测试

Expand Down Expand Up @@ -626,7 +626,7 @@ func (d Dictionary) Delete(word string) {

Go 的 map 有一个内置函数 `delete`。它需要两个参数。第一个是这个 map,第二个是要删除的键。

`delete` 函数不返回任何内容,我们基于相同的概念构建 `Delete` 方法。由于删除一个不存在的值是没有影响的,与我们的 `Update` 和 `Create` 方法不同,我们不需要用错误复杂化 API。
`delete` 函数不返回任何内容,我们基于相同的概念构建 `Delete` 方法。由于删除一个不存在的值是没有影响的,与我们的 `Update` 和 `Add` 方法不同,我们不需要用错误复杂化 API。

## 总结

Expand Down