You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
688 B

1 year ago
package main_test
import (
"testing"
ks "git.jxs.me/r/knapsack"
"github.com/carlmjohnson/be"
)
func TestDefaultsZero(t *testing.T) {
result := ks.MaxValue(0, []ks.Book{})
be.Equal(t, 0, result)
}
func TestFitsOne(t *testing.T) {
result := ks.MaxValue(1, []ks.Book{{Weight: 1, Value: 2}})
be.Equal(t, 2, result)
}
func TestFitsHigher(t *testing.T) {
result := ks.MaxValue(1, []ks.Book{
{Weight: 1, Value: 2},
{Weight: 1, Value: 3},
})
be.Equal(t, 3, result)
}
func TestPrefersMultiple(t *testing.T) {
result := ks.MaxValue(3, []ks.Book{
{Weight: 3, Value: 4},
{Weight: 1, Value: 1},
{Weight: 1, Value: 2},
{Weight: 1, Value: 3},
})
be.Equal(t, 6, result)
}