1
2test_that("crc class works", {
3  expect_s3_class(crc(), "wk_crc")
4  expect_output(print(crc(1, 2, 3)), "\\[1 2, r = 3\\]")
5  expect_identical(as_crc(crc(1, 2, 3)), crc(1, 2, 3))
6
7  expect_identical(
8    as_crc(as.matrix(data.frame(x = 1, y = 2, r = 3))),
9    crc(1, 2, 3)
10  )
11  expect_identical(
12    as_crc(data.frame(x = 1, y = 2, r = 3)),
13    crc(1, 2, 3)
14  )
15  expect_identical(
16    as_crc(matrix(1:3, nrow = 1)),
17    crc(1, 2, 3)
18  )
19})
20
21test_that("coercion to and from wk* classes works", {
22  expect_s3_class(as_wkt(crc(0, 0, 1)), "wk_wkt")
23  expect_s3_class(as_wkb(crc(0, 0, 1)), "wk_wkb")
24
25  expect_identical(
26    wk_handle(crc(1, 2, 3), wkt_writer(precision = 2), n_segments = 4),
27    wkt("POLYGON ((4 2, 1 5, -2 2, 1 -1, 4 2))")
28  )
29
30  expect_identical(
31    as_wkb(wk_handle(crc(1, 2, 3), wkt_writer(precision = 2), n_segments = 4)),
32    as_wkb("POLYGON ((4 2, 1 5, -2 2, 1 -1, 4 2))")
33  )
34
35  # check options for circle resolution + as_wkb/t()
36  prev_opt <- options(wk.crc_n_segments = 4)
37  expect_length(
38    unclass(as_wkb(crc(1, 2, 3)))[[1]],
39    1 + 4 + 4 + 4 + 5 * 8 * 2
40  )
41  options(prev_opt)
42})
43
44test_that("subset-assign works for crc", {
45  x <- crc(1:2, 2:3, 3:4)
46  x[1] <- crc(NA, NA, NA)
47  expect_identical(x, c(crc(NA, NA, NA), crc(2, 3, 4)))
48})
49
50test_that("crc() propagates CRS", {
51  x <- crc(1, 2, 3)
52  wk_crs(x) <- 1234
53
54  expect_identical(wk_crs(x[1]), 1234)
55  expect_identical(wk_crs(c(x, x)), 1234)
56  expect_identical(wk_crs(rep(x, 2)), 1234)
57
58  expect_error(x[1] <- wk_set_crs(x, NULL), "are not equal")
59  x[1] <- wk_set_crs(x, 1234L)
60  expect_identical(wk_crs(x), 1234)
61})
62