forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rod_cutting_test.go
37 lines (32 loc) · 1002 Bytes
/
rod_cutting_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
36
37
package dp
import (
"reflect"
"testing"
)
/*
TestRodCutting tests solution(s) with the following signature and problem description:
CutRod(prices []int, n int) int
Given a list containing price a table such as {1,5,8,9,10} indicating the price of
a rod of a given length (1 inch rod is $1, 2 inch rod is $5, 5 inch rod is $10) and
number n like 3, indicating the length of a given rod, calculate maximum revenue that
can be earned by cutting the rod and selling the pieces when cutting is free.
*/
func TestRodCutting(t *testing.T) {
tests := []struct {
snacks []int
n int
solution int
}{
{[]int{1}, 1, 1},
{[]int{1, 2}, 2, 2},
{[]int{1, 3, 5, 10, 15}, 2, 3},
{[]int{1, 3, 5, 10, 15}, 3, 5},
{[]int{1, 5, 8, 9, 10}, 4, 10},
{[]int{1, 5, 8, 9, 10, 20, 30}, 4, 10},
}
for i, test := range tests {
if got := CutRod(test.snacks, test.n); !reflect.DeepEqual(got, test.solution) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.solution, got)
}
}
}