Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbossek committed Feb 17, 2015
1 parent 0f44868 commit f855571
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
3 changes: 2 additions & 1 deletion tests/testthat/test_ecr.R
Expand Up @@ -24,7 +24,8 @@ test_that("ecr works with simple soo function", {
max.iter = max.iter,
n.params = 2L,
representation = "float",
monitor = makeNullMonitor()
monitor = makeNullMonitor(),
stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = max.iter))
)
}

Expand Down
47 changes: 20 additions & 27 deletions tests/testthat/test_stoppingConditions.R
@@ -1,6 +1,6 @@
context("termination codes")

test_that("termination codes do work", {
test_that("stopping conditions work", {
obj.fn = makeSingleObjectiveFunction(
name = "1D Sphere",
fn = function(x) sum(x^2),
Expand All @@ -11,31 +11,24 @@ test_that("termination codes do work", {
global.opt.value = 0
)

makeControlForTestCase = function(max.iter = 100000L, max.time = 3600L, termination.eps = 0) {
ecr.control(
population.size = 20L,
offspring.size = 20L,
n.params = 1L,
survival.strategy = "plus",
elite.size = 1L,
representation = "float",
max.iter = max.iter,
max.time = max.time,
termination.eps = termination.eps,
monitor = makeNullMonitor()
)
}

# check for max iterations
control = makeControlForTestCase(max.iter = 5L)
expect_equal(ecr(obj.fn, control)$convergence, 0L)

# check for reached tolerence level
set.seed(1)
control = makeControlForTestCase(termination.eps = 2)
expect_equal(ecr(obj.fn, control)$convergence, 1L)
control = ecr.control(
population.size = 2L,
offspring.size = 2L,
n.params = 1L,
survival.strategy = "plus",
elite.size = 1L,
representation = "float",
max.iter = 100L,
max.time = 100,
termination.eps = 0.003,
monitor = makeNullMonitor()
)

# check for max time budget
control = makeControlForTestCase(max.time = 2L)
expect_equal(ecr(obj.fn, control)$convergence, 2L)
})
control$stoppingConditions = list(makeMaximumTimeStoppingCondition(max.time = 2))
expect_true(grepl("Time limit", ecr(obj.fn, control)$message))

# check for max iterations
control$stoppingConditions = list(makeMaximumIterationsStoppingCondition(max.iter = 10L))
expect_true(grepl("iterations", ecr(obj.fn, control)$message))
})

0 comments on commit f855571

Please sign in to comment.