-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from flightaware/inoffensive-tests-bugfixes
Add some inoffensive tests and a bugfix
- Loading branch information
Showing
8 changed files
with
119 additions
and
14 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
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,32 @@ | ||
import unittest | ||
|
||
import tohil | ||
|
||
class TestRecursion(unittest.TestCase): | ||
def test_with_callback(self): | ||
# Can't do this without a callback due to how unittest imports the tests. | ||
# Results in the global environment of this module not being visible from within Tcl. | ||
tohil.eval(""" | ||
package require tohil | ||
proc isodd {num} { | ||
return [expr {![iseven $num]}] | ||
} | ||
""") | ||
def iseven(num): | ||
num = int(num) | ||
if num == 1: | ||
return False | ||
elif num == 0: | ||
return True | ||
else: | ||
return not tohil.call("isodd", num - 2, to=bool) | ||
tohil.register_callback("iseven", iseven) | ||
self.assertTrue(iseven(0)) | ||
self.assertTrue(iseven(2)) | ||
self.assertTrue(iseven(4)) | ||
self.assertTrue(iseven(6)) | ||
self.assertTrue(iseven(200)) | ||
|
||
self.assertFalse(iseven(1)) | ||
self.assertFalse(iseven(3)) | ||
self.assertFalse(iseven(99)) |
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
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