File: test-hv.R

package info (click to toggle)
r-cran-eaf 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,016 kB
  • sloc: ansic: 7,281; perl: 848; makefile: 73; sh: 43; python: 27
file content (34 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
source("helper-common.R")

test_that("hypervolume", {
#skip_on_cran()
test.hv.rda <- function(dataset, reference, maximise = FALSE) {
  nobj <- length(reference)
  load(paste0(dataset, ".rda"))
  return(hypervolume(get(dataset)[,1:nobj], reference = reference, maximise))
}
test.hv.file <- function(file, reference, maximise = FALSE) {
  nobj <- length(reference)
  dataset <- read_datasets(file)
  return(hypervolume(dataset[,1:nobj], reference = reference, maximise))
}

expect_equal(test.hv.rda("DTLZDiscontinuousShape.3d.front.1000pts.10",
                         reference = c(10,10,10)),
             719.223555475191)

expect_equal(test.hv.file("duplicated3.inp",
                          reference = c(-14324, -14906, -14500, -14654, -14232, -14093)),
             1.52890128312393e+20)
})

test_that("hv_contributions", {
  hv_contributions_slow <- function(dataset, reference, maximise) {
    return(hypervolume(dataset, reference, maximise) -
           sapply(1:nrow(dataset), function(x) hypervolume(dataset[-x,], reference, maximise)))
  }
  reference = c(250,0)
  maximise = c(FALSE,TRUE)
  expect_equal(hv_contributions(SPEA2minstoptimeRichmond[,1:2], reference = reference, maximise = maximise),
               hv_contributions_slow(SPEA2minstoptimeRichmond[,1:2], reference = reference, maximise = maximise))
})