2020-03-10 12:20:34 -07:00
|
|
|
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
|
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
|
|
|
|
package snowball
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParametersValid(t *testing.T) {
|
|
|
|
p := Parameters{
|
2020-03-28 13:55:11 -07:00
|
|
|
K: 1,
|
|
|
|
Alpha: 1,
|
|
|
|
BetaVirtuous: 1,
|
|
|
|
BetaRogue: 1,
|
|
|
|
ConcurrentRepolls: 1,
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.Valid(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParametersInvalidK(t *testing.T) {
|
|
|
|
p := Parameters{
|
2020-03-28 13:55:11 -07:00
|
|
|
K: 0,
|
|
|
|
Alpha: 1,
|
|
|
|
BetaVirtuous: 1,
|
|
|
|
BetaRogue: 1,
|
|
|
|
ConcurrentRepolls: 1,
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.Valid(); err == nil {
|
|
|
|
t.Fatalf("Should have failed due to invalid k")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParametersInvalidAlpha(t *testing.T) {
|
|
|
|
p := Parameters{
|
2020-03-28 13:55:11 -07:00
|
|
|
K: 1,
|
|
|
|
Alpha: 0,
|
|
|
|
BetaVirtuous: 1,
|
|
|
|
BetaRogue: 1,
|
|
|
|
ConcurrentRepolls: 1,
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.Valid(); err == nil {
|
|
|
|
t.Fatalf("Should have failed due to invalid alpha")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParametersInvalidBetaVirtuous(t *testing.T) {
|
|
|
|
p := Parameters{
|
2020-03-28 13:55:11 -07:00
|
|
|
K: 1,
|
|
|
|
Alpha: 1,
|
|
|
|
BetaVirtuous: 0,
|
|
|
|
BetaRogue: 1,
|
|
|
|
ConcurrentRepolls: 1,
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.Valid(); err == nil {
|
|
|
|
t.Fatalf("Should have failed due to invalid beta virtuous")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParametersInvalidBetaRogue(t *testing.T) {
|
|
|
|
p := Parameters{
|
2020-03-28 13:55:11 -07:00
|
|
|
K: 1,
|
|
|
|
Alpha: 1,
|
|
|
|
BetaVirtuous: 1,
|
|
|
|
BetaRogue: 0,
|
|
|
|
ConcurrentRepolls: 1,
|
2020-03-10 12:20:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.Valid(); err == nil {
|
|
|
|
t.Fatalf("Should have failed due to invalid beta rogue")
|
|
|
|
}
|
|
|
|
}
|
2020-03-28 13:55:11 -07:00
|
|
|
|
|
|
|
func TestParametersInvalidConcurrentRepolls(t *testing.T) {
|
|
|
|
p := Parameters{
|
|
|
|
K: 1,
|
|
|
|
Alpha: 1,
|
|
|
|
BetaVirtuous: 1,
|
|
|
|
BetaRogue: 1,
|
|
|
|
ConcurrentRepolls: 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.Valid(); err == nil {
|
|
|
|
t.Fatalf("Should have failed due to invalid concurrent repolls")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|