mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-15 22:57:48 +08:00
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
// File: subset_sum_test.go
|
||
// Created Time: 2023-06-24
|
||
// Author: Reanon (793584285@qq.com)
|
||
|
||
package chapter_backtracking
|
||
|
||
import (
|
||
"fmt"
|
||
"strconv"
|
||
"testing"
|
||
|
||
. "github.com/krahets/hello-algo/pkg"
|
||
)
|
||
|
||
func TestSubsetSumINaive(t *testing.T) {
|
||
nums := []int{3, 4, 5}
|
||
target := 9
|
||
res := subsetSumINaive(nums, target)
|
||
|
||
fmt.Printf("target = " + strconv.Itoa(target) + ", входной массив nums = ")
|
||
PrintSlice(nums)
|
||
|
||
fmt.Println("Все подмножества с суммой " + strconv.Itoa(target) + ": res = ")
|
||
for i := range res {
|
||
PrintSlice(res[i])
|
||
}
|
||
fmt.Println("Обратите внимание: результат этого метода содержит повторяющиеся множества")
|
||
}
|
||
|
||
func TestSubsetSumI(t *testing.T) {
|
||
nums := []int{3, 4, 5}
|
||
target := 9
|
||
res := subsetSumI(nums, target)
|
||
|
||
fmt.Printf("target = " + strconv.Itoa(target) + ", входной массив nums = ")
|
||
PrintSlice(nums)
|
||
|
||
fmt.Println("Все подмножества с суммой " + strconv.Itoa(target) + ": res = ")
|
||
for i := range res {
|
||
PrintSlice(res[i])
|
||
}
|
||
}
|
||
|
||
func TestSubsetSumII(t *testing.T) {
|
||
nums := []int{4, 4, 5}
|
||
target := 9
|
||
res := subsetSumII(nums, target)
|
||
|
||
fmt.Printf("target = " + strconv.Itoa(target) + ", входной массив nums = ")
|
||
PrintSlice(nums)
|
||
|
||
fmt.Println("Все подмножества с суммой " + strconv.Itoa(target) + ": res = ")
|
||
for i := range res {
|
||
PrintSlice(res[i])
|
||
}
|
||
}
|