-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests cases for the partial application
- Loading branch information
1 parent
63e4176
commit bb1bbd5
Showing
4 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
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,16 @@ | ||
let sum = lambda(x, y) { return x + y }; | ||
let onePlus = sum(1, _); | ||
|
||
assert_equal("Supply first function arg only", onePlus(3), 4); | ||
assert_equal("Supply second function arg only", sum(_, 3)(7), 10); | ||
|
||
class HasMinus { | ||
def minus(x, y) { | ||
return x - y; | ||
} | ||
} | ||
|
||
let tenMinus = HasMinus().minus(10, _); | ||
|
||
assert_equal("Supply first method arg only", tenMinus(6), 4); | ||
assert_equal("Supply second method arg only", HasMinus().minus(_, 4)(15), 11); |
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
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
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 |
---|---|---|
@@ -1,9 +1,23 @@ | ||
def test_partial_application() { | ||
def test_function_partial_application() { | ||
let sum = lambda(x, y) { return x + y }; | ||
let onePlus = sum(1, _); | ||
|
||
assert_equal("Supply first param only", onePlus(3), 4); | ||
assert_equal("Supply second param only", sum(_, 3)(7), 10); | ||
assert_equal("Supply first function arg only", onePlus(3), 4); | ||
assert_equal("Supply second function arg only", sum(_, 3)(7), 10); | ||
} | ||
|
||
test_partial_application(); | ||
def test_method_partial_application() { | ||
class HasMinus { | ||
def minus(x, y) { | ||
return x - y; | ||
} | ||
} | ||
|
||
let tenMinus = HasMinus().minus(10, _); | ||
|
||
assert_equal("Supply first method arg only", tenMinus(6), 4); | ||
assert_equal("Supply second method arg only", HasMinus().minus(_, 4)(15), 11); | ||
} | ||
|
||
test_function_partial_application(); | ||
test_method_partial_application(); |