# TestUtils

`Models.TestUtils`

— Module`Models.TestUtils`

Provides test fakes, `FakeTemplate`

and `FakeModel`

, that are useful for testing downstream dependencies, and `test_interface`

for testing the Models API has been correctly implemented.

## Interface Tests

`Models.TestUtils.test_interface`

— Function`test_interface(template::Template; inputs=rand(5, 5), outputs=rand(5, 5))`

Test that subtypes of `Template`

and `Model`

implement the expected API. Can be used as an initial test to verify the API has been correctly implemented.

### Note on PredictInputTrait Interface Tests

In the case where the `PredictInputTrait`

is `PointOrDistributionPredictInput`

the the Models API requires only that the distribution in question is `Sampleable`

. When using `Models.TestUtils.test_interface`

to test a model where distributions can be passed to `predict`

, the user should provide `inputs`

of the distribution type appropriate to their model. In the example below the `CustomModel`

accepts `MvNormal`

distributions to `predict`

.

```
using CustomModels
using Distributions
using Models.TestUtils
test_interface(
CustomModelTemplate();
distribution_inputs=[MvNormal(5, 1) for _ in 1:5],
)
```

## Test Fakes

`Models.TestUtils.FakeModel`

— Type`FakeModel`

A fake Model for testing purposes. See `FakeTemplate`

for details.

`Models.TestUtils.FakeTemplate`

— Type`FakeTemplate{E <: EstimateTrait, O <: OutputTrait} <: Template`

This template is a test double for testing purposes. It should be defined (before fitting) with a `predictor`

, which can be changed by mutating the field.

**Fields**

`predictor::Function`

: predicts the outputs of the`FakeModel`

. It is`(num_variates, inputs) -> outputs`

, where the`num_variates`

will be memorized during`fit`

.

**Methods**

`Models.TestUtils.FakeTemplate`

— Method`FakeTemplate{DistributionEstimate, MultiOutput}()`

A `Template`

whose `Model`

will accept real value variables to predict a multivariate normal distribution (with zero-vector mean and identity covariance matrix) for each observation.

`Models.TestUtils.FakeTemplate`

— Method`FakeTemplate{PointEstimate, MultiOutput}()`

A `Template`

whose `Model`

will accept real value variables to predict a vector of 0s for each observation. The input and output will have the same dimension.

`Models.TestUtils.FakeTemplate`

— Method`FakeTemplate{DistributionEstimate, SingleOutput}()`

A `Template`

whose `Model`

will accept real value variables to predict a univariate normal distribution (with zero mean and unit standard deviation) for each observation.

`Models.TestUtils.FakeTemplate`

— Method`FakeTemplate{PointEstimate, SingleOutput}()`

A `Template`

whose `Model`

will accept real value variables to predict 0 for each observation.