library(medfate)

data(examplemeteo)
data(exampleforest)
data(SpParamsMED)
d = 100:105
examplesoil = defaultSoilParams(4)


test_that("Can produce all basic spwb plots and summaries",{
  control = defaultControl("Granier")
  control$verbose = FALSE
  x1 = spwbInput(exampleforest,examplesoil, SpParamsMED, control)
  expect_s3_class(x1, "spwbInput")
  S1<-spwb(x1, examplemeteo[d,], latitude = 41.82592, elevation = 100)
  expect_s3_class(S1, "spwb")
  expect_type(fireHazard(S1, SpParamsMED, exampleforest), "double")
  plot_types <- c("PET_Precipitation", "PET_NetRain", "Snow", "Export", 
                  "Evapotranspiration", "SoilPsi", "SoilRWC", "SoilREW", "SoilTheta", "SoilVol", "PlantExtraction", "HydraulicRedistribution", "LAI", "GroundIrradiance", "PlantLAI", "PlantLAIlive", "PlantTranspiration", "TranspirationPerLeaf", "PlantWaterBalance", "PlantGrossPhotosynthesis", "GrossPhotosynthesisPerLeaf", "FPAR", "AbsorbedSWRFraction", "PlantPsi", "StemRWC", "LeafRWC", "LFMC", "PlantStress", "LeafPLC", "StemPLC")
  for(type in plot_types) {
    expect_s3_class(plot(S1, type), "ggplot")
    expect_s3_class(plot(S1, type, summary.freq = "weeks"), "ggplot")
  }
  expect_type(summary(S1, output = "WaterBalance"), "double")
  expect_type(summary(S1, output = "RWC"), "double")
  expect_type(summary(S1, output = "Stand"), "double")
  expect_type(summary(S1, output = "Plants$LAI"), "double")
  expect_type(summary(S1, output = "AbsorbedSWRFraction"), "double")
  expect_type(summary(S1, output = "Transpiration"), "double")
  expect_type(summary(S1, output = "GrossPhotosynthesis"), "double")
  expect_type(summary(S1, output = "PlantPsi"), "double")
  expect_type(summary(S1, output = "LeafPLC"), "double")
  expect_type(summary(S1, output = "StemPLC"), "double")
  expect_type(summary(S1, output = "PlantStress"), "double")
  expect_type(droughtStress(S1, index = "ADS", draw=FALSE), "double")
  expect_type(waterUseEfficiency(S1, type = "Plant Ag/E", draw=FALSE), "double")
  expect_type(waterUseEfficiency(S1, type = "Stand Ag/E", draw=FALSE), "double")
  expect_s3_class(extract(S1, level = "forest"), "data.frame")
  expect_s3_class(extract(S1, level = "soillayer"), "data.frame")
  expect_s3_class(extract(S1, level = "cohort"), "data.frame")
})

test_that("Can produce all aspwb plots and summaries",{
  control <- defaultControl("Granier")
  control$verbose <- FALSE
  x1 <- aspwbInput(0.75, control, examplesoil)
  expect_s3_class(x1, "aspwbInput")
  S1 <- aspwb(x1, examplemeteo, latitude = 41.82592, elevation = 100)
  expect_s3_class(S1, "aspwb")
  expect_s3_class(plot(S1, "PET_Precipitation"), "ggplot")
  expect_s3_class(plot(S1, "Snow"), "ggplot")
  expect_s3_class(plot(S1, "Export"), "ggplot")
  expect_s3_class(plot(S1, "Evapotranspiration"), "ggplot")
  expect_s3_class(plot(S1, "SoilPsi"), "ggplot")
  expect_s3_class(plot(S1, "SoilREW"), "ggplot")
  expect_s3_class(plot(S1, "SoilRWC"), "ggplot")
  expect_s3_class(plot(S1, "SoilTheta"), "ggplot")
  expect_s3_class(plot(S1, "SoilVol"), "ggplot")
  expect_type(summary(S1, output = "WaterBalance"), "double")
  expect_type(summary(S1, output = "RWC", FUN = "mean"), "double")
  expect_s3_class(extract(S1, level = "soillayer"), "data.frame")
})

