Skip to content

Commit

Permalink
Fix tests to match new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vfisikop committed Feb 26, 2024
1 parent 29ab8e6 commit 9f81805
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
20 changes: 10 additions & 10 deletions tests/testthat/test_Hvol.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
})

}
12 changes: 6 additions & 6 deletions tests/testthat/test_Vvol.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test_Zvol.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})

}
24 changes: 12 additions & 12 deletions tests/testthat/test_rounding.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
})


}

0 comments on commit 9f81805

Please sign in to comment.