-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest-errorHandlingInitialization.R
More file actions
142 lines (106 loc) · 2.25 KB
/
test-errorHandlingInitialization.R
File metadata and controls
142 lines (106 loc) · 2.25 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
context('errorHandling')
test_that(
"Error in FUN - Initialization"
, {
skip_on_cran()
set.seed(10)
sf <- function(x,y) 1000 - (x-5)^2 - (y + 10)^2
FUN <- function(x,y) {
if (runif(1) > 0.25) stop("You foo'd when you should have bar'd.")
return(list(Score = sf(x,y)))
}
bounds = list(
x = c(0,15)
, y = c(-20,100)
)
expect_error(
bayesOpt(
FUN
, bounds
, initPoints = 3
, iters.n = 6
, errorHandling = "continue"
, verbose = 1
)
, "Errors encountered in initialization are listed above."
)
}
)
testthat::test_that(
"NA Return - Initialization"
, {
skip_on_cran()
set.seed(10)
sf <- function(x,y) 1000 - (x-5)^2 - (y + 10)^2
FUN <- function(x,y) {
return(list(Score = if (runif(1) > 0.5) sf(x,y) else NA))
}
bounds = list(
x = c(0,15)
, y = c(-20,100)
)
expect_error(
bayesOpt(
FUN
, bounds
, initPoints = 3
, iters.n = 8
, errorHandling = 2
, verbose = 1
)
, "Errors encountered in initialization are listed above."
)
}
)
testthat::test_that(
"1D Error Handling"
, {
skip_on_cran()
set.seed(11)
sf <- function(x) 1000 - x^2
FUN <- function(x) {
if (runif(1) > 0.5) stop("You foo'd when you should have bar'd.")
return(list(Score = sf(x)))
}
bounds = list(
x = c(-1000,1000)
)
expect_error(
bayesOpt(
FUN
, bounds
, initPoints = 3
, iters.n = 8
, errorHandling = 2
, verbose = 1
)
, "Errors encountered in initialization are listed above."
)
}
)
testthat::test_that(
"Malformed FUN Return"
, {
skip_on_cran()
set.seed(11)
sf <- function(x) 1000 - x^2
FUN <- function(x) {
ot <- if (runif(1) > 0.75) c(0,1) else 1
return(list(Score = sf(x), ot = ot))
}
bounds = list(
x = c(-1000,1000)
)
expect_error(
bayesOpt(
FUN
, bounds
, initPoints = 3
, iters.n = 8
, errorHandling = 2
, verbose = 1
)
, "Errors encountered in initialization are listed above."
)
}
)