Skip to content

Commit 1154954

Browse files
committed
Adds test cases.
1 parent 96b8d78 commit 1154954

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

python/ql/test/query-tests/Expressions/general/expressions_test.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,52 @@ def func():
242242

243243
def mpt_arg(d=MappingProxyType({})):
244244
return 1 in d
245+
246+
247+
248+
249+
250+
251+
252+
253+
254+
255+
256+
257+
#### TruncatedDivision.ql
258+
259+
# NOTE: The following test case will only work under Python 2.
260+
261+
# Truncated division occurs when two integers are divided. This causes the
262+
# fractional part, if there is one, to be discared. So for example, `2 / 3` will
263+
# evaluate to `0` instead of `0.666...`.
264+
265+
def truncated_division():
266+
267+
def average(l):
268+
return sum(l) / len(l)
269+
270+
271+
272+
## Negative Cases
273+
274+
# This case is good, and is a minimal obvious case that should be good. It
275+
# SHOULD NOT be found by the query.
276+
print(3.0 / 2.0)
277+
278+
# This case is good, because the sum is `3.0`, which is a float, and will not
279+
# truncate. This case SHOULD NOT be found by the query.
280+
print(average([1.0, 2.0]))
281+
282+
283+
284+
## Positive Cases
285+
286+
# This case is bad, and is a minimal obvious case that should be bad. It
287+
# SHOULD be found by the query.
288+
print(3 / 2)
289+
290+
# This case is bad, because the sum is `3`, which is an integer, and will
291+
# truncate when divided by the length `2`. This case SHOULD be found by the
292+
# query.
293+
print(average([1,2]))

0 commit comments

Comments
 (0)