Fibonacci Go language learning examples and test Fibonacci number sequence method defined constants

Fibonacci ### Go language learning examples and test the Fibonacci number sequence method defined constants

1.go language test file must end test.go, such as: fib_test.go
method in 2. Test file must be the beginning of the Test, such as: func TestFibList ()

3. The code is as follows:

package learning1

import (
    "fmt"
    "testing"
)
//后一个数的值是前两个的数的和
func TestFibList(t *testing.T){
    a := 1
    b := 1
    for i:=0;i<10;i++{
        tmp := a
        a = b
        b = tmp + a
        fmt.Println(b)
    }
}

4. Run the test test file on the command line:

go test -v fib_test.go

5. The method of defining constants: const keyword

//同时定义多个常量
const(
    Day1 = 1
    Day2 = 2
)
//定义连续常量:itoa
const(
    Day1 = 1 + itoa        //代表连续递增常量
    Day2
    Day3
)
//上述例子中,三个值分别为 1 2 3

Guess you like

Origin www.cnblogs.com/alisleepy/p/11200313.html