From 30c97693eb205c228d4c2286109862b88bd66916 Mon Sep 17 00:00:00 2001 From: evaaepelde Date: Thu, 15 Feb 2024 11:05:53 +0100 Subject: [PATCH] update tests --- tests/testthat/test_inputs/DI_impact.RData | Bin 1250 -> 1250 bytes tests/testthat/test_inputs/D_impacts.RData | Bin 1305 -> 1303 bytes .../test_inputs/ex_dataset_expenses.csv | 10 +- .../test_inputs/ex_dataset_expenses_ps.csv | 10 +- .../test_inputs/ex_dataset_renamed.csv | 10 +- tests/testthat/test_inputs/shocks_cdii.csv | 53 ++ tests/testthat/test_medusa.R | 517 ++++++++++-------- 7 files changed, 343 insertions(+), 257 deletions(-) create mode 100644 tests/testthat/test_inputs/shocks_cdii.csv diff --git a/tests/testthat/test_inputs/DI_impact.RData b/tests/testthat/test_inputs/DI_impact.RData index 92852e41984ec218c7afacc4bfc44fff7f52ad84..1c538a8ff78eaa17b630552b54975e38af75296a 100644 GIT binary patch delta 1205 zcmV;m1WNnj3E~MAABzY80000000z~VPi)&{6u=$lPmvWre;ZstoIo7V1QHicL#hS~ zpX2Yj_7{hxDJ=Am*zbMMFE8(V@8@R=(%EYUcV@IB6um%ee zCdQ=j@ql8AlBm=hsAicA!#?U5;_IAa5`RY8vTGa9Nln!X6?j#WjZk4xZ)(ewqv#yc zV0}TadqOuoe-Y?t^1LwLmk@N6%=5)*Uhs_iml-PEC^*;_Q zSL_Y`#%G!0y!}b-_66z7vc2{AGndy7zfP4wyrv@4B#DU;WqR4rn+;hKr6r4oebo%rZ!_uzO`6il}V}OtMy140m z!=o)~fB$mzF>uL-He?2uhe`jzjAZBy=SN5ee8LXb5}mT1p=>hX}K_dAaZe11;oOW1eQ%YRFj zyIsiAu@`|{4i+n6H@4mOgzM2ifJA)ff2{A^Kg7fsZ&29>P@?Y|Y}dW*mr8M=X&^74 zvRqe=G>uap>^n8_YNrr%IXZ=lTa`_2Rk2pM+KQq|hOG6nc&I&xs%u=$HR|P>VYmjV zx+YVh#7>rq{I1V~J`yuCmBo3!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3vVq@R9+AOJxCwnW~M~bZd3!E8%{Q>z>Tl zepG;J;lmygfTEb;upzh9E}@g{HYFRB%v(1LR8ZC}gMTPzdr zU$nju8F^Pp-zciiV>Lm4&7mU<(zY`GdS8nvW!3pRLlI5{GA~tZfbH7=+YjXxOQMk| zB_69NFDoxEN8;nAm~7>23;;Ro9-H1=VY3Ekcdy+Hq_x*@=YQf@unB_zkJ}{ z<(DvS@_(aem0z8@-f+nX8yUZ2YHV=}6DtNzp+`D4b1g05M-JJ8nhdZLAuh_7YH}Aq zo7o;-6_VFb?M(q@(|f~fn?Z;jzSrq8gKWd3xKHlAd-(LIPMl!RR=@BO(qnRVjvl@7 zYR!c1`QXz0-)~i7y-8B+=J;pN6wO8T{Ayxu|D6Y7R-M6p|x+?RH#(HOU zExq-whSdZWy=rxb&`8xLX<|=`eLaIebt3_95y!`{4PP*3541%VUY91pr?I7z-xgvv9{`~2X_Lpm`*U75-$L^B4~XMc437O4K@SKS_*F5Y$GJen!ew?&d1P7hHO zs*EliCY;Vl-LmL)9%i$SEoIYjsPTaGw&C^z!fZ@jVIBIe%7* z0F{?ex!ln#DQc<0MI?AYkq1-sdCf8(-AIw!3LB@SskEYMERWkE&XQ0|xX#an)^gx> z0GuThyOt%1hH0|z{bzK~_%7C(C8&8~y9d4=e*4UQW7aG|O%&S|_FTw6I$xQRC1x{C zW0qKhlHNY*Y8ntZS?T5b@KJ^nRd#^10.000,Urban,Elderly alone,Elder,Women,Spain,Without studies,Ownership,48035121,936972,475556,459558,46163035 -2,800,2,Baleares,>10.000,Semi-urban,Elderly couples,Elder,Men,Rest of world,Primary education,Ownership,12556374,141847.56,155361.82,78774.24,12180390 -3,390,3,Castilla y León,>10.000,Urban,Couples with children,Young,Women,Spain,Higher education,Rented,8707674,223205.74,506736.98,433788.12,7543943 -4,734,4,Comunidad Valenciana,>10.000,Semi-urban,Couples with children,Adult,Men,EU27,Higher education,Ownership,13642171,725488.8,880212.52,2123.85,12034346 -5,996,5,Navarra,<10.000,Rural,Couples with children,Adult,Women,Other Europe,Post-secondary education,Ownership,24007170,304459.64,612082.52,270376.66,22820251 +1,1667,1,Andalucía,>10.000,Urban,Elderly alone,Elder,Woman,Spain,Without studies,Ownership,48035121,936972,475556,459558,46163035 +2,800,2,Baleares,>10.000,Semi-urban,Elderly couples,Elder,Man,Rest of world,Primary education,Ownership,12556374,141847.56,155361.82,78774.24,12180390 +3,390,3,Castilla y León,>10.000,Urban,Couples with children,Young,Woman,Spain,Higher education,Rented,8707674,223205.74,506736.98,433788.12,7543943 +4,734,4,Comunidad Valenciana,>10.000,Semi-urban,Couples with children,Adult,Man,EU27,Higher education,Ownership,13642171,725488.8,880212.52,2123.85,12034346 +5,996,5,Navarra,<10.000,Rural,Couples with children,Adult,Woman,Other Europe,Post-secondary education,Ownership,24007170,304459.64,612082.52,270376.66,22820251 diff --git a/tests/testthat/test_inputs/ex_dataset_expenses_ps.csv b/tests/testthat/test_inputs/ex_dataset_expenses_ps.csv index a897aac..bcecfa3 100644 --- a/tests/testthat/test_inputs/ex_dataset_expenses_ps.csv +++ b/tests/testthat/test_inputs/ex_dataset_expenses_ps.csv @@ -1,6 +1,6 @@ "NUMERO","FACTOR","NMEMBERS","REGION","MUNISIZE","ZONE","HHTYPE","AGERP","GENDERRP","COUNTRYRP","STUDIESRP","REGMR","GASTOT_CNR","EUR_A_0111_CNR","EUR_A_0112_CNR","EUR_A_0113_CNR","EUR_A_0114_CNR","EUR_A_0111_Scenario1","EUR_A_0112_Scenario1","EUR_A_0113_Scenario1","EUR_A_0114_Scenario1","EUR_A_0111_Scenario2","EUR_A_0112_Scenario2","EUR_A_0113_Scenario2","EUR_A_0114_Scenario2","EUR_A_0111_Scenario3","EUR_A_0112_Scenario3","EUR_A_0113_Scenario3","EUR_A_0114_Scenario3","GASTOT_Scenario1","GASTOT_Scenario2","GASTOT_Scenario3" -1,1667,1,"Andalucía",">10.000","Urban","Elderly alone","Elder ","Women","Spain","Without studies","Ownership",48035121,936972,475556,459558,46163035,1873944,475556,459558,46163035,936972,1426668,459558,46163035,936972,475556,1838232,46163035,48972093,48986233,49413795 -2,800,2,"Baleares",">10.000","Semi-urban","Elderly couples","Elder ","Men","Rest of world","Primary education","Ownership",12556374,141847.56,155361.82,78774.24,12180390,283695.12,155361.82,78774.24,12180390,141847.56,466085.46,78774.24,12180390,141847.56,155361.82,315096.96,12180390,12698221.18,12867097.26,12792696.34 -3,390,3,"Castilla y León",">10.000","Urban","Couples with children","Young","Women","Spain","Higher education","Rented",8707674,223205.74,506736.98,433788.12,7543943,446411.48,506736.98,433788.12,7543943,223205.74,1520210.94,433788.12,7543943,223205.74,506736.98,1735152.48,7543943,8930879.58,9721147.8,10009038.2 -4,734,4,"Comunidad Valenciana",">10.000","Semi-urban","Couples with children","Adult","Men","EU27","Higher education","Ownership",13642171,725488.8,880212.52,2123.85,12034346,1450977.6,880212.52,2123.85,12034346,725488.8,2640637.56,2123.85,12034346,725488.8,880212.52,8495.4,12034346,14367659.97,15402596.21,13648542.72 -5,996,5,"Navarra","<10.000","Rural","Couples with children","Adult","Women","Other Europe","Post-secondary education","Ownership",24007170,304459.64,612082.52,270376.66,22820251,608919.28,612082.52,270376.66,22820251,304459.64,1836247.56,270376.66,22820251,304459.64,612082.52,1081506.64,22820251,24311629.46,25231334.86,24818299.8 +1,1667,1,"Andalucía",">10.000","Urban","Elderly alone","Elder","Woman","Spain","Without studies","Ownership",48035121,936972,475556,459558,46163035,1873944,475556,459558,46163035,936972,1426668,459558,46163035,936972,475556,1838232,46163035,48972093,48986233,49413795 +2,800,2,"Baleares",">10.000","Semi-urban","Elderly couples","Elder","Man","Rest of world","Primary education","Ownership",12556374,141847.56,155361.82,78774.24,12180390,283695.12,155361.82,78774.24,12180390,141847.56,466085.46,78774.24,12180390,141847.56,155361.82,315096.96,12180390,12698221.18,12867097.26,12792696.34 +3,390,3,"Castilla y León",">10.000","Urban","Couples with children","Young","Woman","Spain","Higher education","Rented",8707674,223205.74,506736.98,433788.12,7543943,446411.48,506736.98,433788.12,7543943,223205.74,1520210.94,433788.12,7543943,223205.74,506736.98,1735152.48,7543943,8930879.58,9721147.8,10009038.2 +4,734,4,"Comunidad Valenciana",">10.000","Semi-urban","Couples with children","Adult","Man","EU27","Higher education","Ownership",13642171,725488.8,880212.52,2123.85,12034346,1450977.6,880212.52,2123.85,12034346,725488.8,2640637.56,2123.85,12034346,725488.8,880212.52,8495.4,12034346,14367659.97,15402596.21,13648542.72 +5,996,5,"Navarra","<10.000","Rural","Couples with children","Adult","Woman","Other Europe","Post-secondary education","Ownership",24007170,304459.64,612082.52,270376.66,22820251,608919.28,612082.52,270376.66,22820251,304459.64,1836247.56,270376.66,22820251,304459.64,612082.52,1081506.64,22820251,24311629.46,25231334.86,24818299.8 diff --git a/tests/testthat/test_inputs/ex_dataset_renamed.csv b/tests/testthat/test_inputs/ex_dataset_renamed.csv index 02a142d..d1b44ad 100644 --- a/tests/testthat/test_inputs/ex_dataset_renamed.csv +++ b/tests/testthat/test_inputs/ex_dataset_renamed.csv @@ -1,6 +1,6 @@ NUMERO,FACTOR,NMEMBERS,REGION,MUNISIZE,ZONE,HHTYPE,AGERP,GENDERRP,COUNTRYRP,STUDIESRP,REGMR -1,1667,1,Andalucía,>10.000,Urban,Elderly alone,Elder ,Women,Spain,Without studies,Ownership -2,800,2,Baleares,>10.000,Semi-urban,Elderly couples,Elder ,Men,Rest of world,Primary education,Ownership -3,390,3,Castilla y León,>10.000,Urban,Couples with children,Young,Women,Spain,Higher education,Rented -4,734,4,Comunidad Valenciana,>10.000,Semi-urban,Couples with children,Adult,Men,EU27,Higher education,Ownership -5,996,5,Navarra,<10.000,Rural,Couples with children,Adult,Women,Other Europe,Post-secondary education,Ownership +1,1667,1,Andalucía,>10.000,Urban,Elderly alone,Elder,Woman,Spain,Without studies,Ownership +2,800,2,Baleares,>10.000,Semi-urban,Elderly couples,Elder,Man,Rest of world,Primary education,Ownership +3,390,3,Castilla y León,>10.000,Urban,Couples with children,Young,Woman,Spain,Higher education,Rented +4,734,4,Comunidad Valenciana,>10.000,Semi-urban,Couples with children,Adult,Man,EU27,Higher education,Ownership +5,996,5,Navarra,<10.000,Rural,Couples with children,Adult,Woman,Other Europe,Post-secondary education,Ownership diff --git a/tests/testthat/test_inputs/shocks_cdii.csv b/tests/testthat/test_inputs/shocks_cdii.csv new file mode 100644 index 0000000..c8d0818 --- /dev/null +++ b/tests/testthat/test_inputs/shocks_cdii.csv @@ -0,0 +1,53 @@ +names,coicop,Scenario1,Scenario2,Scenario3 +Bread and cereals,EUR_A_0111,2,3,1 +Meat,EUR_A_0112,1,1,1 +Fish,EUR_A_0113,1,1,1 +"Milk, cheese and eggs",EUR_A_0114,1,1,1 +Oils and fats,EUR_A_0115,1,1,1 +Fruits,EUR_A_0116,1,1,1 +Vegetables including potatoes and other root vegetables,EUR_A_0117,1,1,1 +"Sugar, preserves, honey, chocolate, confectionery and ice cream",EUR_A_0118,1,1,1 +Food products not included above,EUR_A_0119,1,1,1 +Non-alcoholic beverages,EUR_A_012,1,1,1 +Alcoholic beverages,EUR_A_021,1,1,1 +Tabacco,EUR_A_022,1,1,1 +Narcotics,EUR_A_023,1,1,1 +Articles of clothing,EUR_A_031,1,1,1 +Footwear,EUR_A_032,1,1,1 +Real rentals,EUR_A_041,1,1,1 +Imputed rents,EUR_A_042,1,1,1 +Current expenses of maintenance and repair of the housing,EUR_A_043,1,1,1 +Other services related to housing,EUR_A_044,1,1,1 +"Electricity, gas and other fuels",EUR_A_045,1.2,1,3 +"Furniture, furnishing articles, carpets and other floor coverings and their repairs",EUR_A_051,1,1,1 +Textile articles for the home and their repairs,EUR_A_052,1,1,1 +"Heating and applicances, refrigerators, washing machines and other large domestic applicances; accesories and their repairs",EUR_A_053,1,1,1 +"Glassware, crockery, cutlery, other household utensils and their repairs",EUR_A_054,1,1,1 +Tools for home and garden,EUR_A_055,1,1,1 +Goods and services for the current maintenance of the home,EUR_A_056,1,1,1 +"Medicines and other pharmaceutical products, devices and therapeutic material",EUR_A_061,1,1,1 +Out-of-hospital medical and paramedical services,EUR_A_062,1,1,1 +Hospital services,EUR_A_063,1,1,1 +Purchase of vehicles,EUR_A_071,1,1,1 +Use of personal vehicles,EUR_A_072,1,1,1 +Terrestrial public transport,EUR_A_073_T,1,1.5,2 +Air transport,EUR_A_073_A,1,1,1 +Maritim transport,EUR_A_073_M,1,1,1 +Postal services,EUR_A_081,1,1,1 +Telephone and fax equipment,EUR_A_082,1,1,1 +"Telephone, telegraph and fax services",EUR_A_083,1,1,1 +"Audiovisual, photographic and information processing equipment and accessories including their repairs",EUR_A_091,1,1,1 +Other important durable goods for leisure and culture,EUR_A_092,1,1,1 +"Other recreational items and equipment, flowers, gardening, and pets",EUR_A_093,1,1,1 +Recreational and cultural services,EUR_A_094,1,1,1 +"Press, bookstore and stationery",EUR_A_095,1,1,1 +All-include vacations,EUR_A_096,1,1,1 +Education,EUR_A_101_105,1,1,1 +Food and drinks outside the home,EUR_A_111,1,1,1 +Accommodation services,EUR_A_112,1,1,1 +Personal care,EUR_A_121,1,1,1 +Personal effects not previously declared,EUR_A_122,1,1,1 +Social protection,EUR_A_123,1,1,1 +Insurance services,EUR_A_124,1,1,1 +Financial services not declared elsewhere,EUR_A_125,1,1,1 +Other services not declared elsewhere,EUR_A_126_128,1,1,1 diff --git a/tests/testthat/test_medusa.R b/tests/testthat/test_medusa.R index 5fe64b1..acf805c 100644 --- a/tests/testthat/test_medusa.R +++ b/tests/testthat/test_medusa.R @@ -1,222 +1,222 @@ library(medusa) library(testthat) library(magrittr) -# -# test_that("Test1_Available basic variables", { -# test_result <- available_var_impact() -# test_expect <- c("QUINTILE", "DECILE", "VENTILE", "PERCENTILE", "REGION", -# "MUNISIZE", "ZONE", "HHTYPE", "CHILDREN", "POVERTY", -# "GENDERRP", "FEMDEGREE", "AGERP", "COUNTRYRP", "STUDIESRP", -# "PROFESSIONALSRP", "CONTTYPERP", "WORKDAYRP", "REGMR") -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test2_Available intersectional variables", { -# test_result <- available_var_intersec() -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# test_expect <- read.csv(file = paste0(path, "/is_categories.csv"), -# header = TRUE, -# sep = ",", -# dec = ".") -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test3_Example shocks", { -# setwd(file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs")) -# ex_shocks() -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") -# test_result <- read.csv(file = paste0(path, "/Example_shocks.csv"), -# header = TRUE, -# sep = ",", -# dec = ".") -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# test_expect <- read.csv(file = paste0(path, "/shocks.csv"), -# header = TRUE, -# sep = ",", -# dec = ".") -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test4_Example intersectional variables csv", { -# setwd(file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs")) -# ex_var_intersec() -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") -# test_result <- read.csv(file = paste0(path, "/Var_Intersec.csv"), -# header = TRUE, -# sep = ",", -# dec = ".") -# -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# test_expect <- read.csv(file = paste0(path, "/is_categories.csv"), -# header = TRUE, -# sep = ",", -# dec = ".") -# -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test5_Load raw hbs data", { -# y <- seq(2006,2021,1) -# -# db_path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# options(timeout = max(300, getOption("timeout"))) #increase downloading time -# rpackageutils::download_unpack_zip( -# data_directory = db_path, -# url = "https://zenodo.org/record/10654144/files/csv.zip?download=1") -# -# for (year in y){ -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/csv") -# epf_hh <- read.csv(file.path(path, paste0("/epf_", year, "_h.csv"))) -# test_expect <- round(sum(epf_hh$GASTOT/epf_hh$FACTOR, na.rm = TRUE)) -# -# load_rawhbs(year = year, path = file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/csv"), -# path_outputs = file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs")) -# load(file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs",paste0("/epf_list_", year, ".RData"))) -# epf_hg <- epf_list$epf_hg -# test_result <- round(sum(epf_hg$GASTOT/epf_hg$FACTOR, na.rm = TRUE)) -# -# testthat::expect_equal(test_result, test_expect) -# } -# }) -# -# -# test_that("Test6_Standardize & rename values", { -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# test_expect <- read.csv(file.path(path, "ex_dataset_renamed.csv")) -# -# epf_hh <- read.csv(file.path(path, "ex_dataset.csv")) -# test_result <- standardize(epf_hh) -# -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test7_Add coicop", { -# y <- seq(2006,2021,1) -# for (year in y){ -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/coicop") -# lists <- read.csv(file.path(path, paste0("coicop_", year, ".csv"))) -# for (r in colnames(lists)) { -# assign(r, lists %>% dplyr::filter(nchar(get(r))>0) %>% dplyr::pull(r)) -# } -# test_expect <- coicop -# -# hbs <- get(paste0("epf_list_", year)) -# epf_hg <- hbs$epf_hg -# epf_hg <- add_coicop(epf_hg, year) -# test_result <- epf_hg %>% dplyr:: select(starts_with("EUR_A_")) %>% colnames() -# testthat::expect_equal(test_result, test_expect) -# } -# }) -# -# -# test_that("Test8_Elevate_hbs population", { -# y <- seq(2006,2021,1) -# country <-"ES" -# for (year in y){ -# pop_NA <- restatapi::get_eurostat_data("demo_gind", -# filters = c("AVG", country), -# date_filter = year) -# pop_NA <- pop_NA$values -# test_expect <- round( pop_NA, digits = 0) -# -# hbs <- get(paste0("epf_list_", year)) -# epf_hg <- hbs$epf_hg -# epf_hg <- add_coicop(epf_hg, year) -# epf <- elevate_hbs(epf_hg, year) -# test_result <- round(sum(epf$POBLACIONCN), digits = 0) -# -# testthat::expect_equal(test_result, test_expect) -# } -# }) -# -# -# test_that("Test8_Elevate_hbs expenses", { -# y <- seq(2006,2021,1) -# country <-"ES" -# for (year in y){ -# -# macro <- gcfhogares95_22 %>% -# dplyr::select(COICOP, as.character(year[1])) %>% -# dplyr::rename('macro_ref' = as.character({{year}})) -# macro$macro_ref <- as.numeric(gsub(",","",macro$macro_ref)) -# gf_na <- macro %>% -# dplyr::filter(COICOP == "TOTAL") %>% -# dplyr::select(macro_ref) -# gf_na <- as.numeric(gf_na$macro_ref) -# test_expect <- gf_na * 1000000 -# -# hbs <- get(paste0("epf_list_", year)) -# epf_hg <- hbs$epf_hg -# epf_hg <- add_coicop(epf_hg, year) -# epf <- elevate_hbs(epf_hg, year) -# test_result <- round(sum(epf$GASTOT_CNR), digits = 0) -# -# testthat::expect_equal(test_result, test_expect) -# } -# }) -# -# -# test_that("Test9_Price_shock", { -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# epf <- read.csv(file.path(path, "ex_dataset_expenses.csv")) -# shocks <- read.csv(file.path(path, "shocks_ps.csv")) -# test_result <- price_shock(epf, shocks, 2006) -# -# test_expect <- read.csv(file.path(path, "ex_dataset_expenses_ps.csv")) -# -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test10_Impact", { -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# epf <- read.csv(file.path(path, "ex_dataset_expenses_ps.csv")) -# shocks <- read.csv(file.path(path, "shocks_ps.csv")) -# shocks_scenario_names <- names(shocks)[3:length(names(shocks))] -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") -# setwd(path) -# test_result <- impact(epf, shocks_scenario_names = shocks_scenario_names) -# -# test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/D_impacts.RData")) -# test_expect <- d_impacts -# -# testthat::expect_equal(test_result, test_expect) -# }) -# -# -# test_that("Test11_Basic graph", { -# vars <- c("AGERP", "COUNTRYRP", "GENDERRP", "HHTYPE", "MUNISIZE", "REGION", "REGMR", "STUDIESRP", "ZONE" ) -# for (g in vars) { -# test_result <- png::readPNG(file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/figures/DI_",g,".png"))) -# test_expect <- png::readPNG(file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_outputs/figures/DI_",g,".png"))) -# -# testthat::expect_equal(test_result, test_expect) -# } -# }) -# -# -# test_that("Test12_Impact Intersectional", { -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# epf <- read.csv(file.path(path, "ex_dataset_expenses_ps.csv")) -# shocks <- read.csv(file.path(path, "shocks_ps.csv")) -# shocks_scenario_names <- names(shocks)[3:length(names(shocks))] -# category_a <- c("AGERP", "GENDERRP", "COUNTRYRP", "ZONE", "REGION") -# category_b <- c("GENDERRP", "COUNTRYRP", "REGMR", "HHTYPE", "MUNISIZE") -# pairs <- data.frame(category_a, category_b) -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") -# setwd(path) -# test_result <- impact_intersectional(epf, pairs = pairs , shocks_scenario_names = shocks_scenario_names) -# -# test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/DI_impact.RData")) -# test_expect <- is_d_impacts -# -# testthat::expect_equal(test_result, test_expect) -# }) + +test_that("Test1_Available basic variables", { + test_result <- available_var_impact() + test_expect <- c("QUINTILE", "DECILE", "VENTILE", "PERCENTILE", "REGION", + "MUNISIZE", "ZONE", "HHTYPE", "CHILDREN", "POVERTY", + "GENDERRP", "FEMDEGREE", "AGERP", "COUNTRYRP", "STUDIESRP", + "PROFESSIONALSRP", "CONTTYPERP", "WORKDAYRP", "REGMR") + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test2_Available intersectional variables", { + test_result <- available_var_intersec() + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + test_expect <- read.csv(file = paste0(path, "/is_categories.csv"), + header = TRUE, + sep = ",", + dec = ".") + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test3_Example shocks", { + setwd(file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs")) + ex_shocks() + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + test_result <- read.csv(file = paste0(path, "/Example_shocks.csv"), + header = TRUE, + sep = ",", + dec = ".") + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + test_expect <- read.csv(file = paste0(path, "/shocks.csv"), + header = TRUE, + sep = ",", + dec = ".") + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test4_Example intersectional variables csv", { + setwd(file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs")) + ex_var_intersec() + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + test_result <- read.csv(file = paste0(path, "/Var_Intersec.csv"), + header = TRUE, + sep = ",", + dec = ".") + + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + test_expect <- read.csv(file = paste0(path, "/is_categories.csv"), + header = TRUE, + sep = ",", + dec = ".") + + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test5_Load raw hbs data", { + y <- seq(2006,2021,1) + + db_path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + options(timeout = max(300, getOption("timeout"))) #increase downloading time + rpackageutils::download_unpack_zip( + data_directory = db_path, + url = "https://zenodo.org/record/10654144/files/csv.zip?download=1") + + for (year in y){ + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/csv") + epf_hh <- read.csv(file.path(path, paste0("/epf_", year, "_h.csv"))) + test_expect <- round(sum(epf_hh$GASTOT/epf_hh$FACTOR, na.rm = TRUE)) + + load_rawhbs(year = year, path = file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/csv"), + path_outputs = file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs")) + load(file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs",paste0("/epf_list_", year, ".RData"))) + epf_hg <- epf_list$epf_hg + test_result <- round(sum(epf_hg$GASTOT/epf_hg$FACTOR, na.rm = TRUE)) + + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test6_Standardize & rename values", { + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + test_expect <- read.csv(file.path(path, "ex_dataset_renamed.csv")) + + epf_hh <- read.csv(file.path(path, "ex_dataset.csv")) + test_result <- standardize(epf_hh) + + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test7_Add coicop", { + y <- seq(2006,2021,1) + for (year in y){ + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/coicop") + lists <- read.csv(file.path(path, paste0("coicop_", year, ".csv"))) + for (r in colnames(lists)) { + assign(r, lists %>% dplyr::filter(nchar(get(r))>0) %>% dplyr::pull(r)) + } + test_expect <- coicop + + hbs <- get(paste0("epf_list_", year)) + epf_hg <- hbs$epf_hg + epf_hg <- add_coicop(epf_hg, year) + test_result <- epf_hg %>% dplyr:: select(starts_with("EUR_A_")) %>% colnames() + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test8_Elevate_hbs population", { + y <- seq(2006,2021,1) + country <-"ES" + for (year in y){ + pop_NA <- restatapi::get_eurostat_data("demo_gind", + filters = c("AVG", country), + date_filter = year) + pop_NA <- pop_NA$values + test_expect <- round( pop_NA, digits = 0) + + hbs <- get(paste0("epf_list_", year)) + epf_hg <- hbs$epf_hg + epf_hg <- add_coicop(epf_hg, year) + epf <- elevate_hbs(epf_hg, year) + test_result <- round(sum(epf$POBLACIONCN), digits = 0) + + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test8_Elevate_hbs expenses", { + y <- seq(2006,2021,1) + country <-"ES" + for (year in y){ + + macro <- gcfhogares95_22 %>% + dplyr::select(COICOP, as.character(year[1])) %>% + dplyr::rename('macro_ref' = as.character({{year}})) + macro$macro_ref <- as.numeric(gsub(",","",macro$macro_ref)) + gf_na <- macro %>% + dplyr::filter(COICOP == "TOTAL") %>% + dplyr::select(macro_ref) + gf_na <- as.numeric(gf_na$macro_ref) + test_expect <- gf_na * 1000000 + + hbs <- get(paste0("epf_list_", year)) + epf_hg <- hbs$epf_hg + epf_hg <- add_coicop(epf_hg, year) + epf <- elevate_hbs(epf_hg, year) + test_result <- round(sum(epf$GASTOT_CNR), digits = 0) + + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test9_Price_shock", { + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + epf <- read.csv(file.path(path, "ex_dataset_expenses.csv")) + shocks <- read.csv(file.path(path, "shocks_ps.csv")) + test_result <- price_shock(epf, shocks, 2006) + + test_expect <- read.csv(file.path(path, "ex_dataset_expenses_ps.csv")) + + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test10_Impact", { + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + epf <- read.csv(file.path(path, "ex_dataset_expenses_ps.csv")) + shocks <- read.csv(file.path(path, "shocks_ps.csv")) + shocks_scenario_names <- names(shocks)[3:length(names(shocks))] + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + setwd(path) + test_result <- impact(epf, shocks_scenario_names = shocks_scenario_names) + + test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/D_impacts.RData")) + test_expect <- d_impacts + + testthat::expect_equal(test_result, test_expect) +}) + + +test_that("Test11_Basic graph", { + vars <- c("AGERP", "COUNTRYRP", "GENDERRP", "HHTYPE", "MUNISIZE", "REGION", "REGMR", "STUDIESRP", "ZONE" ) + for (g in vars) { + test_result <- png::readPNG(file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/figures/DI_",g,".png"))) + test_expect <- png::readPNG(file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_outputs/figures/DI_",g,".png"))) + + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test12_Impact Intersectional", { + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + epf <- read.csv(file.path(path, "ex_dataset_expenses_ps.csv")) + shocks <- read.csv(file.path(path, "shocks_ps.csv")) + shocks_scenario_names <- names(shocks)[3:length(names(shocks))] + category_a <- c("AGERP", "GENDERRP", "COUNTRYRP", "ZONE", "REGION") + category_b <- c("GENDERRP", "COUNTRYRP", "REGMR", "HHTYPE", "MUNISIZE") + pairs <- data.frame(category_a, category_b) + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + setwd(path) + test_result <- impact_intersectional(epf, pairs = pairs , shocks_scenario_names = shocks_scenario_names) + + test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs/DI_impact.RData")) + test_expect <- is_d_impacts + + testthat::expect_equal(test_result, test_expect) +}) test_that("Test13_Calculate distributional impacts for all years (basic), no elevated", { @@ -235,32 +235,65 @@ test_that("Test13_Calculate distributional impacts for all years (basic), no ele test_expect <- d_impacts testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test14_Calculate distributional impacts for all years (basic), elevated", { + y <- seq(2006,2021,1) + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + shocks <- read.csv(file.path(path, "shocks_cdi.csv")) + + for (year in y){ + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + setwd(path) + calc_di(year = year, elevate = T, shocks = shocks, file_name_impact = paste0("D_impact_e_",year)) + test_result <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_outputs/outputs_di/D_impact_e_", year,".RData"))) + test_result <- d_impacts + + test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/D_impacts/D_impact_e_", year,".RData"))) + test_expect <- d_impacts + + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test15_Calculate distributional impacts for all years (intersectional), no elevated", { + y <- seq(2006,2021,1) + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + shocks <- read.csv(file.path(path, "shocks_cdii.csv")) + + for (year in y){ + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + setwd(path) + calc_di(year = year, shocks = shocks, var_impact = NULL, var_intersec = "all", file_name_intersec = paste0("DI_impact_",year), fig = F) + test_result <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_outputs/outputs_dii/DI_impact_", year,".RData"))) + test_result <- is_d_impacts - # vars <- categories$categories - # for (g in vars) { - # print(g) - # test_result <- png::readPNG(file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/figures/DI_",g,".png"))) - # test_expect <- png::readPNG(file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_outputs/figures/DI_",g,".png"))) - # - # testthat::expect_equal(test_result, test_expect) - # } + test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/DI_impacts/DI_impact_", year,".RData"))) + test_expect <- is_d_impacts + + testthat::expect_equal(test_result, test_expect) + } +}) + + +test_that("Test16_Calculate distributional impacts for all years (intersectional), no elevated", { + y <- seq(2006,2021,1) + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") + shocks <- read.csv(file.path(path, "shocks_cdii.csv")) + + for (year in y){ + path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") + setwd(path) + calc_di(year = year, elevate = T, shocks = shocks, var_impact = NULL, var_intersec = "all", file_name_intersec = paste0("DI_impact_e_",year), fig = F) + test_result <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_outputs/outputs_dii/DI_impact_e_", year,".RData"))) + test_result <- is_d_impacts + + test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/DI_impacts/DI_impact_e_", year,".RData"))) + test_expect <- is_d_impacts + + testthat::expect_equal(test_result, test_expect) } }) -# -# -# test_that("Test13_Calculate distributional impacts for all years (basic), elevated", { -# y <- seq(2006,2021,1) -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_inputs") -# shocks <- read.csv(file.path(path, "shocks_cdi.csv")) -# -# for (year in y){ -# path <- file.path(rprojroot::find_root(rprojroot::is_testthat), "test_outputs") -# setwd(path) -# calc_di(year = year, elevate = T, shocks = shocks, file_name_impact = paste0("D_impact_e_",year)) -# -# test_expect <- load(path <- file.path(rprojroot::find_root(rprojroot::is_testthat), paste0("test_inputs/DI_impact_e_", year,".RData"))) -# test_expect <- is_d_impacts -# -# testthat::expect_equal(test_result, test_expect) -# } -# })