# aego/testing

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

Test functions are package functions named `TestXxx` in `*_test.aes` files, and `aego test` runs them headless. The documentation sandbox does not run `aego test`, so the example calls its test function from `Ready`; in a project, move `TestDamage` into a `_test.aes` file and drop the script.

## Example

```aes run
package demo

import (
    "aego/log"
    "aego/math"
    "aego/testing"
)

func damage(hp int, hit int) int {
    return math.MaxInt(hp - hit, 0)
}

func label(hp int) string {
    if hp == 0 {
        return "dead"
    }
    return "alive"
}

func TestDamage() {
    testing.Equal(damage(10, 3), 7)
    testing.Equal(damage(2, 5), 0)
    testing.EqualString(label(damage(2, 5)), "dead")
    testing.EqualFloat(math.Sqrt(2), 1.4142, 0.001)
    testing.True(damage(10, 0) == 10, "a zero hit changes nothing")
    testing.False(damage(1, 1) > 0, "the last hit kills")
}

script Runner {
    func Ready() {
        TestDamage()
        log.Info("TestDamage passed")
    }
}
```

## Equal

```
func Equal(got int, want int)
```

Fails the test when two ints differ.

## EqualFloat

```
func EqualFloat(got float, want float, eps float)
```

Fails the test when got is further than eps from want, or is NaN.

## EqualString

```
func EqualString(got string, want string)
```

Fails the test when two strings differ.

## Fail

```
func Fail(msg string)
```

Stops the test and reports msg.

## False

```
func False(v bool, msg string)
```

Fails the test with msg when v is true.

## True

```
func True(v bool, msg string)
```

Fails the test with msg when v is false.
