tests/testthat/test_plot_weather.R

context("Plot informations about weather conditions")
library(weatheranalysisFR)
library(ggplot2)
library(cowplot)
library(scales)
library(reshape2)

test_that("Input: not fitting class", {
  expect_error(weather_plot(123))
  expect_error(weather_plot(1:20))
  expect_error(weather_plot("duration"))
})

test_that("Input: temperature", {
  d <- plot_weather(klimaFR$temp_mean)
  e <- plot_weather(klimaFR$temp_max, yr = c(1967, 1969, 1965))
  f <- plot_weather(klimaFR$temp_min, yr = c(1967, 1969, 1965), both = FALSE)
  graphics.off()
  expect_true(class(d)[1] == "gg")
  expect_true(length(d) == 9)
  expect_true(class(e)[1] == "gg")
  expect_true(length(e) == 9)
  expect_true(class(f)[1] == "gg")
  expect_true(length(f) == 9)
})

test_that("Input: duration", {
  d <- plot_weather(klimaFR$sun_dur)
  e <- plot_weather(klimaFR$sun_dur, yr = c(1967, 1969, 1965))
  f <- plot_weather(klimaFR$sun_dur, yr = c(1967, 1969, 1965), both = FALSE)
  graphics.off()
  expect_true(class(d)[1] == "gg")
  expect_true(length(d) == 9)
  expect_true(class(e)[1] == "gg")
  expect_true(length(e) == 9)
  expect_true(class(f)[1] == "gg")
  expect_true(length(f) == 9)
})

test_that("Input: height", {
  d <- plot_weather(klimaFR$precip)
  e <- plot_weather(klimaFR$precip, yr = c(1967, 1969, 1965))
  f <- plot_weather(klimaFR$precip, yr = c(1967, 1969, 1965), both = FALSE)
  graphics.off()
  expect_true(class(d)[1] == "gg")
  expect_true(length(d) == 9)
  expect_true(class(e)[1] == "gg")
  expect_true(length(e) == 9)
  expect_true(class(f)[1] == "gg")
  expect_true(length(f) == 9)
})

test_that("Input: speed", {
  d <- plot_weather(klimaFR$wind_speed)
  e <- plot_weather(klimaFR$wind_speed, yr = c(1967, 1969, 1965))
  f <- plot_weather(klimaFR$wind_speed, yr = c(1967, 1969, 1965), both = FALSE)
  graphics.off()
  expect_true(class(d)[1] == "gg")
  expect_true(length(d) == 9)
  expect_true(class(e)[1] == "gg")
  expect_true(length(e) == 9)
  expect_true(class(f)[1] == "gg")
  expect_true(length(f) == 9)
})
buozyte/weatheranalysisFR documentation built on Nov. 4, 2019, 8:16 a.m.