alteryx / AlteryxPrescriptive

R Package for Optimization in Alteryx
GNU General Public License v3.0
3 stars 6 forks source link

Write a testFactory function. #1

Open ramnathv opened 8 years ago

ramnathv commented 8 years ago

The test code can be refactored considerably by refactoring common elements into a testFactory function. Here is a crude example.

config <- list(inputMode = 'file', problemType = 'lp')
payload <- list(config = config, inputs = NULL)

createTestGrid <- function(filePaths, solvers){
  expand.grid(filePath = filePaths, solver = solvers)
}

testGrid <- createTestGrid(
  filePaths = c("file1.lp", "file2.lp"),
  solvers = c("glpk", "gurobi")
)

expectedSolutions = list(`file1.lp` = 10, `file2.lp` = 20)

testFactory <- function(filePath, solver){
  test_that(paste("Testing ", solver, "on", filePath), {
     payload$config$solver = solver
     payload$config$filePath = filePath
     sol = AlteryxSolve(payload)
     expect_equal(sol$objval, expectedSolutions[[filePath]])
  })
}

mapply(testFactory, filePath = testGrid$filePath, solvers = testGrid$solver)
ramnathv commented 8 years ago

@kuol here is the idea that i discussed with you during our call. This should allow us to add a lot more tests by just tweaking the list of filenames and solvers. The same idea can be extended to the other modes.

kuol commented 8 years ago

Very cool, thanks Ramnath!

-Kuo

On Thu, Mar 17, 2016 at 5:28 PM, Ramnath Vaidyanathan < notifications@github.com> wrote:

@kuol https://github.com/kuol here is the idea that i discussed with you during our call. This should allow us to add a lot more tests by just tweaking the list of filenames and solvers. The same idea can be extended to the other modes.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/ramnathv/AlteryxPrescriptive/issues/1#issuecomment-198129632