Metadata-Version: 2.4
Name: checkcases
Version: 0.1.0
Summary: Check a Python function against example inputs with clear pass/fail output. Handy for practice exercises.
Author: PyChallenge
License-Expression: MIT
Project-URL: Homepage, https://pychallenge.com
Project-URL: Practice challenges, https://pychallenge.com
Keywords: testing,exercises,practice,learning,education,examples
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Education
Classifier: Topic :: Education
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# checkcases

Check a Python function against a few example inputs and see clearly what passes and what fails.

It's made for practice: you write a function, list some inputs with the answers you expect, and run `check`. No test framework, no setup, no dependencies.

```bash
pip install checkcases
```

## Example

```python
from checkcases import check, raises

def fizzbuzz(n):
    if n % 15 == 0:
        return "FizzBuzz"
    if n % 3 == 0:
        return "Fizz"
    if n % 5 == 0:
        return "Buzz"
    return str(n)

check(fizzbuzz, [
    (3, "Fizz"),
    (5, "Buzz"),
    (15, "FizzBuzz"),
    (7, "7"),
])
```

```
PASS fizzbuzz(3) == 'Fizz'
PASS fizzbuzz(5) == 'Buzz'
PASS fizzbuzz(15) == 'FizzBuzz'
PASS fizzbuzz(7) == '7'
------------------------------
4/4 passed
```

When something is wrong, you see the call, what came back and what you expected:

```
FAIL add(1, 2) returned 4, expected 3
```

## Writing cases

| Case | Means |
|---|---|
| `(5, 25)` | `f(5)` should return `25` |
| `((2, 3), 5)` | `f(2, 3)` should return `5` |
| `{"args": (2,), "kwargs": {"b": 3}, "expected": 5}` | `f(2, b=3)` should return `5` |
| `((1, 0), raises(ZeroDivisionError))` | `f(1, 0)` should raise `ZeroDivisionError` |

Floats are compared with a small tolerance, so `0.1 + 0.2` counts as `0.3`. Change it with `check(f, cases, tol=1e-6)`.

## Using the result

`check` returns a result you can use in scripts:

```python
result = check(add, cases, verbose=False)
if not result:
    print(result.failures)
```

`result.passed`, `result.failed` and `result.failures` hold the details, and the result is truthy when everything passed.

## Looking for something to practice on?

[PyChallenge](https://pychallenge.com) has Python challenges to work through in your browser, from beginner to more advanced.

## License

MIT
