Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
virgesmith committed Feb 8, 2021
1 parent 7f128af commit 3304c50
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/DataFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ void no::df::transition(no::Model& model, py::array_t<int64_t> categories, py::a

// check matrix is 2d, square & categories len = matrix len
if (matrix.ndim() != 2)
throw py::type_error("cumulative transition matrix dimension is %%"s % matrix.ndim());
throw py::value_error("cumulative transition matrix dimension is %%"s % matrix.ndim());
if (matrix.shape(0) != matrix.shape(1))
throw py::type_error("cumulative transition matrix shape is not square: %% by %%"s % matrix.shape(0) % matrix.shape(1));
throw py::value_error("cumulative transition matrix shape is not square: %% by %%"s % matrix.shape(0) % matrix.shape(1));
if (m != matrix.shape(0))
throw py::value_error("cumulative transition matrix size (%%) is not same as length of categories (%%)"s % matrix.shape(0) % m);

Expand Down
8 changes: 7 additions & 1 deletion test/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ def test_errors():
# identity matrix means no transitions
trans = np.identity(len(cats))

# category data MUST be 64bit integer. This will alomst certainly be the default on linux/OSX but not on windows
# invalid transition matrices
assert_throws(ValueError, no.df.transition, model, cats, np.ones((1,2)), df, "DC2101EW_C_ETHPUK11")
assert_throws(ValueError, no.df.transition, model, cats, np.ones((1,1)), df, "DC2101EW_C_ETHPUK11")
assert_throws(ValueError, no.df.transition, model, cats, trans+0.1, df, "DC2101EW_C_ETHPUK11")

# category data MUST be 64bit integer. This will almost certainly be the default on linux/OSX (LP64) but maybe not on windows (LLP64)
df["DC2101EW_C_ETHPUK11"]= df["DC2101EW_C_ETHPUK11"].astype(np.int32)

assert_throws(TypeError, no.df.transition, model, cats, trans, df, "DC2101EW_C_ETHPUK11")


def test_basic():

# test unique index generation
Expand Down
16 changes: 16 additions & 0 deletions test/test_mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def _test_mc_serial(model):
mc = model.mc()
assert mc.seed() == 19937

mc.reset()
assert mc.raw() == 6231104047474287856
assert mc.raw() == 14999272868227999252
mc.reset()
assert mc.raw() == 6231104047474287856
assert mc.raw() == 14999272868227999252

mc.reset()
s = mc.state()
a = mc.ustream(5)
Expand Down Expand Up @@ -224,6 +231,15 @@ def _test_mc_serial(model):
assert a[4] == 6.461894711350323
assert a[5] == 2.8566436418145944

mc.reset()
a = mc.arrivals([1.0, 2.0, 3.0, 0.0], 1.0, 1, 0.0)
assert np.allclose(a[0], [0.361778116731657, 0.430740169244778, 1.580095480774, 2.226284951909032, 2.511949316090492, 2.809348320658414, 2.929632529913839])
mc.reset()
# now with a mim separation of 1.0
a = mc.arrivals([1.0, 2.0, 3.0, 0.0], 1.0, 1, 1.0)
assert np.allclose(a[0], [0.361778116731657, 1.430740169244778])
mc.reset()

# Exp.value = p +/- 1/sqrt(N)
h = model.mc().hazard(0.2, 10000)
assert isinstance(h, np.ndarray)
Expand Down
9 changes: 8 additions & 1 deletion test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
import numpy as np
import neworder as no

#no.verbose()
from utils import assert_throws

no.verbose()

def test_base():
base = no.Model(no.NoTimeline(), no.MonteCarlo.deterministic_identical_stream)

assert_throws(NotImplementedError, no.run, base)

def test_multimodel():
pass
Expand Down

0 comments on commit 3304c50

Please sign in to comment.