feat: friday

This commit is contained in:
2026-02-13 18:29:01 -05:00
parent 279ff88836
commit 2cac846a4d
2 changed files with 167 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
package pacificatlanticwaterflow
import (
"sort"
"testing"
)
func sortResult(result [][]int) {
sort.Slice(result, func(i, j int) bool {
if result[i][0] != result[j][0] {
return result[i][0] < result[j][0]
}
return result[i][1] < result[j][1]
})
}
func TestPacificAtlantic(t *testing.T) {
tests := []struct {
name string
heights [][]int
expected [][]int
}{
{
name: "5x5 grid",
heights: [][]int{
{1, 2, 2, 3, 5},
{3, 2, 3, 4, 4},
{2, 4, 5, 3, 1},
{6, 7, 1, 4, 5},
{5, 1, 1, 2, 4},
},
expected: [][]int{{0, 4}, {1, 3}, {1, 4}, {2, 2}, {3, 0}, {3, 1}, {4, 0}},
},
{
name: "3x2 all ones",
heights: [][]int{
{1, 1},
{1, 1},
{1, 1},
},
expected: [][]int{{0, 0}, {0, 1}, {1, 0}, {1, 1}, {2, 0}, {2, 1}},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := PacificAtlantic(tc.heights)
sortResult(result)
sortResult(tc.expected)
if len(result) != len(tc.expected) {
t.Fatalf("expected %d results, got %d: %v", len(tc.expected), len(result), result)
}
for i := range tc.expected {
if result[i][0] != tc.expected[i][0] || result[i][1] != tc.expected[i][1] {
t.Errorf("result[%d] = %v, expected %v", i, result[i], tc.expected[i])
}
}
})
}
}