Files
metabuilder/mojo/examples/testing/README.md
johndoe6345789 d772201bf1 feat: Replace placeholder examples with official Modular Mojo examples
Added official examples from github.com/modular/modular:
- gpu-intro, gpu-functions, gpu-block-and-warp (GPU programming)
- layout_tensor, layouts (tensor operations)
- life (Conway's Game of Life)
- operators (custom operators)
- process (subprocess handling)
- python-interop (Python integration)
- testing (unit test patterns)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 17:40:19 +00:00

55 lines
1.4 KiB
Markdown

# Modular testing framework examples
This directory contains examples of using the Mojo testing framework for unit
testing. See the [Testing](https://docs.modular.com/mojo/tools/testing) section
of the [Mojo manual](https://docs.modular.com/mojo/manual/) for a complete
discussion of how to use the Mojo testing framework.
## Files
This directory contains the following files:
- `src/my_math/__init__.mojo`: a Mojo package file
- `src/my_math/utils.mojo`: a Mojo module source file
- `src/example.mojo`: a simple Mojo program that uses the functions from the
`my_math` package
- `test/my_math/test_*.mojo`: Mojo test files containing unit tests for
functions defined in the `my_math` package
- `pixi.toml`: a [Pixi](https://pixi.sh) project file
containing the project dependencies and task definitions.
## Run the code
This example project uses the [Pixi](https://pixi.sh/latest/) package
and virtual environment manager.
Once you have installed `pixi`, activate the project's virtual environment by
navigating to the project's root directory and executing:
```bash
pixi shell
```
Run the unit tests contained in the `test` directory by executing:
```bash
mojo run test/my_math/test_dec.mojo
mojo run test/my_math/test_inc.mojo
```
If desired, you can run the example program by executing:
```bash
mojo src/example.mojo
```
Once you're done, deactivate the project's virtual environment by executing:
```bash
exit
```