forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
house_robber_test.go
35 lines (30 loc) · 828 Bytes
/
house_robber_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package dp
import (
"testing"
)
/*
TestMaxHouseRobber tests solution(s) with the following signature and problem description:
func MaxHouseRobber(wealth []int) int
Given an array representing the amount of wealth inside houses like {1,2,3,4} return the
maximum wealth the robber can steal like `6` with the condition that he is not allowed to
rob two consecutive houses.
*/
func TestMaxHouseRobber(t *testing.T) {
tests := []struct {
houses []int
max int
}{
{[]int{}, 0},
{[]int{1}, 1},
{[]int{1, 2}, 2},
{[]int{1, 2, 3, 4}, 6},
{[]int{1, 3, 5, 10, 15}, 21},
{[]int{1, 5, 8, 9, 10}, 19},
{[]int{1, 5, 8, 9, 10, 20, 30}, 49},
}
for i, test := range tests {
if got := MaxHouseRobber(test.houses); got != test.max {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.max, got)
}
}
}