Skip to content

Commit

Permalink
fix: the notEqual operator for numbers when comparing against more th…
Browse files Browse the repository at this point in the history
…an one value (#230)

Fix: the notEqual operator for numbers had a bug when comparing against more than one value
  • Loading branch information
elliotCamblor authored Dec 18, 2023
1 parent 18a65b4 commit 7e8f276
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Binary file modified bucketing-lib.debug.wasm
Binary file not shown.
Binary file modified bucketing-lib.release.wasm
Binary file not shown.
12 changes: 10 additions & 2 deletions bucketing/segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ func _checkNumberFilter(num float64, filterNums []float64, operator string) bool
return false
}

if operator == "!=" {
passesFilter := true
for _, filterNum := range filterNums {
if math.IsNaN(filterNum) || num == filterNum {
passesFilter = false
}
}
return passesFilter
}

// replace filterNums.some() logic
someValue := false
for _, filterNum := range filterNums {
Expand All @@ -271,8 +281,6 @@ func _checkNumberFilter(num float64, filterNums []float64, operator string) bool

if operator == "=" {
someValue = num == filterNum
} else if operator == "!=" {
someValue = num != filterNum
} else if operator == ">" {
someValue = num > filterNum
} else if operator == ">=" {
Expand Down
5 changes: 3 additions & 2 deletions bucketing/segmentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ func TestEvaluateOperator_MultiNotEqualCustomDataFilters(t *testing.T) {
SubType: "customData",
Comparator: ComparatorNotEqual,
},
Values: []interface{}{float64(0)},
Values: []interface{}{float64(0), float64(1)},
},
DataKey: "numKey",
DataKeyType: "Number",
Expand Down Expand Up @@ -1416,7 +1416,8 @@ func Test_CheckNumberFilter(t *testing.T) {
{num: 10, filterNums: []float64{15}, operator: "<=", want: true},

{num: 10, filterNums: []float64{5, 15}, operator: "!=", want: true},
{num: 10, filterNums: []float64{}, operator: "!=", want: false},
{num: 15, filterNums: []float64{5, 15}, operator: "!=", want: false},
{num: 10, filterNums: []float64{}, operator: "!=", want: true},
{num: 10, filterNums: []float64{math.NaN()}, operator: "!=", want: false},

{num: 10, filterNums: []float64{}, operator: "fakeop", want: false},
Expand Down

0 comments on commit 7e8f276

Please sign in to comment.