1 | initial version |
When working with sage, the recommended test environment is to use sage's built-in test runner. In this system you write your tests for a function into its docstring. For example, consider myfile.sage
:
def my_function(n):
r""" Regular old docstring stuff, explaining what the function does. And then...
TESTS::
sage: my_function(1)
23
sage: my_function(2)
91
"""
do stuff
return result
To run the tests, use the sage command but with the -t
option. So in this example, execute sage -t path/to/myfile.sage
. Sage will run the tests, verifying that the code my_function(1)
outputs 23
. There is a small nuance to be aware of here. It basically tries to simulate the interactive sage shell. So even though my_function(1) outputs the number 23, the string 23 is what is outputted to the interactive sage shell for printing. Whatever string representation would appear in the interactive sage shell is checked against what you type.
If one of your tests fail, this environment will tell you the output that your code generated so that you can compare it to the output you expected, the OP requested.
2 | No.2 Revision |
When working with sage, the recommended test environment is to use sage's built-in test runner. In this system you write your tests for a function into its docstring. For example, consider myfile.sage
:
def my_function(n):
r""" Regular old docstring stuff, explaining what the function does. And then...
TESTS::
sage: my_function(1)
23
sage: my_function(2)
91
"""
do stuff
return result
To run the tests, use the sage command but with the -t
option. So in this example, execute sage -t path/to/myfile.sage
. Sage will run the tests, verifying that the code my_function(1)
outputs 23
. There is a small nuance to be aware of here. It basically tries to simulate the interactive sage shell. So even though my_function(1) outputs the number 23, the string 23 is what is outputted to the interactive sage shell for printing. Whatever string representation would appear in the interactive sage shell is checked against what you type.
If one of your tests fail, this environment will tell you the output that your code generated so that you can compare it to the output you expected, the OP requested.expected!