Skip to content

Commit

Permalink
Merge pull request #275 from checkr/zz/fix-float-equal
Browse files Browse the repository at this point in the history
Fix float comparison
  • Loading branch information
zhouzhuojie authored Jul 5, 2019
2 parents acf2fe2 + e01a5e0 commit 5b62880
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ require (
github.com/tinylib/msgp v1.1.0 // indirect
github.com/urfave/negroni v0.3.0
github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67
github.com/zhouzhuojie/conditions v0.0.0-20190213052452-7de314ba1d59
github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87
github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5
golang.org/x/net v0.0.0-20190313220215-9f648a60d977
golang.org/x/sys v0.0.0-20190312061237-fead79001313 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ github.com/tinylib/msgp v1.1.0 h1:9fQd+ICuRIu/ue4vxJZu6/LzxN0HwMds2nq/0cFvxHU=
github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/urfave/negroni v0.3.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67/go.mod h1:eRmB4tpcIoEUfMNyiXTbnZtzfODhBhZB3BIWGDD+vLs=
github.com/zhouzhuojie/conditions v0.0.0-20190213052452-7de314ba1d59 h1:T+NwShgssYUhadQdSZrmDBhpl462zdAq1Na6/jJ/OI8=
github.com/zhouzhuojie/conditions v0.0.0-20190213052452-7de314ba1d59/go.mod h1:Izhy98HD3MkfwGPz+p9ZV2JuqrpbHjaQbUq9iZHh+ZY=
github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87 h1:5pQTfWe/n9OvmwOamjhkePoT3dtJv0If1CXl3zkhSZg=
github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87/go.mod h1:Izhy98HD3MkfwGPz+p9ZV2JuqrpbHjaQbUq9iZHh+ZY=
github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5 h1:YuR5otuPvpk6EPrKy9rVXiQKTqgY6OEqSlzko9kcfCI=
github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5/go.mod h1:nhm/3zpPm56iKoXLEeeevuI5V9qEtNhuhLbPZwcrgcs=
go.opencensus.io v0.20.1 h1:pMEjRZ1M4ebWGikflH7nQpV6+Zr88KBMA2XJD3sbijw=
Expand Down
54 changes: 54 additions & 0 deletions pkg/handler/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,60 @@ func TestEvalSegment(t *testing.T) {
assert.NotEmpty(t, log)
assert.True(t, evalNextSegment)
})

t.Run("test float comparison - 9990403>=9990404 evals to be false", func(t *testing.T) {
s := entity.GenFixtureSegment()
s.RolloutPercent = uint(100)
s.Constraints = []entity.Constraint{
{
Model: gorm.Model{ID: 500},
SegmentID: 200,
Property: "foo",
Operator: models.ConstraintOperatorGTE,
Value: `9990404`,
},
}
s.PrepareEvaluation()

vID, log, evalNextSegment := evalSegment(100, models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"foo": float64(9990403)},
EntityID: "entityID1",
EntityType: "entityType1",
FlagID: int64(100),
}, s)

assert.Nil(t, vID)
assert.NotZero(t, log)
assert.True(t, evalNextSegment)
})

t.Run("test float comparison - 9990404>=9990403 evals to be true", func(t *testing.T) {
s := entity.GenFixtureSegment()
s.RolloutPercent = uint(100)
s.Constraints = []entity.Constraint{
{
Model: gorm.Model{ID: 500},
SegmentID: 200,
Property: "foo",
Operator: models.ConstraintOperatorGTE,
Value: `9990403`,
},
}
s.PrepareEvaluation()

vID, log, evalNextSegment := evalSegment(100, models.EvalContext{
EnableDebug: true,
EntityContext: map[string]interface{}{"foo": float64(9990404)},
EntityID: "entityID1",
EntityType: "entityType1",
FlagID: int64(100),
}, s)

assert.NotZero(t, vID)
assert.NotZero(t, log)
assert.False(t, evalNextSegment)
})
}

func TestEvalFlag(t *testing.T) {
Expand Down
8 changes: 7 additions & 1 deletion vendor/github.com/zhouzhuojie/conditions/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions vendor/github.com/zhouzhuojie/conditions/evaluator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ github.com/tinylib/msgp/msgp
github.com/urfave/negroni
# github.com/yadvendar/negroni-newrelic-go-agent v0.0.0-20160803090806-3dc58758cb67
github.com/yadvendar/negroni-newrelic-go-agent
# github.com/zhouzhuojie/conditions v0.0.0-20190213052452-7de314ba1d59
# github.com/zhouzhuojie/conditions v0.0.0-20190705160302-784df330cb87
github.com/zhouzhuojie/conditions
# github.com/zhouzhuojie/withtimeout v0.0.0-20190405051827-12b39eb2edd5
github.com/zhouzhuojie/withtimeout
Expand Down

0 comments on commit 5b62880

Please sign in to comment.