-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: expand testing of augmented assignment operators (#70)
Add some more tests for augmented assignment operators, and remove some existing ones that had similar coverage. assignops.c4m was similar to basic10.c4m: """ Basic test of augmented assignment. """ """ $output: 45 """ x = 0 for i in 0 to 10 { x += i } print(x) The grammar specifies the augmented assignment operators here: assign ::= expression assignmentOp expression EOS assignmentOp ::= ':' | '=' | '+=' | '-=' | '*=' | '/=' | '|=' | '&=' | '^=' | '>>=' | '<<=' Note that commit b4fdc8e (2024-07-03, "Reworking of lists, etc") changed the behavior of the /= operator so that: - For division by zero, SIGFPE is no longer produced. - For division by a negative number, the result is now correct. Refs: #55 Refs: #57 Refs: #71
- Loading branch information
Showing
9 changed files
with
234 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Basic test of every augmented assignment operator. | ||
""" | ||
""" | ||
$output: | ||
3 | ||
-2 | ||
-12 | ||
6 | ||
7 | ||
5 | ||
13 | ||
3 | ||
6 | ||
""" | ||
|
||
x = 2 | ||
|
||
x += 1 | ||
print(x) | ||
|
||
x -= 5 | ||
print(x) | ||
|
||
x *= 6 | ||
print(x) | ||
|
||
x /= -2 | ||
print(x) | ||
|
||
x |= 7 | ||
print(x) | ||
|
||
x &= 13 | ||
print(x) | ||
|
||
x ^= 8 | ||
print(x) | ||
|
||
x >>= 2 | ||
print(x) | ||
|
||
x <<= 1 | ||
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Basic test of augmented assignment operator: /= | ||
""" | ||
""" | ||
$output: | ||
12 | ||
6 | ||
-6 | ||
-3 | ||
3 | ||
""" | ||
|
||
x = 12 | ||
|
||
x /= 1 | ||
print(x) | ||
|
||
x /= 2 | ||
print(x) | ||
|
||
x /= -1 | ||
print(x) | ||
|
||
x /= 2 | ||
print(x) | ||
|
||
x /= -1 | ||
print(x) | ||
|
||
# TODO: remove this later. See basic25.c4m. | ||
x /= 0 | ||
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Basic test of augmented assignment operator: *= | ||
""" | ||
""" | ||
$output: | ||
3 | ||
6 | ||
-6 | ||
-12 | ||
24 | ||
0 | ||
""" | ||
|
||
x = 3 | ||
|
||
x *= 1 | ||
print(x) | ||
|
||
x *= 2 | ||
print(x) | ||
|
||
x *= -1 | ||
print(x) | ||
|
||
x *= 2 | ||
print(x) | ||
|
||
x *= -2 | ||
print(x) | ||
|
||
x *= 0 | ||
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Basic test of augmented assignment operator: <<= | ||
""" | ||
""" | ||
$output: | ||
0 | ||
0 | ||
1 | ||
2 | ||
8 | ||
4611686018427387904 | ||
-1 | ||
-2 | ||
-2305843009213693952 | ||
-4611686018427387904 | ||
""" | ||
|
||
x = 0 | ||
|
||
x <<= 0 | ||
print(x) | ||
|
||
x <<= 1 | ||
print(x) | ||
|
||
x = 1 | ||
|
||
x <<= 0 | ||
print(x) | ||
|
||
x <<= 1 | ||
print(x) | ||
|
||
x <<= 2 | ||
print(x) | ||
|
||
x <<= 59 | ||
print(x) | ||
|
||
x = -1 | ||
|
||
x <<= 0 | ||
print(x) | ||
|
||
x <<= 1 | ||
print(x) | ||
|
||
x <<= 60 | ||
print(x) | ||
|
||
x <<= 1 | ||
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Basic test of augmented assignment operator: >>= | ||
""" | ||
""" | ||
$output: | ||
9223372036854775807 | ||
9223372036854775807 | ||
4611686018427387903 | ||
15 | ||
7 | ||
1 | ||
0 | ||
0 | ||
0 | ||
""" | ||
|
||
x = 0x7fffffffffffffff | ||
print(x) | ||
|
||
x >>= 0 | ||
print(x) | ||
|
||
x >>= 1 | ||
print(x) | ||
|
||
x >>= 58 | ||
print(x) | ||
|
||
x >>= 1 | ||
print(x) | ||
|
||
x >>= 2 | ||
print(x) | ||
|
||
x >>= 1 | ||
print(x) | ||
|
||
x >>= 0 | ||
print(x) | ||
|
||
x >>= 1 | ||
print(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Basic test of augmented assignment operator: ^= | ||
""" | ||
""" | ||
$output: | ||
2 | ||
0 | ||
-2 | ||
-4 | ||
-4 | ||
3 | ||
""" | ||
|
||
x = 3 | ||
|
||
x ^= 1 | ||
print(x) | ||
|
||
x ^= 2 | ||
print(x) | ||
|
||
x ^= -2 | ||
print(x) | ||
|
||
x ^= 2 | ||
print(x) | ||
|
||
x ^= 0 | ||
print(x) | ||
|
||
x ^= -1 | ||
print(x) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.