alteryx / alteryx/AlteryxPrescriptive

Write a testFactory function.

Aperta
#1 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
testing
Lingua principale
R
Stelle
3
Fork
5
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

``` r
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)
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.