Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f3ea10

Browse files
committed
Move the query and examples over to 2/query-tests
1 parent 376638e commit 2f3ea10

4 files changed

Lines changed: 46 additions & 51 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#### TruncatedDivision.ql
2+
3+
# NOTE: The following test case will only work under Python 2.
4+
5+
# NOTE: While there are other files that have the same matching examples, this
6+
# example file tries to explain the motivation of each example. Hopefully it's
7+
# fine to have multiple such files.
8+
9+
# Truncated division occurs when two integers are divided. This causes the
10+
# fractional part, if there is one, to be discared. So for example, `2 / 3` will
11+
# evaluate to `0` instead of `0.666...`.
12+
13+
def truncated_division():
14+
15+
def average(l):
16+
return sum(l) / len(l)
17+
18+
19+
20+
## Negative Cases
21+
22+
# This case is good, and is a minimal obvious case that should be good. It
23+
# SHOULD NOT be found by the query.
24+
print(3.0 / 2.0)
25+
26+
# This case is good, because the sum is `3.0`, which is a float, and will not
27+
# truncate. This case SHOULD NOT be found by the query.
28+
print(average([1.0, 2.0]))
29+
30+
31+
32+
## Positive Cases
33+
34+
# This case is bad, and is a minimal obvious case that should be bad. It
35+
# SHOULD be found by the query.
36+
print(3 / 2)
37+
38+
# This case is bad, because the sum is `3`, which is an integer, and will
39+
# truncate when divided by the length `2`. This case SHOULD be found by the
40+
# query.
41+
#
42+
# NOTE (2020-02-20):
43+
# The current version of the Value/pointsTo API doesn't permit this detection,
44+
# unfortunately, but we preserve this example in the hopes that future
45+
# versions will catch it. That will necessitate changing the expected results.
46+
print(average([1,2]))

python/ql/test/query-tests/Expressions/general/TruncatedDivision.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/ql/test/query-tests/Expressions/general/TruncatedDivision.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -242,52 +242,3 @@ 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)