-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package client | ||
|
||
//会引入我们GetFibonacci所在的本地包 | ||
import ( | ||
"ch14/series" | ||
"testing" | ||
) | ||
|
||
func TestPackage(t *testing.T) { | ||
t.Log(series.GetFibonacci(5)) | ||
//t.Log(series.square(5)) | ||
} | ||
|
||
//执行结果 重名的init方法被执行两次 | ||
//init1 | ||
//init2 | ||
//=== RUN TestPackage | ||
//--- PASS: TestPackage (0.00s) | ||
//package_test.go:10: [1 1 2 3 5] <nil> | ||
//PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package series | ||
|
||
import "fmt" | ||
|
||
func init() { | ||
fmt.Println("init1") | ||
} | ||
|
||
func init() { | ||
fmt.Println("init2") | ||
} | ||
|
||
|
||
|
||
//大写字母开头包外可以访问 | ||
func GetFibonacci(n int) ([]int, error) { | ||
fibList := []int{1, 1} | ||
for i := 2; /*短变量声明*/ i < n; i++ { | ||
fibList = append(fibList, fibList[i-2]+fibList[i-1]) | ||
} | ||
return fibList, nil | ||
} | ||
|
||
//小写字母开头包外不能访问 | ||
func square(n int) int { | ||
return n * n | ||
} |