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 = list(name = 'tas'), 
                     Indicators = list(name = '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 = list(name = 'tas'),
                                      Indicators = list(name = '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 = list(name = list('tas'))),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('tas'), dependent = NULL))

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

 recipe <- list(Analysis =
                list(Variables = list(Indicators = list(list(name = 'gdd'))),
                     Workflow = list(Indicators = TRUE, Calibration = 'SBC')))
 expect_equal(check_number_of_dependent_verifications(recipe, conf),
              list(independent = c('gdd'), dependent = NULL))
 
 recipe <- list(Analysis =
                list(Variables = list(ECVs = list(list(name = 'tas')), 
                                      Indicators = list(list(name = 'gdd'), 
                                                        list(name = '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 = list(list(name = 'tas')), 
                                      Indicators = list(list(name = 'gdd'),
                                                        list(name = '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(list(name = 'gdd'), 
                                                        list(name = '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 = list(list(name = 'tasmax')),
                                      Indicators = list(list(name = 'gdd'),
                                                        list(name = '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(list(name = 'tasmax'), 
                                                   list(name = 'tas')),
                                      Indicators = list(list(name = 'gdd'), 
                                                        list(name = '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(list(name = 'tasmax'),
                                                   list(name = 'tas')),
                                      Indicators = list(list(name = 'gdd'), 
                                                        list(name = 'gst'), 
                                                        list(name = '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(list(name = 'gdd'), 
                                                        list(name = '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 = list(list(name ='tasmax')),
                                      Indicators = list(list(name = 'gdd'), 
                                                        list(name = '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(list(name = 'tasmax'), list(name = 'tas')),
                                      Indicators = list(list(name = 'gdd'), list(name = '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(list(name = 'tasmax'), list(name = 'tas')),
                                      Indicators = list(list(name = 'gdd'),
                                                        list(name = 'gst'), list(name = '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))
})
