Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative simple syntax for unit_test to be used as a with context #115

Open
acbart opened this issue Mar 15, 2024 · 0 comments
Open

Alternative simple syntax for unit_test to be used as a with context #115

acbart opened this issue Mar 15, 2024 · 0 comments
Labels
Assertions Tool Issues pertaining to the Assertions tool (declarative statements about student code)

Comments

@acbart
Copy link
Collaborator

acbart commented Mar 15, 2024

Writing up the SIGCSE slides, I realized that unit_test is a bit ugly in its current form. It's also a lot less flexible than it could be.

unit_test('cube_elements',
            ([[1, 2, 3]], [1, 8, 27]),
            ([[1]], [1]),
            ([[4, 4, 4]], [64, 64, 64]),
            ([[0]], [0]),
            ([[]], []))

I've dealt with it for years on my own, but for other people, I think the following syntax would be nice:

with unit_test('cube_elements'):
    assert_equal(cube_elements([1, 2, 3]), [1, 8, 27])
    assert_equal(cube_elements([1]), [1])
    assert_equal(cube_elements([4, 4, 4]), [64, 64, 64])
    assert_equal(cube_elements([0]), [0])
    assert_equal(cube_elements([]), [])

I've got the basics of the context version down; if you call unit_test without any tests, then it just returns the with context manager object. The only part that needs additional work is handling the each_score[test_index] logic.

@acbart acbart added the Assertions Tool Issues pertaining to the Assertions tool (declarative statements about student code) label Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Assertions Tool Issues pertaining to the Assertions tool (declarative statements about student code)
Projects
None yet
Development

No branches or pull requests

1 participant