mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Adds test cases.
This commit is contained in:
@@ -242,3 +242,52 @@ from types import MappingProxyType
|
||||
|
||||
def mpt_arg(d=MappingProxyType({})):
|
||||
return 1 in d
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#### TruncatedDivision.ql
|
||||
|
||||
# NOTE: The following test case will only work under Python 2.
|
||||
|
||||
# Truncated division occurs when two integers are divided. This causes the
|
||||
# fractional part, if there is one, to be discared. So for example, `2 / 3` will
|
||||
# evaluate to `0` instead of `0.666...`.
|
||||
|
||||
def truncated_division():
|
||||
|
||||
def average(l):
|
||||
return sum(l) / len(l)
|
||||
|
||||
|
||||
|
||||
## Negative Cases
|
||||
|
||||
# This case is good, and is a minimal obvious case that should be good. It
|
||||
# SHOULD NOT be found by the query.
|
||||
print(3.0 / 2.0)
|
||||
|
||||
# This case is good, because the sum is `3.0`, which is a float, and will not
|
||||
# truncate. This case SHOULD NOT be found by the query.
|
||||
print(average([1.0, 2.0]))
|
||||
|
||||
|
||||
|
||||
## Positive Cases
|
||||
|
||||
# This case is bad, and is a minimal obvious case that should be bad. It
|
||||
# SHOULD be found by the query.
|
||||
print(3 / 2)
|
||||
|
||||
# This case is bad, because the sum is `3`, which is an integer, and will
|
||||
# truncate when divided by the length `2`. This case SHOULD be found by the
|
||||
# query.
|
||||
print(average([1,2]))
|
||||
|
||||
Reference in New Issue
Block a user