Testing Container Capacity Algorithm Implementation in hello-algo
This test suite validates the maxCapacity function implementation in the hello-algo repository, focusing on container capacity calculations using a greedy algorithm approach. The tests verify the algorithm’s ability to find the maximum water volume that can be contained between vertical lines of varying heights.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
krahets/hello-algo
codes/go/chapter_greedy/max_capacity_test.go
// File: max_capacity_test.go
// Created Time: 2023-07-23
// Author: Reanon ([email protected])
package chapter_greedy
import (
"fmt"
"testing"
)
func TestMaxCapacity(t *testing.T) {
ht := []int{3, 8, 5, 2, 7, 7, 3, 4}
// 贪心算法
res := maxCapacity(ht)
fmt.Println("最大容量为", res)
}