From 6323982964d80602f331d907c610a99b389ad57f Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 1 May 2020 22:17:16 +0300 Subject: [PATCH] fix test for behaviour penalty validation --- score_params.go | 3 ++- score_params_test.go | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/score_params.go b/score_params.go index 7f07428..ad2bc24 100644 --- a/score_params.go +++ b/score_params.go @@ -164,10 +164,11 @@ func (p *PeerScoreParams) validate() error { if p.IPColocationFactorWeight > 0 { return fmt.Errorf("invalid IPColocationFactorWeight; must be negative (or 0 to disable)") } - if p.IPColocationFactorWeight < 0 && p.IPColocationFactorThreshold < 1 { + if p.IPColocationFactorWeight != 0 && p.IPColocationFactorThreshold < 1 { return fmt.Errorf("invalid IPColocationFactorThreshold; must be at least 1") } + // check the behaviour penalty if p.BehaviourPenaltyWeight > 0 { return fmt.Errorf("invalid BehaviourPenaltyWeight; must be negative (or 0 to disable)") } diff --git a/score_params_test.go b/score_params_test.go index e617098..45018d7 100644 --- a/score_params_test.go +++ b/score_params_test.go @@ -153,17 +153,29 @@ func TestPeerScoreParamsValidation(t *testing.T) { if (&PeerScoreParams{TopicScoreCap: 1, AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 2, IPColocationFactorWeight: -1, IPColocationFactorThreshold: 1}).validate() == nil { t.Fatal("expected validation error") } - if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: 1}) == nil { + if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: 1}).validate() == nil { t.Fatal("expected validation error") } - if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1}) == nil { + if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1}).validate() == nil { t.Fatal("expected validation error") } - if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1, BehaviourPenaltyDecay: 2}) == nil { + if (&PeerScoreParams{AppSpecificScore: appScore, DecayInterval: time.Second, DecayToZero: 0.01, BehaviourPenaltyWeight: -1, BehaviourPenaltyDecay: 2}).validate() == nil { t.Fatal("expected validation error") } // don't use these params in production! + if (&PeerScoreParams{ + AppSpecificScore: appScore, + DecayInterval: time.Second, + DecayToZero: 0.01, + IPColocationFactorWeight: -1, + IPColocationFactorThreshold: 1, + BehaviourPenaltyWeight: -1, + BehaviourPenaltyDecay: 0.999, + }).validate() != nil { + t.Fatal("expected validation success") + } + if (&PeerScoreParams{ TopicScoreCap: 1, AppSpecificScore: appScore, @@ -177,7 +189,6 @@ func TestPeerScoreParamsValidation(t *testing.T) { t.Fatal("expected validation success") } - // don't use these params in production! if (&PeerScoreParams{ TopicScoreCap: 1, AppSpecificScore: appScore,