tests/testthat/test-ROI.R

context("ROI")

suppressMessages(library('testthat'))
suppressMessages(library('dplyr'))
suppressMessages(library('magrittr'))
suppressMessages(library('purrr'))
suppressMessages(library('stringr'))
suppressMessages(library('tibble'))
suppressMessages(library('tidyr'))
suppressMessages(library('ROI.plugin.ecos'))
suppressMessages(library('fbar'))

test_that('toy model 1', {

  expanded <- reactiontbl_to_expanded(dplyr::tibble(
    abbreviation = c('one', 'two'),
    equation = c('alpha -> beta', 'gamma -> delta'),
    lowbnd = c(-1,-1),
    uppbnd = c(3,3),
    obj_coef = c(1,0)))
  
  model <- expanded_to_ROI(expanded)
  
  expect_gte(length(ROI::ROI_applicable_solvers(model)),1)
  
  result <- ROI::ROI_solve(model)
  
  expect_equal(result$status$code, 0)
  expect_equal(result$objval, 0)
})

test_that('toy model 2', {

  expanded <- reactiontbl_to_expanded(dplyr::tibble(
    abbreviation = c('one', 'two'),
    equation = c('alpha -> ', ' <-> alpha'),
    lowbnd = c(-1,-1),
    uppbnd = c(3,3),
    obj_coef = c(1,0)))
  
  model <- expanded_to_ROI(expanded)
  
  expect_gte(length(ROI::ROI_applicable_solvers(model)),1)
  
  result <- ROI::ROI_solve(model)
  
  expect_equal(result$status$code, 0)
  expect_equal(result$objval, 3)
})

Try the fbar package in your browser

Any scripts or data that you put into this service are public.

fbar documentation built on Sept. 2, 2020, 5:08 p.m.