|
|
|
@ -13,6 +13,11 @@ func TestDefaultsZero(t *testing.T) {
|
|
|
|
|
be.Equal(t, 0, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEmpty(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(1, []ks.Book{})
|
|
|
|
|
be.Equal(t, 0, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFitsOne(t *testing.T) {
|
|
|
|
|
result := ks.MaxValue(1, []ks.Book{
|
|
|
|
|
{Weight: 1, Value: 2},
|
|
|
|
@ -45,3 +50,48 @@ func TestIgnoresTooBig(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
be.Equal(t, 1, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dynamic
|
|
|
|
|
|
|
|
|
|
func TestDynamicDefaultsZero(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(0, []ks.Book{})
|
|
|
|
|
be.Equal(t, 0, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDynamicFitsOne(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(1, []ks.Book{
|
|
|
|
|
{Weight: 1, Value: 2},
|
|
|
|
|
})
|
|
|
|
|
be.Equal(t, 2, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDynamicFitsHigher(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(1, []ks.Book{
|
|
|
|
|
{Weight: 1, Value: 3},
|
|
|
|
|
{Weight: 1, Value: 2},
|
|
|
|
|
})
|
|
|
|
|
be.Equal(t, 3, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDynamicPrefersMultiple(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(3, []ks.Book{
|
|
|
|
|
{Weight: 3, Value: 4},
|
|
|
|
|
{Weight: 1, Value: 1},
|
|
|
|
|
{Weight: 1, Value: 2},
|
|
|
|
|
{Weight: 1, Value: 3},
|
|
|
|
|
})
|
|
|
|
|
be.Equal(t, 6, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDynamicIgnoresTooBig(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(1, []ks.Book{
|
|
|
|
|
{Weight: 10, Value: 4},
|
|
|
|
|
{Weight: 1, Value: 1},
|
|
|
|
|
})
|
|
|
|
|
be.Equal(t, 1, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDynamicEmpty(t *testing.T) {
|
|
|
|
|
result := ks.DynamicMaxValue(1, []ks.Book{})
|
|
|
|
|
be.Equal(t, 0, result)
|
|
|
|
|
}
|
|
|
|
|