Testing Permutation Algorithm Implementation in hello-algo
This test suite validates permutation algorithms implementation in Go, focusing on both unique and duplicate element permutations. It ensures correct generation of all possible permutations for given input arrays using backtracking techniques.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
krahets/hello-algo
zh-hant/codes/go/chapter_backtracking/permutation_test.go
// File: permutation_test.go
// Created Time: 2023-05-09
// Author: Reanon ([email protected])
package chapter_backtracking
import (
"fmt"
"testing"
. "github.com/krahets/hello-algo/pkg"
)
func TestPermutationI(t *testing.T) {
/* 全排列 I */
nums := []int{1, 2, 3}
fmt.Printf("輸入陣列 nums = ")
PrintSlice(nums)
res := permutationsI(nums)
fmt.Printf("所有排列 res = ")
fmt.Println(res)
}
func TestPermutationII(t *testing.T) {
nums := []int{1, 2, 2}
fmt.Printf("輸入陣列 nums = ")
PrintSlice(nums)
res := permutationsII(nums)
fmt.Printf("所有排列 res = ")
fmt.Println(res)
}