From 9f8180515b878209dffd442b247f7067400c4c90 Mon Sep 17 00:00:00 2001 From: vfisikop Date: Mon, 26 Feb 2024 18:01:13 +0200 Subject: [PATCH] Fix tests to match new interface --- tests/testthat/test_Hvol.R | 20 ++++++++++---------- tests/testthat/test_Vvol.R | 12 ++++++------ tests/testthat/test_Zvol.R | 14 +++++++------- tests/testthat/test_rounding.R | 24 ++++++++++++------------ 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/testthat/test_Hvol.R b/tests/testthat/test_Hvol.R index 061a33ac..16b657fd 100644 --- a/tests/testthat/test_Hvol.R +++ b/tests/testthat/test_Hvol.R @@ -4,15 +4,15 @@ library(volesti) Hruntest <- function(P, name_string, exactvol, tol, num_of_exps, alg, seed){ - + vol = 0 for (j in 1:num_of_exps) { if (alg == "CB") { - vol = vol + volume(P, seed = seed)$volume + vol = vol + volume(P, settings = list("seed" = seed))$volume } else if (alg == "SOB") { - vol = vol + volume(P, settings = list("algorithm" = "SOB"), seed = seed)$volume + vol = vol + volume(P, settings = list("algorithm" = "SOB", "seed" = seed))$volume } else { - vol = vol + volume(P, settings = list("algorithm" = "CG"), seed = seed)$volume + vol = vol + volume(P, settings = list("algorithm" = "CG", "seed" = seed))$volume } } vol = vol / num_of_exps @@ -28,7 +28,7 @@ Hruntest <- function(P, name_string, exactvol, tol, num_of_exps, alg, seed){ cran_only = TRUE for (i in 1:2) { - + if (i==1) { algo = 'CG' num_of_exps = 10 @@ -37,30 +37,30 @@ for (i in 1:2) { num_of_exps = 10 } - + test_that("Volume H-cube10", { P = gen_cube(10, 'H') res = Hruntest(P, 'H-cube10', 1024, 0.2, num_of_exps, algo, 5) expect_equal(res, 1) }) - + test_that("Volume H-cross5", { P = gen_cross(5, 'H') res = Hruntest(P, 'H-cross10', 0.2666667, 0.2, num_of_exps, algo, 5) expect_equal(res, 1) }) - + test_that("Volume H-prod_simplex_5_5", { P = gen_prod_simplex(5) res = Hruntest(P, 'H-prod_simplex_5_5', (1/prod(1:5))^2, 0.2, num_of_exps, algo, 5) expect_equal(res, 1) }) - + test_that("Volume H-cube10", { P = gen_cube(10, 'H') res = Hruntest(P, 'H-cube10', 1024, 0.2, 5, "SOB", 5) expect_equal(res, 1) }) - + } diff --git a/tests/testthat/test_Vvol.R b/tests/testthat/test_Vvol.R index 9e18e52b..9fcabf30 100644 --- a/tests/testthat/test_Vvol.R +++ b/tests/testthat/test_Vvol.R @@ -3,13 +3,13 @@ context("V-polytopes' volume test") library(volesti) Vruntest <- function(P, name_string, exactvol, tol, num_of_exps, algorithm,seed){ - + vol = 0 for (j in 1:num_of_exps) { if (algorithm == "CB") { - vol = vol + volume(P, rounding = "none", seed = seed)$volume + vol = vol + volume(P, settings=list("error" = 1, "seed" = seed), rounding = "none")$volume } else { - vol = vol + volume(P, settings = list("algorithm" = "CG", "error" = 0.1), rounding = "none", seed = seed)$volume + vol = vol + volume(P, settings = list("algorithm" = "CG", "error" = 1, "seed" = seed), rounding = "none")$volume } } vol = vol / num_of_exps @@ -29,12 +29,12 @@ for (i in 1:2) { seed = 5 if (i==1) { algo = 'CG' - tol = 0.2 + tol = 1 } else { algo = 'CB' - tol = 0.2 + tol = 1 } - + test_that("Volume V-simplex3", { P = gen_simplex(3, 'V') res = Vruntest(P, 'V-simplex3', 1/prod(1:3), tol, num_of_exps, algo, seed) diff --git a/tests/testthat/test_Zvol.R b/tests/testthat/test_Zvol.R index f382b003..3f13e7cf 100644 --- a/tests/testthat/test_Zvol.R +++ b/tests/testthat/test_Zvol.R @@ -3,14 +3,14 @@ context("Zonotopes' volume test") library(volesti) Zruntest <- function(P, name_string, tol, num_of_exps, algo, seed){ - + exactvol = exact_vol(P) vol = 0 for (j in 1:num_of_exps) { if (algo == "CB") { - vol = vol + volume(P, settings = list("hpoly" = FALSE), rounding = "none", seed = seed)$volume + vol = vol + volume(P, settings = list("hpoly" = FALSE, "error" = 0.5, "seed" = seed), rounding = "none")$volume } else { - vol = vol + volume(P, settings = list("algorithm" = "CG", "error" = 0.1), rounding = "none", seed = seed)$volume + vol = vol + volume(P, settings = list("algorithm" = "CG", "error" = 1, "seed" = seed), rounding = "none")$volume } } vol = vol / num_of_exps @@ -29,17 +29,17 @@ num_of_exps = 2 for (i in 1:2) { if (i==1) { algo = 'CG' - tol = 0.2 + tol = 1 } else { algo = 'CB' - tol = 0.2 + tol = 1 } test_that("Volume Zonotope_2_4", { #skip_if(Sys.info()[["machine"]] %in% c("x86_32")) - Z = gen_rand_zonotope(2, 4, seed = 127) + Z = gen_rand_zonotope(2, 4, generator = list("seed" = 127)) res = Zruntest(Z, 'Zonotope_2_4', tol, num_of_exps, algo, 5) expect_equal(res, 1) }) - + } diff --git a/tests/testthat/test_rounding.R b/tests/testthat/test_rounding.R index 5d308e36..48f931df 100644 --- a/tests/testthat/test_rounding.R +++ b/tests/testthat/test_rounding.R @@ -3,19 +3,19 @@ context("Rounding test") library(volesti) testRound <- function(P, exactvol, tol, name_string, num_of_exps, algo, rotation,seed){ - + if (rotation) { P = rand_rotate(P) - listHpoly = round_polytope(P, seed = seed) + listHpoly = round_polytope(P, settings=list("seed" = seed)) } else { - listHpoly = round_polytope(P, seed = seed) + listHpoly = round_polytope(P, settings=list("seed" = seed)) } vol = 0 for (j in 1:num_of_exps) { if (algo == "CB") { - vol = vol + listHpoly$round_value * volume(listHpoly$P, seed = seed)$volume + vol = vol + listHpoly$round_value * volume(listHpoly$P, settings=list("seed" = seed))$volume } else { - vol = vol + listHpoly$round_value * volume(listHpoly$P, settings=list("algorithm"="CG", "error"=0.1), seed = seed)$volume + vol = vol + listHpoly$round_value * volume(listHpoly$P, settings=list("algorithm"="CG", "error"=0.1, "seed" = seed))$volume } } vol = vol / num_of_exps @@ -26,24 +26,24 @@ testRound <- function(P, exactvol, tol, name_string, num_of_exps, algo, rotation res = 1 } return(res) - - + + } cran_only = TRUE for (i in 1:2) { - + num_of_exps = 10 - - - + + + test_that("Rounding H-skinny_cube10", { seed=5 P = gen_skinny_cube(10) res = testRound(P, 102400, 0.3, 'H-skinny_cube10', num_of_exps, 'CB', FALSE,seed) expect_equal(res, 1) }) - + }