library(testthat)
test_that("A few combinations", {
 source("/esarchive/scratch/nperez/git/Flor/OperationalCS/data_analysis/check_recipe.R")
 recipe <- list(Analysis = 
                list(Variables = list(ECVs = 'tas', Indicators = 'gdd'),
                     Workflow = list(Calibration = 'SBC', Indicators = TRUE)))
 conf <- list(code_dir = "/esarchive/scratch/nperez/git/Flor/OperationalCS/")
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = NULL,
                   dependent = list(c('tas', 'gdd'))))
 
 recipe <- list(Analysis = 
                list(Variables = list(ECVs = 'tas', Indicators = 'gdd'),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC'))) 
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('tas', 'gdd'), dependent = NULL))
  
 recipe <- list(Analysis =
                list(Variables = list(ECVs = 'tas'),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c(ECVs = 'tas'), dependent = NULL))

 recipe <- list(Analysis =
                list(Variables = list(ECVs = 'tas', 'tasmax'),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c(ECVs = 'tas', 'tasmax'), dependent = NULL))

 recipe <- list(Analysis =
                list(Variables = list(Indicators = 'gdd'),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c(Indicators = 'gdd'), dependent = NULL))
 
 recipe <- list(Analysis =
                list(Variables = list(ECVs = 'tas', 
                                      Indicators = list('gdd', 'gst')), 
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('tas', 'gdd', 'gst'), dependent = NULL))

 recipe <- list(Analysis =
                list(Variables = list(ECVs = 'tas', 
                                      Indicators = list('gdd', 'gst')),  
                     Workflow = list(Calibration = 'SBC', Indicators = TRUE)))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = NULL, dependent = list(c('tas', 'gdd', 'gst'))))
# Dependent workflow: cal & ind
  recipe <- list(Analysis =
                list(Variables = list(
                                      Indicators = list('gdd', 'gst')),
                     Workflow = list(Calibration = 'SBC', Indicators = TRUE)))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = NULL, dependent = list(c('gdd', 'gst'))))

  recipe <- list(Analysis =
                list(Variables = list(ECVs = 'tasmax',
                                      Indicators = list('gdd', 'gst')),
                     Workflow = list(Calibration = 'SBC', Indicators = TRUE)))
  expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = 'tasmax', dependent = list(c('gdd', 'gst'))))

  recipe <- list(Analysis =
                 list(Variables = list(ECVs = list('tasmax', 'tas'),
                                      Indicators = list('gdd', 'gst')),
                     Workflow = list(Calibration = 'SBC', Indicators = TRUE)))
  expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = 'tasmax', dependent = list(c('tas', 'gdd', 'gst'))))

  recipe <- list(Analysis =
                 list(Variables = list(ECVs = list('tasmax', 'tas'),
                                      Indicators = list('gdd', 'gst', 'spr32')),
                     Workflow = list(Calibration = 'SBC', Indicators = TRUE)))
  expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = NULL, 
                   dependent = list(c('tasmax', 'spr32'), c('tas', 'gdd', 'gst'))))
# Independent workflow: ind & cal
  recipe <- list(Analysis =
                list(Variables = list(
                                      Indicators = list('gdd', 'gst')),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('gdd', 'gst'), dependent = NULL))

  recipe <- list(Analysis =
                list(Variables = list(ECVs = 'tasmax',
                                      Indicators = list('gdd', 'gst')),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
  expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('tasmax', 'gdd', 'gst'), dependent = NULL))

  recipe <- list(Analysis =
                 list(Variables = list(ECVs = list('tasmax', 'tas'),
                                      Indicators = list('gdd', 'gst')),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
  expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('tasmax', 'tas', 'gdd', 'gst'), dependent = NULL))

  recipe <- list(Analysis =
                 list(Variables = list(ECVs = list('tasmax', 'tas'),
                                      Indicators = list('gdd', 'gst', 'spr32')),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
  expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('tasmax', 'spr32', 'tas', 'gdd', 'gst'),
                   dependent = NULL))
})
