Skip to content

Commit 6b2f484

Browse files
tests
1 parent 5fae8f4 commit 6b2f484

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

R/gcf_grid.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,31 @@ gcf_grid <- function (x = seq(0, 1, length.out = nrow(z)),
7373
mainminmax=!bar, mainminmax_minmax=TRUE,
7474
afterplotfunc=NULL,
7575
cex.main=par()$cex.main,
76-
...) {#browser()
76+
...) {
7777
if (missing(z)) {
7878
if (!missing(x)) {
7979
if (is.list(x)) {
8080
z <- x$z
8181
y <- x$y
8282
x <- x$x
83-
}
84-
else {
83+
} else {
8584
z <- x
8685
x <- seq.int(0, 1, length.out = nrow(z))
8786
}
87+
} else {
88+
stop("no 'z' matrix specified")
8889
}
89-
else stop("no 'z' matrix specified")
90-
}
91-
else if (is.list(x)) {
90+
} else if (is.list(x)) {
9291
y <- x$y
9392
x <- x$x
9493
}
95-
if (any(diff(x) <= 0) || any(diff(y) <= 0))
94+
if (any(diff(x) <= 0) || any(diff(y) <= 0)) {
9695
stop("increasing 'x' and 'y' values expected")
96+
}
9797

98-
if (any(diff(x) <= 0) || any(diff(y) <= 0))
98+
if (any(diff(x) <= 0) || any(diff(y) <= 0)) {
9999
stop("increasing 'x' and 'y' values expected")
100+
}
100101

101102

102103
t2 <- cbind(expand.grid(x, y), tz=c(z))

tests/testthat/test-gcf_grid.R

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,55 @@ test_that("gcf_grid works", {
1818
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), bar=T), NA)
1919
# pts
2020
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), pts=matrix(c(.1,.2,.3,.4),2,2)), NA)
21+
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), pts=c(.1,.2,.3,.4)), NA)
2122
# Can't reset.par
2223
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), reset.par = F))
2324
# afterplotfunc, not useful, maybe should remove
24-
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), afterplotfunc = function(){print("after")}), NA)
25+
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), afterplotfunc = function(){("after")}), NA)
26+
27+
# Lines
28+
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), lines_only = T), NA)
29+
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), with_lines = T), NA)
30+
expect_error(gcf_grid(cos(r^2)*exp(-r/(2*pi)), with_lines = T, lines_only = T), NA)
31+
32+
# Errors
33+
expect_error(gcf_grid()) # No z given
34+
expect_error(gcf_grid(x)) # No z given
35+
expect_error(gcf_grid(rev(x), y, cos(r^2)*exp(-r/(2*pi))))
36+
expect_error(gcf_grid(x, rev(y), cos(r^2)*exp(-r/(2*pi))))
37+
2538
})
39+
40+
test_that("gcf_func", {
41+
p1 <- gcf_func(function(xx){exp(-sum((xx-.5)^2/.1))})
42+
p2 <- cf_func(function(xx){exp(-sum((xx-.5)^2/.1))}, gg=T)
43+
expect_is(p1, "gg")
44+
expect_is(p2, "gg")
45+
})
46+
47+
test_that("gcf_data", {
48+
x <- runif(20)
49+
y <- runif(20)
50+
z <- exp(-(x-.5)^2-5*(y-.5)^2)# + rnorm(20,0,.05)
51+
p1 <- gcf_data(x,y,z)
52+
p2 <- cf_data(x,y,z, gg=T)
53+
expect_is(p1, "gg")
54+
expect_is(p2, "gg")
55+
})
56+
57+
test_that("gcf", {
58+
# Func
59+
p1 <- gcf(function(xx){exp(-sum((xx-.5)^2/.1))})
60+
p2 <- cf(function(xx){exp(-sum((xx-.5)^2/.1))}, gg=T)
61+
expect_is(p1, "gg")
62+
expect_is(p2, "gg")
63+
64+
# Data
65+
x <- runif(20)
66+
y <- runif(20)
67+
z <- exp(-(x-.5)^2-5*(y-.5)^2)# + rnorm(20,0,.05)
68+
p3 <- gcf_data(x,y,z)
69+
p4 <- cf_data(x,y,z, gg=T)
70+
expect_is(p3, "gg")
71+
expect_is(p4, "gg")
72+
})

0 commit comments

Comments
 (0)