-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace StackBusters with TCO assertions (mbittarelli FTW)
- Loading branch information
Showing
9 changed files
with
64 additions
and
187 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
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,28 @@ | ||
module TCOMethod | ||
module TestHelpers | ||
module Assertions | ||
def assert_tail_call_optimized(method, *args) | ||
is_tco = tail_call_optimized(method, *args) | ||
msg = "Expected method #{method.name} to be tail call optimized" | ||
assert is_tco, msg | ||
end | ||
|
||
def refute_tail_call_optimized(method, *args) | ||
is_tco = tail_call_optimized(method, *args) | ||
msg = "Expected method #{method.name} not to be tail call optimized" | ||
refute is_tco, msg | ||
end | ||
|
||
def tail_call_optimized?(method, *args) | ||
initial_length = nil | ||
method.call(*args) do | ||
if initial_length.nil? | ||
initial_length = caller.length | ||
else | ||
break initial_length == caller.length | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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