test_that("fit_mobility returns a finite deterministic fit", {
  pars <- seair_params(beta = 1.5, sigma = 0.3, kappa = 0.2,
                       gamma_A = 0.1, gamma_I = 0.13,
                       alpha = 0.5, delta = 0.3)
  m     <- seq(0, 1, length.out = 21)
  ftrue <- stats::dbeta(m, 3, 3)
  init  <- seair_init(m, ftrue, I_seed = 1e-4)
  times <- seq(0, 20, by = 5)
  sol   <- seair_solve(init, pars, times = times)
  I_obs <- seair_aggregate(sol)$I

  fit <- fit_mobility(times, I_obs, pars,
                      K = 1, m_grid = m,
                      start = log(c(3, 3)),
                      n_restarts = 0,
                      control = list(maxit = 20))

  expect_true(is.finite(fit$loss))
  expect_lt(fit$loss, 1e-10)
  expect_length(fit$f_hat, length(m))
})
