Skip to content

Commit a644191

Browse files
committed
Added and edited examples
1 parent 3de9e4c commit a644191

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

squirrel/debug_keywords.nut

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# __LINE__ is an integer that is the line where that keyword is on.
2+
print("Print happened at line " + __LINE__ + "\n")
3+
print("Print happened at line " + __LINE__ + "\n")
4+
print("Print happened at line " + __LINE__ + "\n")
5+
6+
# __FILE__ is the name of the file the code is running on.
7+
print("Name of the file is " + __FILE__ + "\n")

squirrel/sum_of_even_squares.nut

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
function assert(success)
1+
function assert(success, line)
22
{
3-
if (!success) throw "Assertion test failed"
3+
if (!success) throw "Assertion test failed at line " + line
44
}
55

66
function sumOfEvenSquares(a)
77
{
88
return a.filter(@(_, a) a % 2 == 0).map(@(a) a * a).reduce(@(a, b) a + b) || 0
99
}
1010

11-
assert(sumOfEvenSquares([]) == 0)
12-
assert(sumOfEvenSquares([1]) == 0)
13-
assert(sumOfEvenSquares([1,2]) == 4)
14-
assert(sumOfEvenSquares([1,2,3]) == 4)
15-
assert(sumOfEvenSquares([1,2,3,4]) == 20)
16-
assert(sumOfEvenSquares([4,6,7,2]) == 56)
11+
assert(sumOfEvenSquares([]) == 0, __LINE__)
12+
assert(sumOfEvenSquares([1]) == 0, __LINE__)
13+
assert(sumOfEvenSquares([1,2]) == 4, __LINE__)
14+
assert(sumOfEvenSquares([1,2,3]) == 4, __LINE__)
15+
assert(sumOfEvenSquares([1,2,3,4]) == 20, __LINE__)
16+
assert(sumOfEvenSquares([4,6,7,2]) == 56, __LINE__)

squirrel/test.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sq "$PSScriptRoot\clockhands_time.nut" |
1818
sq "$PSScriptRoot\clockhands.nut" |
1919
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
2020
Assert-MatchTests &&
21+
sq "$PSScriptRoot\debug_keywords.nut" &&
2122
sq "$PSScriptRoot\floating_point_mystery.nut" &&
2223
sq "$PSScriptRoot\hello.nut" &&
2324
"I like carrots" | sq "$PSScriptRoot\permutations.nut" |

0 commit comments

Comments
 (0)