Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace test doubles with constants #3024

Merged
merged 28 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ In most cases, they should be used instead of (deprecated) `bson.D.Map()`,
The bar for adding new helpers is very high.
Please check all existing ones.

If there's a need to use any large number to test corner cases,
we create constants for them with explanation what do they represent, and refer to them.
For example:

```go
const doubleMaxPrec = float64(1<<53 - 1) // 9007199254740991.0: largest double values that could be represented as integer exactly
chilagrow marked this conversation as resolved.
Show resolved Hide resolved
```

#### Integration tests naming guidelines

1. Test names should include the name of the command being tested.
Expand Down
74 changes: 37 additions & 37 deletions integration/query_bitwise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"Array": {
value: primitive.A{1, 5},
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-min", "int32-zero",
"int64-3", "int64-big", "int64-double-big",
"int64-min", "int64-zero",
Expand All @@ -73,8 +73,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"ArrayFloatWholeBitPositionValue": {
value: primitive.A{1.0},
expectedIDs: []any{
"double-1", "double-2", "double-4", "double-big",
"double-min-overflow-verge", "double-zero",
"double-1", "double-3", "double-big",
"double-zero",
"int32-1", "int32-2", "int32-3", "int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3", "int64-big",
"int64-double-big", "int64-min", "int64-zero",
Expand Down Expand Up @@ -108,8 +108,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"DoubleWhole": {
value: 2.0,
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-1", "int32-2", "int32-3", "int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3",
"int64-big", "int64-double-big", "int64-min", "int64-zero",
Expand Down Expand Up @@ -137,8 +137,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"Binary": {
value: primitive.Binary{Data: []byte{2}},
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-1", "int32-2", "int32-3", "int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3",
"int64-big", "int64-double-big", "int64-min", "int64-zero",
Expand All @@ -147,8 +147,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"BinaryWithZeroBytes": {
value: primitive.Binary{Data: []byte{0, 0, 2}},
expectedIDs: []any{
"double-1", "double-2", "double-3", "double-big",
"double-min-overflow-verge", "double-whole", "double-zero",
"double-1", "double-2", "double-big",
"double-whole", "double-zero",
"int32", "int32-1", "int32-min", "int32-zero",
"int64", "int64-1", "int64-big", "int64-double-big",
"int64-min", "int64-zero",
Expand All @@ -166,8 +166,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"Int32": {
value: int32(2),
expectedIDs: []any{
"double-1", "double-2", "double-4", "double-big",
"double-min-overflow-verge", "double-zero",
"double-1", "double-3", "double-big",
"double-zero",
"int32-1", "int32-2", "int32-3",
"int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3", "int64-big",
Expand All @@ -186,8 +186,8 @@ func TestQueryBitwiseAllClear(t *testing.T) {
"Int64Max": {
value: math.MaxInt64,
expectedIDs: []any{
"double-1", "double-2",
"double-min-overflow-verge", "double-zero",
"double-1",
"double-zero",
"int32-zero",
"int64-min",
"int64-zero",
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestQueryBitwiseAllSet(t *testing.T) {
}{
"Array": {
value: primitive.A{1, 5},
expectedIDs: []any{"double-3", "double-whole", "int32", "int32-max", "int64", "int64-max"},
expectedIDs: []any{"double-2", "double-whole", "int32", "int32-max", "int64", "int64-max"},
},
"ArrayNegativeBitPositionValue": {
value: primitive.A{-1},
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestQueryBitwiseAllSet(t *testing.T) {
},
"DoubleWhole": {
value: 2.0,
expectedIDs: []any{"double-3", "double-whole", "int32", "int32-max", "int64", "int64-max"},
expectedIDs: []any{"double-2", "double-whole", "int32", "int32-max", "int64", "int64-max"},
},
"DoubleNegativeValue": {
value: -1.0,
Expand All @@ -307,16 +307,16 @@ func TestQueryBitwiseAllSet(t *testing.T) {

"Binary": {
value: primitive.Binary{Data: []byte{2}},
expectedIDs: []any{"double-3", "double-whole", "int32", "int32-max", "int64", "int64-max"},
expectedIDs: []any{"double-2", "double-whole", "int32", "int32-max", "int64", "int64-max"},
},
"BinaryWithZeroBytes": {
value: primitive.Binary{Data: []byte{0, 0, 2}},
expectedIDs: []any{"double-4", "int32-2", "int32-3", "int32-max", "int64-2", "int64-3", "int64-max"},
expectedIDs: []any{"double-3", "int32-2", "int32-3", "int32-max", "int64-2", "int64-3", "int64-max"},
},

"Int32": {
value: int32(2),
expectedIDs: []any{"double-3", "double-whole", "int32", "int32-max", "int64", "int64-max"},
expectedIDs: []any{"double-2", "double-whole", "int32", "int32-max", "int64", "int64-max"},
},
"Int32NegativeValue": {
value: int32(-1),
Expand Down Expand Up @@ -394,8 +394,8 @@ func TestQueryBitwiseAnyClear(t *testing.T) {
"Array": {
value: primitive.A{1, 5},
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-1", "int32-2", "int32-3",
"int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3",
Expand Down Expand Up @@ -430,8 +430,8 @@ func TestQueryBitwiseAnyClear(t *testing.T) {
"DoubleWhole": {
value: 2.0,
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-1", "int32-2", "int32-3",
"int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3",
Expand Down Expand Up @@ -460,8 +460,8 @@ func TestQueryBitwiseAnyClear(t *testing.T) {
"Binary": {
value: primitive.Binary{Data: []byte{2}},
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-1", "int32-2", "int32-3",
"int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3",
Expand All @@ -471,8 +471,8 @@ func TestQueryBitwiseAnyClear(t *testing.T) {
"BinaryWithZeroBytes": {
value: primitive.Binary{Data: []byte{0, 0, 2}},
expectedIDs: []any{
"double-1", "double-2", "double-3",
"double-big", "double-min-overflow-verge", "double-whole", "double-zero",
"double-1", "double-2",
"double-big", "double-whole", "double-zero",
"int32", "int32-1", "int32-min", "int32-zero",
"int64", "int64-1", "int64-big", "int64-double-big",
"int64-min", "int64-zero",
Expand All @@ -482,8 +482,8 @@ func TestQueryBitwiseAnyClear(t *testing.T) {
"Int32": {
value: int32(2),
expectedIDs: []any{
"double-1", "double-2", "double-4",
"double-big", "double-min-overflow-verge", "double-zero",
"double-1", "double-3",
"double-big", "double-zero",
"int32-1", "int32-2", "int32-3",
"int32-min", "int32-zero",
"int64-1", "int64-2", "int64-3",
Expand All @@ -502,8 +502,8 @@ func TestQueryBitwiseAnyClear(t *testing.T) {
"Int64Max": {
value: math.MaxInt64,
expectedIDs: []any{
"double-1", "double-2", "double-3", "double-4",
"double-big", "double-min-overflow-verge", "double-whole", "double-zero",
"double-1", "double-2", "double-3",
"double-big", "double-whole", "double-zero",
"int32", "int32-1", "int32-2", "int32-3", "int32-max", "int32-min", "int32-zero",
"int64", "int64-1", "int64-2", "int64-3", "int64-big", "int64-double-big",
"int64-min", "int64-zero",
Expand Down Expand Up @@ -572,7 +572,7 @@ func TestQueryBitwiseAnySet(t *testing.T) {
"Array": {
value: primitive.A{1, 5},
expectedIDs: []any{
"double-3", "double-whole",
"double-2", "double-whole",
"int32", "int32-1", "int32-2", "int32-3", "int32-max",
"int64", "int64-1", "int64-2", "int64-max",
},
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestQueryBitwiseAnySet(t *testing.T) {
"DoubleWhole": {
value: 2.0,
expectedIDs: []any{
"double-3", "double-whole",
"double-2", "double-whole",
"int32", "int32-max",
"int64", "int64-max",
},
Expand All @@ -631,17 +631,17 @@ func TestQueryBitwiseAnySet(t *testing.T) {

"Binary": {
value: primitive.Binary{Data: []byte{2}},
expectedIDs: []any{"double-3", "double-whole", "int32", "int32-max", "int64", "int64-max"},
expectedIDs: []any{"double-2", "double-whole", "int32", "int32-max", "int64", "int64-max"},
},
"BinaryWithZeroBytes": {
value: primitive.Binary{Data: []byte{0, 0, 2}},
expectedIDs: []any{"double-4", "int32-2", "int32-3", "int32-max", "int64-2", "int64-3", "int64-max"},
expectedIDs: []any{"double-3", "int32-2", "int32-3", "int32-max", "int64-2", "int64-3", "int64-max"},
},

"Int32": {
value: int32(2),
expectedIDs: []any{
"double-3", "double-whole",
"double-2", "double-whole",
"int32", "int32-max",
"int64", "int64-max",
},
Expand All @@ -658,7 +658,7 @@ func TestQueryBitwiseAnySet(t *testing.T) {
"Int64Max": {
value: math.MaxInt64,
expectedIDs: []any{
"double-3", "double-4",
"double-2", "double-3",
"double-big", "double-whole",
"int32", "int32-1", "int32-2", "int32-3", "int32-max", "int32-min",
"int64", "int64-1", "int64-2", "int64-3", "int64-big",
Expand Down
Loading
Loading