Skip to content

Commit

Permalink
Additional tests for edge cases related to cross-type numeric compari…
Browse files Browse the repository at this point in the history
…sons (google#231)
  • Loading branch information
TristonianJones authored Mar 18, 2022
1 parent c7eddf5 commit d917b9f
Showing 1 changed file with 254 additions and 0 deletions.
254 changes: 254 additions & 0 deletions tests/simple/testdata/comparisons.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,72 @@ section {
expr: "dyn(1.0) < 1u"
value: { bool_value: false }
}
test {
name: "lt_dyn_int_big_uint"
expr: "dyn(1) < 9223372036854775808u"
value: { bool_value: true }
}
test {
name: "lt_dyn_small_int_uint"
expr: "dyn(-1) < 0u"
value: { bool_value: true }
}
test {
name: "not_lt_dyn_int_big_lossy_double"
expr: "dyn(9223372036854775807) < 9223372036854775808.0"
value: { bool_value: false }
}
test {
name: "lt_dyn_int_big_lossy_double"
expr: "dyn(9223372036854775807) < 9223372036854777857.0"
value: { bool_value: true }
}
test {
name: "not_lt_dyn_int_small_double"
expr: "dyn(9223372036854775807) < -9223372036854777857.0"
value: { bool_value: false }
}
test {
name: "not_lt_dyn_int_small_lossy_double"
expr: "dyn(-9223372036854775808) < -9223372036854775809.0"
value: { bool_value: false }
}
test {
name: "not_lt_dyn_uint_small_int"
expr: "dyn(1u) < -9223372036854775808"
value: { bool_value: false }
}
test {
name: "not_lt_dyn_big_uint_int"
expr: "dyn(9223372036854775808u) < 1"
value: { bool_value: false }
}
test {
name: "not_lt_dyn_uint_small_double"
expr: "dyn(18446744073709551615u) < -1.0"
value: { bool_value: false }
}
test {
name: "lt_dyn_uint_big_double"
expr: "dyn(18446744073709551615u) < 18446744073709590000.0"
value: { bool_value: true }
}
test {
name: "not_lt_dyn_big_double_uint"
expr: "dyn(18446744073709553665.0) < 18446744073709551615u"
value: { bool_value: false }
}
test {
name: "not_lt_dyn_big_double_int"
expr: "dyn(9223372036854775808.0) < 9223372036854775807"
value: { bool_value: false }
}
test {
name: "not_lt_dyn_small_double_int"
expr: "dyn(-9223372036854775809.0) < -9223372036854775808"
value: { bool_value: false }
}

}
section {
name: "gt_literal"
Expand Down Expand Up @@ -1471,6 +1537,67 @@ section {
expr: "dyn(1.0) > 1u"
value: { bool_value: false }
}
test {
name: "not_gt_dyn_int_big_uint"
expr: "dyn(1) > 9223372036854775808u"
value: { bool_value: false }
}
test {
name: "not_gt_dyn_small_int_uint"
expr: "dyn(-1) > 0u"
value: { bool_value: false }
}
test {
name: "not_gt_dyn_int_big_double"
expr: "dyn(9223372036854775807) > 9223372036854775808.0"
value: { bool_value: false }
}
test {
name: "not_gt_dyn_int_small_lossy_double"
description: "The conversion of the int to double is lossy and the numbers end up being equal"
expr: "dyn(-9223372036854775808) > -9223372036854775809.0"
value: { bool_value: false }
}
test {
name: "gt_dyn_int_small_lossy_double_greater"
expr: "dyn(-9223372036854775808) > -9223372036854777857.0"
value: { bool_value: true }
}
test {
name: "gt_dyn_uint_small_int"
expr: "dyn(1u) > -1"
value: { bool_value: true }
}
test {
name: "gt_dyn_big_uint_int"
expr: "dyn(9223372036854775808u) > 1"
value: { bool_value: true }
}
test {
name: "gt_dyn_uint_small_double"
expr: "dyn(9223372036854775807u) > -1.0"
value: { bool_value: true }
}
test {
name: "not_gt_dyn_uint_big_double"
expr: "dyn(18446744073709551615u) > 18446744073709590000.0"
value: { bool_value: false }
}
test {
name: "gt_dyn_big_double_uint"
expr: "dyn(18446744073709553665.0) > 18446744073709551615u"
value: { bool_value: true }
}
test {
name: "not_gt_dyn_big_double_int"
expr: "dyn(9223372036854775808.0) > 9223372036854775807"
value: { bool_value: false }
}
test {
name: "not_gt_dyn_small_double_int"
expr: "dyn(-9223372036854775809.0) > -9223372036854775808"
value: { bool_value: false }
}
}
section {
name: "lte_literal"
Expand Down Expand Up @@ -1672,6 +1799,67 @@ section {
expr: "dyn(2.0) <= 1u"
value: { bool_value: false }
}
test {
name: "lte_dyn_int_big_uint"
expr: "dyn(1) <= 9223372036854775808u"
value: { bool_value: true }
}
test {
name: "lte_dyn_small_int_uint"
expr: "dyn(-1) <= 0u"
value: { bool_value: true }
}
test {
name: "lte_dyn_int_big_double"
expr: "dyn(9223372036854775807) <= 9223372036854775808.0"
value: { bool_value: true }
}
test {
name: "lte_dyn_int_small_lossy_double"
description: "The conversion of the int to double is lossy and the numbers end up being equal"
expr: "dyn(-9223372036854775808) <= -9223372036854775809.0"
value: { bool_value: true }
}
test {
name: "not_lte_dyn_int_small_lossy_double_less"
expr: "dyn(-9223372036854775808) <= -9223372036854777857.0"
value: { bool_value: false }
}
test {
name: "not_lte_dyn_uint_small_int"
expr: "dyn(1u) <= -9223372036854775808"
value: { bool_value: false }
}
test {
name: "not_lte_dyn_big_uint_int"
expr: "dyn(9223372036854775808u) <= 1"
value: { bool_value: false }
}
test {
name: "not_lte_dyn_uint_small_double"
expr: "dyn(18446744073709551615u) <= -1.0"
value: { bool_value: false }
}
test {
name: "lte_dyn_uint_big_double"
expr: "dyn(18446744073709551615u) <= 18446744073709590000.0"
value: { bool_value: true }
}
test {
name: "not_lte_dyn_big_double_uint"
expr: "dyn(18446744073709553665.0) <= 18446744073709551615u"
value: { bool_value: false }
}
test {
name: "lte_dyn_big_double_int"
expr: "dyn(9223372036854775808.0) <= 9223372036854775807"
value: { bool_value: true }
}
test {
name: "lte_dyn_small_double_int"
expr: "dyn(-9223372036854775809.0) <= -9223372036854775808"
value: { bool_value: true }
}
}
section {
name: "gte_literal"
Expand Down Expand Up @@ -1883,6 +2071,72 @@ section {
expr: "dyn(0.0) >= 1u"
value: { bool_value: false }
}
test {
name: "not_gte_dyn_int_big_uint"
expr: "dyn(1) >= 9223372036854775808u"
value: { bool_value: false }
}
test {
name: "not_gte_dyn_small_int_uint"
expr: "dyn(-1) >= 0u"
value: { bool_value: false }
}
test {
name: "gte_dyn_int_big_lossy_double"
expr: "dyn(9223372036854775807) >= 9223372036854775808.0"
value: { bool_value: true }
}
test {
name: "not_gte_dyn_int_big_double"
expr: "dyn(9223372036854775807) >= 9223372036854777857.0"
value: { bool_value: false }
}
test {
name: "gte_dyn_int_small_lossy_double_equal"
description: "The conversion of the int to double is lossy and the numbers end up being equal"
expr: "dyn(-9223372036854775808) >= -9223372036854775809.0"
value: { bool_value: true }
}
test {
name: "gte_dyn_int_small_lossy_double_greater"
expr: "dyn(-9223372036854775808) >= -9223372036854777857.0"
value: { bool_value: true }
}
test {
name: "gte_dyn_uint_small_int"
expr: "dyn(1u) >= -1"
value: { bool_value: true }
}
test {
name: "gte_dyn_big_uint_int"
expr: "dyn(9223372036854775808u) >= 1"
value: { bool_value: true }
}
test {
name: "gte_dyn_uint_small_double"
expr: "dyn(9223372036854775807u) >= -1.0"
value: { bool_value: true }
}
test {
name: "not_gte_dyn_uint_big_double"
expr: "dyn(18446744073709551615u) >= 18446744073709553665.0"
value: { bool_value: false }
}
test {
name: "gte_dyn_big_double_uint"
expr: "dyn(18446744073709553665.0) >= 18446744073709551615u"
value: { bool_value: true }
}
test {
name: "gte_dyn_big_double_int"
expr: "dyn(9223372036854775808.0) >= 9223372036854775807"
value: { bool_value: true }
}
test {
name: "gte_dyn_small_double_int"
expr: "dyn(-9223372036854775809.0) >= -9223372036854775808"
value: { bool_value: true }
}
}
section {
name: "in_list_literal"
Expand Down

0 comments on commit d917b9f

Please sign in to comment.