test_that("Can produce all advanced spwb plots and summaries",{
  for(transpirationMode in c("Sperry", "Sureau")) {
    control = defaultControl(transpirationMode)
    control$verbose = FALSE
    x2 = spwbInput(exampleforest,examplesoil, SpParamsMED, control)
    coh_1 = row.names(x2$cohorts)[1]
    expect_s3_class(x2, "spwbInput")
    S2<-spwb(x2, examplemeteo[d,], latitude = 41.82592, elevation = 100)
    expect_s3_class(S2, "spwb")
    expect_type(fireHazard(S2, SpParamsMED, exampleforest), "double")
    expect_s3_class(plot(S2, "SoilPlantConductance"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiMin"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiMax"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiRange"), "ggplot")
    expect_s3_class(plot(S2, "StemPsi"), "ggplot")
    expect_s3_class(plot(S2, "RootPsi"), "ggplot")
    expect_s3_class(plot(S2, "TempMin_SL"), "ggplot")
    expect_s3_class(plot(S2, "TempMin_SH"), "ggplot")
    expect_s3_class(plot(S2, "TempMax_SL"), "ggplot")
    expect_s3_class(plot(S2, "TempMax_SH"), "ggplot")
    expect_s3_class(plot(S2, "GSWMin_SL"), "ggplot")
    expect_s3_class(plot(S2, "GSWMin_SH"), "ggplot")
    expect_s3_class(plot(S2, "GSWMax_SL"), "ggplot")
    expect_s3_class(plot(S2, "GSWMax_SH"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiMin_SL"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiMin_SH"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiMax_SL"), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiMax_SH"), "ggplot")
    expect_s3_class(plot(S2, "StemRWC"), "ggplot")
    expect_s3_class(plot(S2, "LeafRWC"), "ggplot")
    expect_s3_class(plot(S2, "LFMC"), "ggplot")
    expect_s3_class(plot(S2, "PlantWaterBalance"), "ggplot")
    expect_s3_class(plot(S2, "PlantNetPhotosynthesis"), "ggplot")
    expect_s3_class(plot(S2, "NetPhotosynthesisPerLeaf"), "ggplot")
    expect_s3_class(plot(S2, "PlantWUE"), "ggplot")
    expect_s3_class(plot(S2, "PlantAbsorbedSWR"), "ggplot")
    expect_s3_class(plot(S2, "AbsorbedSWRPerLeaf"), "ggplot")
    expect_s3_class(plot(S2, "PlantNetLWR"), "ggplot")
    expect_s3_class(plot(S2, "NetLWRPerLeaf"), "ggplot")
    expect_s3_class(plot(S2, "Temperature"), "ggplot")
    expect_s3_class(plot(S2, "AirTemperature"), "ggplot")
    expect_s3_class(plot(S2, "CanopyTemperature"), "ggplot")
    expect_s3_class(plot(S2, "SoilTemperature"), "ggplot")
    expect_s3_class(plot(S2, "CanopyEnergyBalance"), "ggplot")
    expect_s3_class(plot(S2, "SoilEnergyBalance"), "ggplot")
    expect_type(summary(S2, output = "AbsorbedSWR"), "double")
    expect_type(summary(S2, output = "NetLWR"), "double")
    expect_type(summary(S2, output = "NetPhotosynthesis"), "double")
    expect_type(summary(S2, output = "dEdP"), "double")
    expect_type(summary(S2, output = "PlantWaterBalance"), "double")
    expect_type(summary(S2, output = "LeafPsiMin"), "double")
    expect_type(summary(S2, output = "LeafPsiMax"), "double")
    expect_type(summary(S2, output = "LeafRWC"), "double")
    expect_type(summary(S2, output = "StemRWC"), "double")
    expect_type(summary(S2, output = "LFMC"), "double")
    expect_type(summary(S2, output = "StemPsi"), "double")
    expect_type(summary(S2, output = "RootPsi"), "double")
    expect_type(summary(S2, output = "SunlitLeaves$LeafPsiMin"), "double")
    expect_type(summary(S2, output = "ShadeLeaves$LeafPsiMin"), "double")
    expect_type(summary(S2, output = "SunlitLeaves$LeafPsiMax"), "double")
    expect_type(summary(S2, output = "ShadeLeaves$LeafPsiMax"), "double")
    expect_type(summary(S2, output = "SunlitLeaves$TempMin"), "double")
    expect_type(summary(S2, output = "ShadeLeaves$TempMin"), "double")
    expect_type(summary(S2, output = "SunlitLeaves$TempMax"), "double")
    expect_type(summary(S2, output = "ShadeLeaves$TempMax"), "double")
    expect_type(summary(S2, output = "SunlitLeaves$GSWMin"), "double")
    expect_type(summary(S2, output = "ShadeLeaves$GSWMin"), "double")
    expect_type(summary(S2, output = "SunlitLeaves$GSWMax"), "double")
    expect_type(summary(S2, output = "ShadeLeaves$GSWMax"), "double")
    expect_type(droughtStress(S2, index = "ADS", draw=FALSE), "double")
    expect_type(waterUseEfficiency(S2, "Plant An/E", draw=FALSE), "double")
    expect_type(waterUseEfficiency(S2, "Stand An/E", draw=FALSE), "double")
    expect_type(resistances(S2, cohort = coh_1, draw=FALSE), "list")
    expect_s3_class(extract(S2, level = "shadeleaf"), "data.frame")
    expect_s3_class(extract(S2, level = "sunlitleaf"), "data.frame")
  }
})

test_that("Can produce all advanced subdaily spwb plots",{
  for(transpirationMode in c("Sperry", "Sureau")) {
    control = defaultControl(transpirationMode)
    control$verbose <- FALSE
    control$subdailyResults <- TRUE
    x2 <- spwbInput(exampleforest,examplesoil, SpParamsMED, control)
    expect_s3_class(x2, "spwbInput")
    S2<-spwb(x2, examplemeteo[d,], latitude = 41.82592, elevation = 100)
    expect_s3_class(S2, "spwb")
    
    expect_s3_class(plot(S2, "LeafPsi", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafPsiAverage", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "RootPsi", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "StemPsi", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "StemRWC", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafRWC", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "StemPLC", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "StemSympRWC", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafSympRWC", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "StemSympPsi", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafSympPsi", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "PlantExtraction", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "PlantTranspiration", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafTranspiration", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "TranspirationPerLeaf", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "PlantGrossPhotosynthesis", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafGrossPhotosynthesis", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "PlantNetPhotosynthesis", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafNetPhotosynthesis", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafAbsorbedPAR", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafAbsorbedSWR", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafNetLWR", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafCi", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafIntrinsicWUE", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafVPD", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafStomatalConductance", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "LeafTemperature", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "Temperature", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(S2, "PlantWaterBalance", subdaily = TRUE), "ggplot")
    expect_type(waterUseEfficiency(S2, type = "Leaf Ci", draw=FALSE), "double")
    expect_type(waterUseEfficiency(S2, type = "Leaf iWUE", draw=FALSE), "double")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="E"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="Ag"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="An"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="dEdP"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="RootPsi"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="StemPsi"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="StemPLC"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="StemRWC"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="LeafRWC"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="StemSympRWC"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="LeafSympRWC"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="PWB"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="Temperature"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="ExtractionInst"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Abs_PAR"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Abs_SWR"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Net_LWR"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$E"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Ag"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$An"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Ci"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Gsw"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$VPD"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Temp"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$Psi"), "data.frame")
    expect_s3_class(medfate:::.extractSubdaily(S2, output="SunlitLeaves$iWUE"), "data.frame")    
  }    
})

test_that("Can produce all advanced spwb_day plots",{
  for(transpirationMode in c("Sperry", "Sureau")) {
    control = defaultControl(transpirationMode)
    control$verbose <- TRUE
    control$subdailyResults <- TRUE
    x2 = spwbInput(exampleforest,examplesoil, SpParamsMED, control)
    expect_s3_class(x2, "spwbInput")
    d1 = d[1]
    sd2<-spwb_day(x2, examplemeteo$dates[d1],
                  unlist(examplemeteo[d1,]), 
                  latitude = 41.82592, elevation = 100, slope=0, aspect=0)
    expect_s3_class(sd2, "spwb_day")
    expect_type(fireHazard(sd2, SpParamsMED, exampleforest), "double")
    expect_s3_class(plot(sd2, "LeafPsi"), "ggplot")
    expect_s3_class(plot(sd2, "LeafPsiAverage"), "ggplot")
    expect_s3_class(plot(sd2, "RootPsi"), "ggplot")
    expect_s3_class(plot(sd2, "StemPsi"), "ggplot")
    expect_s3_class(plot(sd2, "StemPLC"), "ggplot")
    expect_s3_class(plot(sd2, "StemRWC"), "ggplot")
    expect_s3_class(plot(sd2, "LeafRWC"), "ggplot")
    expect_s3_class(plot(sd2, "StemSympRWC"), "ggplot")
    expect_s3_class(plot(sd2, "LeafSympRWC"), "ggplot")
    expect_s3_class(plot(sd2, "SoilPlantConductance"), "ggplot")
    expect_s3_class(plot(sd2, "PlantExtraction"), "ggplot")
    expect_s3_class(plot(sd2, "PlantTranspiration"), "ggplot")
    expect_s3_class(plot(sd2, "TranspirationPerLeaf"), "ggplot")
    expect_s3_class(plot(sd2, "PlantGrossPhotosynthesis"), "ggplot")
    expect_s3_class(plot(sd2, "GrossPhotosynthesisPerLeaf"), "ggplot")
    expect_s3_class(plot(sd2, "PlantNetPhotosynthesis"), "ggplot")
    expect_s3_class(plot(sd2, "NetPhotosynthesisPerLeaf"), "ggplot")
    expect_s3_class(plot(sd2, "LeafTranspiration"), "ggplot")
    expect_s3_class(plot(sd2, "LeafGrossPhotosynthesis"), "ggplot")
    expect_s3_class(plot(sd2, "LeafNetPhotosynthesis"), "ggplot")
    expect_s3_class(plot(sd2, "LeafAbsorbedSWR"), "ggplot")
    expect_s3_class(plot(sd2, "LeafAbsorbedPAR"), "ggplot")
    expect_s3_class(plot(sd2, "LeafNetLWR"), "ggplot")
    expect_s3_class(plot(sd2, "LeafCi"), "ggplot")
    expect_s3_class(plot(sd2, "LeafIntrinsicWUE"), "ggplot")
    expect_s3_class(plot(sd2, "LeafStomatalConductance"), "ggplot")
    expect_s3_class(plot(sd2, "LeafTemperature"), "ggplot")
    expect_s3_class(plot(sd2, "Temperature"), "ggplot")
    expect_s3_class(plot(sd2, "CanopyEnergyBalance"), "ggplot")
    expect_s3_class(plot(sd2, "SoilEnergyBalance"), "ggplot")
    expect_s3_class(plot(sd2, "PlantWaterBalance"), "ggplot")
    expect_s3_class(plot(sd2, "WaterBalancePerLeaf"), "ggplot")    
  }
})

test_that("Can produce all basic growth plots and summaries",{
  examplesoil = defaultSoilParams(4)
  control = defaultControl("Granier")
  control$verbose = FALSE
  x1 = growthInput(exampleforest,examplesoil, SpParamsMED, control)
  expect_s3_class(x1, "growthInput")
  G1<-growth(x1, examplemeteo[d,], latitude = 41.82592, elevation = 100)
  expect_s3_class(G1, "growth")
  
  expect_type(fireHazard(G1, SpParamsMED, exampleforest), "double")
  expect_s3_class(plot(G1, "CarbonBalance"), "ggplot")
  expect_s3_class(plot(G1, "DecompositionPools"), "ggplot")
  expect_s3_class(plot(G1, "BiomassBalance"), "ggplot")
  expect_s3_class(plot(G1, "GrossPhotosynthesis"), "ggplot")
  expect_s3_class(plot(G1, "MaintenanceRespiration"), "ggplot")
  expect_s3_class(plot(G1, "LabileCarbonBalance"), "ggplot")
  expect_s3_class(plot(G1, "SugarLeaf"), "ggplot")
  expect_s3_class(plot(G1, "StarchLeaf"), "ggplot")
  expect_s3_class(plot(G1, "SugarSapwood"), "ggplot")
  expect_s3_class(plot(G1, "StarchSapwood"), "ggplot")
  expect_s3_class(plot(G1, "SugarTransport"), "ggplot")
  expect_s3_class(plot(G1, "RootExudation"), "ggplot")
  expect_s3_class(plot(G1, "StructuralBiomassBalance"), "ggplot")
  expect_s3_class(plot(G1, "LabileBiomassBalance"), "ggplot")
  expect_s3_class(plot(G1, "PlantBiomassBalance"), "ggplot")
  expect_s3_class(plot(G1, "MortalityBiomassLoss"), "ggplot")
  expect_s3_class(plot(G1, "CohortBiomassBalance"), "ggplot")
  expect_s3_class(plot(G1, "SapwoodArea"), "ggplot")
  expect_s3_class(plot(G1, "LeafArea"), "ggplot")
  expect_s3_class(plot(G1, "FineRootBiomass"), "ggplot")
  expect_s3_class(plot(G1, "DBH"), "ggplot")
  expect_s3_class(plot(G1, "Height"), "ggplot")
  expect_s3_class(plot(G1, "SAgrowth"), "ggplot")
  expect_s3_class(plot(G1, "LAgrowth"), "ggplot")
  expect_s3_class(plot(G1, "HuberValue"), "ggplot")
  expect_type(summary(G1, output = "CarbonBalance"), "double")
  expect_type(summary(G1, output = "LabileCarbonBalance$GrossPhotosynthesis"), "double")
  expect_type(summary(G1, output = "MaintenanceRespiration"), "double")
  expect_type(summary(G1, output = "GrowthCosts"), "double")
  expect_type(summary(G1, output = "RootExudation"), "double")
  expect_type(summary(G1, output = "LabileCarbonBalance"), "double")
  expect_type(summary(G1, output = "SugarLeaf"), "double")
  expect_type(summary(G1, output = "StarchLeaf"), "double")
  expect_type(summary(G1, output = "SugarSapwood"), "double")
  expect_type(summary(G1, output = "StarchSapwood"), "double")
  expect_type(summary(G1, output = "SugarTransport"), "double")
  expect_type(summary(G1, output = "LeafArea"), "double")
  expect_type(summary(G1, output = "SapwoodArea"), "double")
  expect_type(summary(G1, output = "FineRootBiomass"), "double")
  expect_type(summary(G1, output = "LAgrowth"), "double")
  expect_type(summary(G1, output = "SAgrowth"), "double")
  expect_type(droughtStress(G1, index = "ADS", draw=FALSE), "double")
  expect_type(waterUseEfficiency(G1, type = "Plant Ag/E", draw=FALSE), "double")
  expect_type(waterUseEfficiency(G1, type = "Stand Ag/E", draw=FALSE), "double")
  
})

test_that("Can produce all advanced growth plots and summaries",{
  for(transpirationMode in c("Sperry", "Sureau")) {
    control = defaultControl(transpirationMode)
    control$verbose = FALSE
    x2 = growthInput(exampleforest,examplesoil, SpParamsMED, control)
    coh_1 = row.names(x2$cohorts)[1]
    expect_s3_class(x2, "growthInput")
    G2<-growth(x2, examplemeteo[d,], latitude = 41.82592, elevation = 100)
    expect_s3_class(G2, "growth")
    expect_type(fireHazard(G2, SpParamsMED, exampleforest), "double")
    expect_s3_class(plot(G2, "FineRootArea"), "ggplot")
    expect_s3_class(plot(G2, "FRAgrowth"), "ggplot")
    expect_s3_class(plot(G2, "RootAreaLeafArea"), "ggplot")
    expect_type(summary(G2, output = "FineRootArea"), "double")
    expect_type(summary(G2, output = "FRAgrowth"), "double")
    expect_type(droughtStress(G2, index = "ADS", draw=FALSE), "double")
    expect_type(waterUseEfficiency(G2, "Plant An/E", draw=FALSE), "double")
    expect_type(waterUseEfficiency(G2, "Stand An/E", draw=FALSE), "double")  
    expect_type(resistances(G2, cohort = coh_1, draw=FALSE), "list")
  }  
})

test_that("Can produce all advanced subdaily growth plots",{
  for(transpirationMode in c("Sperry", "Sureau")) {
    control = defaultControl(transpirationMode)
    control$verbose <- FALSE
    control$subdailyResults <- TRUE
    control$subdailyCarbonBalance <- TRUE
    x2 = growthInput(exampleforest,examplesoil, SpParamsMED, control)
    expect_s3_class(x2, "growthInput")
    G2<-growth(x2, examplemeteo[d,], latitude = 41.82592, elevation = 100)
    expect_s3_class(G2, "growth")
    
    expect_s3_class(plot(G2, "GrossPhotosynthesis", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "MaintenanceRespiration", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "GrowthCosts", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "RootExudation", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "LabileCarbonBalance", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "SugarTransport", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "SugarLeaf", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "SugarSapwood", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "StarchLeaf", subdaily = TRUE), "ggplot")
    expect_s3_class(plot(G2, "StarchSapwood", subdaily = TRUE), "ggplot")
    expect_type(waterUseEfficiency(G2, type = "Leaf Ci", draw=FALSE), "double")
    expect_type(waterUseEfficiency(G2, type = "Leaf iWUE", draw=FALSE), "double")
    expect_s3_class(.extractSubdaily(G2, output="GrossPhotosynthesis"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="MaintenanceRespiration"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="GrowthCosts"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="RootExudation"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="LabileCarbonBalance"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="SugarLeaf"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="SugarSapwood"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="StarchLeaf"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="StarchSapwood"), "data.frame")
    expect_s3_class(.extractSubdaily(G2, output="SugarTransport"), "data.frame")
  }
})

test_that("Can produce all advanced growth_day plots",{
  for(transpirationMode in c("Sperry", "Sureau")) {
    control = defaultControl(transpirationMode)
    control$verbose <- FALSE
    control$subdailyResults <- TRUE
    control$subdailyCarbonBalance <- TRUE
    x2 <- growthInput(exampleforest,examplesoil, SpParamsMED, control)
    expect_s3_class(x2, "growthInput")
    d1 <- d[1]
    sd2<-growth_day(x2, examplemeteo$dates[d1],
                    unlist(examplemeteo[d1,]), 
                    latitude = 41.82592, elevation = 100, slope=0, aspect=0)
    expect_s3_class(sd2, "growth_day")
    expect_type(fireHazard(sd2, SpParamsMED, exampleforest), "double")
    expect_s3_class(plot(sd2, "GrossPhotosynthesis"), "ggplot")
    expect_s3_class(plot(sd2, "MaintenanceRespiration"), "ggplot")
    expect_s3_class(plot(sd2, "RootExudation"), "ggplot")
    expect_s3_class(plot(sd2, "LabileCarbonBalance"), "ggplot")
    expect_s3_class(plot(sd2, "SugarLeaf"), "ggplot")
    expect_s3_class(plot(sd2, "StarchLeaf"), "ggplot")
    expect_s3_class(plot(sd2, "SugarSapwood"), "ggplot")
    expect_s3_class(plot(sd2, "StarchSapwood"), "ggplot")
    expect_s3_class(plot(sd2, "SugarTransport"), "ggplot")
  }  
})

test_that("Can produce all fordyn plots",{
  control <- defaultControl("Granier")
  control$verbose <- FALSE
  fd<-fordyn(exampleforest, examplesoil, 
             SpParamsMED, examplemeteo, control,
             latitude = 41.82592, elevation = 100)
  expect_s3_class(plot(fd, "PET_Precipitation"), "ggplot")
  expect_s3_class(plot(fd, "PET_NetRain"), "ggplot")
  expect_s3_class(plot(fd, "Snow"), "ggplot")
  expect_s3_class(plot(fd, "Export"), "ggplot")
  expect_s3_class(plot(fd, "Evapotranspiration"), "ggplot")
  expect_s3_class(plot(fd, "SoilPsi"), "ggplot")
  expect_s3_class(plot(fd, "SoilREW"), "ggplot")
  expect_s3_class(plot(fd, "SoilRWC"), "ggplot")
  expect_s3_class(plot(fd, "SoilTheta"), "ggplot")
  expect_s3_class(plot(fd, "SoilVol"), "ggplot")
  expect_s3_class(plot(fd, "PlantExtraction"), "ggplot")
  expect_s3_class(plot(fd, "HydraulicRedistribution"), "ggplot")
  expect_s3_class(plot(fd, "LAI"), "ggplot")
  expect_s3_class(plot(fd, "PlantLAI"), "ggplot")
  expect_s3_class(plot(fd, "PlantLAIlive"), "ggplot")
  expect_s3_class(plot(fd, "PlantStress"), "ggplot")
  expect_s3_class(plot(fd, "LeafPLC"), "ggplot")
  expect_s3_class(plot(fd, "StemPLC"), "ggplot")
  expect_s3_class(plot(fd, "PlantPsi"), "ggplot")
  expect_s3_class(plot(fd, "PlantTranspiration"), "ggplot")
  expect_s3_class(plot(fd, "TranspirationPerLeaf"), "ggplot")
  expect_s3_class(plot(fd, "PlantGrossPhotosynthesis"), "ggplot")
  expect_s3_class(plot(fd, "GrossPhotosynthesisPerLeaf"), "ggplot")
  expect_s3_class(plot(fd, "CarbonBalance"), "ggplot")
  expect_s3_class(plot(fd, "DecompositionPools"), "ggplot")
  expect_s3_class(plot(fd, "BiomassBalance"), "ggplot")
  expect_s3_class(plot(fd, "GrossPhotosynthesis"), "ggplot")
  expect_s3_class(plot(fd, "MaintenanceRespiration"), "ggplot")
  expect_s3_class(plot(fd, "LabileCarbonBalance"), "ggplot")
  expect_s3_class(plot(fd, "SugarLeaf"), "ggplot")
  expect_s3_class(plot(fd, "StarchLeaf"), "ggplot")
  expect_s3_class(plot(fd, "SugarSapwood"), "ggplot")
  expect_s3_class(plot(fd, "StarchSapwood"), "ggplot")
  expect_s3_class(plot(fd, "SugarTransport"), "ggplot")
  expect_s3_class(plot(fd, "RootExudation"), "ggplot")
  expect_s3_class(plot(fd, "StructuralBiomassBalance"), "ggplot")
  expect_s3_class(plot(fd, "LabileBiomassBalance"), "ggplot")
  expect_s3_class(plot(fd, "PlantBiomassBalance"), "ggplot")
  expect_s3_class(plot(fd, "MortalityBiomassLoss"), "ggplot")
  expect_s3_class(plot(fd, "CohortBiomassBalance"), "ggplot")
  expect_s3_class(plot(fd, "SapwoodArea"), "ggplot")
  expect_s3_class(plot(fd, "LeafArea"), "ggplot")
  expect_s3_class(plot(fd, "FineRootBiomass"), "ggplot")
  expect_s3_class(plot(fd, "DBH"), "ggplot")
  expect_s3_class(plot(fd, "Height"), "ggplot")
  expect_s3_class(plot(fd, "SAgrowth"), "ggplot")
  expect_s3_class(plot(fd, "LAgrowth"), "ggplot")
  expect_s3_class(plot(fd, "HuberValue"), "ggplot")
  expect_s3_class(plot(fd, "NumTreeSpecies"), "ggplot")
  expect_s3_class(plot(fd, "NumTreeCohorts"), "ggplot")
  expect_s3_class(plot(fd, "NumShrubSpecies"), "ggplot")
  expect_s3_class(plot(fd, "NumShrubCohorts"), "ggplot")
  expect_s3_class(plot(fd, "StandBasalArea"), "ggplot")
  expect_s3_class(plot(fd, "StandDensity"), "ggplot")
  expect_s3_class(plot(fd, "StandShrubCover"), "ggplot")
  expect_s3_class(plot(fd, "SpeciesBasalArea"), "ggplot")
  expect_s3_class(plot(fd, "SpeciesDensity"), "ggplot")
  expect_s3_class(plot(fd, "SpeciesShrubCover"), "ggplot")
  expect_s3_class(plot(fd, "CohortBasalArea"), "ggplot")
  expect_s3_class(plot(fd, "CohortDensity"), "ggplot")
  expect_s3_class(plot(fd, "CohortShrubCover"), "ggplot")
  expect_s3_class(plot(fd, "DominantTreeHeight"), "ggplot")
  expect_s3_class(plot(fd, "DominantTreeDiameter"), "ggplot")
  expect_s3_class(plot(fd, "QuadraticMeanTreeDiameter"), "ggplot")
  expect_s3_class(plot(fd, "HartBeckingIndex"), "ggplot")
  expect_s3_class(extract(fd, level = "forest"), "data.frame")
  expect_s3_class(extract(fd, level = "soillayer"), "data.frame")
  expect_s3_class(extract(fd, level = "cohort"), "data.frame")
})

