// recursive_function_demo.go 文件
package function_demo
// Factorial 计算N的阶乘
func Factorial(n int) int {
if n <= 1 {
return 1
}
return n * Factorial(n-1)
}
// Fibonacci 计算斐波那契数列的第n项
func Fibonacci(n int) int {
if n <= 1 {
return n
}
return Fibonacci(n-1) + Fibonacci(n-2)
}
// recursive_function_demo_test.go 文件
package function_demo
import (
"fmt"
"testing"
)
func TestFactorial(t *testing.T) {
fmt.Println("10的阶乘: ", Factorial(10))
}
func TestFibonacci(t *testing.T) {
fmt.Println("斐波那契数列: ", Fibonacci(10))
}