context("WeightedMean tests")
set.seed(1)
dat1 <- array(rnorm(10000), dim = c(lat = 50, lon = 100))
lat1 <- seq(-90, 90, length.out = 50)
lon1 <- seq(0, 360, length.out = 101)[1:100]

set.seed(1)
dat2 <- array(rnorm(10000), dim = c(lat = 180, lon = 360, sdate = 2))
lat2 <- seq(-89.5, 89.5, length.out = 180)
lon2 <- seq(-180, 179, length.out = 360)

set.seed(1)
dat3 <- array(rnorm(10000), dim = c(sdate = 2, lat = 171, lon = 350))
lat3 <- seq(-90, 90, length.out = 181)[c(1:80, seq(81, 101, by = 2), 102:181)]
lon3 <- seq(-180, 179, length.out = 360)[c(1:170, seq(171, 190, by = 2), 191:360)]

set.seed(1)
dat4 <- array(rnorm(10000), dim = c(lat = 180, lon = 360, sdate = 2, time = 1))
lat4 <- seq(-89.5, 89.5, length.out = 180)
lon4 <- seq(-179.5, 179.5, length.out = 360)


test_that("dat1", {
expect_equal(
dim(WeightedMean(dat1, lat = lat1, lon = lon1)),
NULL
)
expect_equal(
as.vector(WeightedMean(dat1, lat = lat1, lon = lon1)),
-0.009785971,
tolerance = 0.0001
)
})

test_that("dat2", {
expect_equal(
dim(WeightedMean(dat2, lat = lat2, lon = lon2)),
NULL
)
expect_equal(
as.vector(WeightedMean(dat2, lat = lat2, lon = lon2)),
c(-0.005799676, -0.007599831),
tolerance = 0.0001
)
})

test_that("dat3", {
expect_equal(
dim(WeightedMean(dat3, lat = lat3, lon = lon3)),
NULL
)
expect_equal(
as.vector(WeightedMean(dat3, lat = lat3, lon = lon3)),
c(-0.0253997, 0.0132251),
tolerance = 0.0001
)

})


test_that("dat4", {
expect_equal(
dim(WeightedMean(dat4, lat = lat4, lon = lon4)),
c(sdate = 2, time = 1)
)
expect_equal(
as.vector(WeightedMean(dat4, lat = lat4, lon = lon4)),
c(-0.005799676, -0.007599831),
tolerance = 0.0001
)
})
