Skip to content

Commit

Permalink
additional unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed May 21, 2024
1 parent 3f76572 commit 3df4aaa
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions core/pkg/evaluator/fractional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evaluator

import (
"context"
"github.com/stretchr/testify/assert"
"testing"

"github.com/open-feature/flagd/core/pkg/logger"
Expand Down Expand Up @@ -579,3 +580,49 @@ func BenchmarkFractionalEvaluation(b *testing.B) {
})
}
}

func Test_fractionalEvaluationVariant_getPercentage(t *testing.T) {
type fields struct {
variant string
weight int
}
type args struct {
totalWeight int
}
tests := []struct {
name string
fields fields
args args
want float64
}{
{
name: "get percentage",
fields: fields{
weight: 10,
},
args: args{
totalWeight: 20,
},
want: 50,
},
{
name: "total weight 0",
fields: fields{
weight: 10,
},
args: args{
totalWeight: 0,
},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := fractionalEvaluationVariant{
variant: tt.fields.variant,
weight: tt.fields.weight,
}
assert.Equalf(t, tt.want, v.getPercentage(tt.args.totalWeight), "getPercentage(%v)", tt.args.totalWeight)
})
}
}

0 comments on commit 3df4aaa

Please sign in to comment.