bigwhite / GoProgrammingFromBeginnerToMaster

Go语言精进之路书籍配套代码
Apache License 2.0
249 stars 82 forks source link

chapter4/sources/method_set_9.go示例代码错误 #19

Closed bravility closed 2 years ago

bravility commented 2 years ago

method_set_9.go示例代码内容为女性员工:

// 返回女性员工总数
func FemaleCount(s Stmt) (int, error) {
    result, err := s.Exec("select count(*) from employee_tab where gender=?", "1")
    if err != nil {
        return 0, err
    }

    return result.Int(), nil
}

但method_set_9_test.go的示例代码内容则为男性员工:

func TestEmployeeMaleCount(t *testing.T) {
    f := fakeStmtForMaleCount{}
    c, _ := MaleCount(f)
    if c != 5 {
        t.Errorf("want: %d, actual: %d", 5, c)
        return
    }
}

同时微信读书24.2中引用的示例代码也是男性员工,所以推断应该以书中男性员工为准: image

bigwhite commented 2 years ago

感谢指出问题,已更新示例代码。