-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ecnama
committed
Nov 30, 2024
1 parent
c85586f
commit 0b0a96f
Showing
10 changed files
with
277 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ Imports: | |
openxlsx, | ||
readODS | ||
Suggests: | ||
testthat (>= 3.0.0) | ||
testthat (>= 3.0.0), | ||
mockr | ||
Config/testthat/edition: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
read_file_output <- data.frame( | ||
"Nom complet" = c("Laurence Marchand", "Laurence ROZE", "Laurence Roze"), | ||
"Nom d’utilisateur" = c("[email protected]", "[email protected]", "[email protected]"), | ||
"Q01_Filiere" = c("1 : FC_FIRE (Filière classique ou filière internationale)", "2 : EMIR", "3 : MICA"), | ||
"Q02_Voeux->EII" = c(1, NA, NA), | ||
"Q02_Voeux->E&T" = c(2, NA, NA), | ||
"Q02_Voeux->INFO" = c(5, NA, NA), | ||
"Q02_Voeux->MA" = c(4, NA, NA), | ||
"Q02_Voeux->GCU" = c(3, NA, NA), | ||
"Q02_Voeux->GMA" = c(6, NA, NA), | ||
"Q02_Voeux->GPM" = c(7, NA, NA), | ||
"Q03_VoeuxEMIR->EII" = c(NA, 4, NA), | ||
"Q03_VoeuxEMIR->INFO" = c(NA, 3, NA), | ||
"Q03_VoeuxEMIR->GPM" = c(NA, 2, NA), | ||
"Q03_VoeuxEMIR->E&T" = c(NA, 1, NA), | ||
"Q04_voeuxMICA->GCU" = c(NA, NA, 4), | ||
"Q04_voeuxMICA->MA" = c(NA, NA, 1), | ||
"Q04_voeuxMICA->GMA" = c(NA, NA, 3), | ||
"Q04_voeuxMICA->INFO" = c(NA, NA, 2), | ||
check.names = FALSE | ||
) | ||
|
||
read_file_output_invalid <- data.frame( | ||
"Nom complet" = c("Laurence Marchand", "Laurence ROZE", "Laurence Roze"), | ||
"Nom d’utilisateur" = c("[email protected]", "[email protected]", "[email protected]"), | ||
"Q01_Filiere" = c("1 : FC_FIRE (Filière classique ou filière internationale)", "4 : Filière that doesn't exist", "3 : MICA"), | ||
"Q02_Voeux->EII" = c(1, NA, NA), | ||
"Q02_Voeux->E&T" = c(2, NA, NA), | ||
"Q02_Voeux->INFO" = c(5, NA, NA), | ||
"Q02_Voeux->MA" = c(4, NA, NA), | ||
"Q02_Voeux->GCU" = c(3, NA, NA), | ||
"Q02_Voeux->GMA" = c(6, NA, NA), | ||
"Q02_Voeux->GPM" = c(7, NA, NA), | ||
"Q03_VoeuxEMIR->EII" = c(NA, 4, NA), | ||
"Q03_VoeuxEMIR->INFO" = c(NA, 3, NA), | ||
"Q03_VoeuxEMIR->GPM" = c(NA, 2, NA), | ||
"Q03_VoeuxEMIR->E&T" = c(NA, 1, NA), | ||
"Q04_voeuxMICA->GCU" = c(NA, NA, 4), | ||
"Q04_voeuxMICA->MA" = c(NA, NA, 1), | ||
"Q04_voeuxMICA->GMA" = c(NA, NA, 3), | ||
"Q04_voeuxMICA->INFO" = c(NA, NA, 2), | ||
check.names = FALSE | ||
) | ||
|
||
synth_wishes_input_fc_fire <- data.frame( | ||
"Q01_Filiere" = "1 : FC_FIRE (Filière classique ou filière internationale)", | ||
"Q02_Voeux->EII" = 1, | ||
"Q02_Voeux->E&T" = 2, | ||
"Q02_Voeux->INFO" = 5, | ||
"Q02_Voeux->MA" = 4, | ||
"Q02_Voeux->GCU" = 3, | ||
"Q02_Voeux->GMA" = 6, | ||
"Q02_Voeux->GPM" = 7, | ||
"Q03_VoeuxEMIR->EII" = NA, | ||
"Q03_VoeuxEMIR->INFO" = NA, | ||
"Q03_VoeuxEMIR->GPM" = NA, | ||
"Q03_VoeuxEMIR->E&T" = NA, | ||
"Q04_voeuxMICA->GCU" = NA, | ||
"Q04_voeuxMICA->MA" = NA, | ||
"Q04_voeuxMICA->GMA" = NA, | ||
"Q04_voeuxMICA->INFO" = NA, | ||
check.names = FALSE | ||
) | ||
|
||
synth_wishes_output_fc_fire <- c( | ||
"FC_FIRE", | ||
"EII", | ||
"E&T", | ||
"GCU", | ||
"MA", | ||
"INFO", | ||
"GMA", | ||
"GPM" | ||
) | ||
|
||
synth_wishes_input_emir <- data.frame( | ||
"Q01_Filiere" = "2 : EMIR", | ||
"Q02_Voeux->EII" = NA, | ||
"Q02_Voeux->E&T" = NA, | ||
"Q02_Voeux->INFO" = NA, | ||
"Q02_Voeux->MA" = NA, | ||
"Q02_Voeux->GCU" = NA, | ||
"Q02_Voeux->GMA" = NA, | ||
"Q02_Voeux->GPM" = NA, | ||
"Q03_VoeuxEMIR->EII" = 4, | ||
"Q03_VoeuxEMIR->INFO" = 3, | ||
"Q03_VoeuxEMIR->GPM" = 2, | ||
"Q03_VoeuxEMIR->E&T" = 1, | ||
"Q04_voeuxMICA->GCU" = NA, | ||
"Q04_voeuxMICA->MA" = NA, | ||
"Q04_voeuxMICA->GMA" = NA, | ||
"Q04_voeuxMICA->INFO" = NA, | ||
check.names = FALSE | ||
) | ||
|
||
synth_wishes_output_emir <- c( | ||
"EMIR", | ||
"E&T", | ||
"GPM", | ||
"INFO", | ||
"EII" | ||
) | ||
|
||
synth_wishes_input_mica <- data.frame( | ||
"Q01_Filiere" = "3 : MICA", | ||
"Q02_Voeux->EII" = NA, | ||
"Q02_Voeux->E&T" = NA, | ||
"Q02_Voeux->INFO" = NA, | ||
"Q02_Voeux->MA" = NA, | ||
"Q02_Voeux->GCU" = NA, | ||
"Q02_Voeux->GMA" = NA, | ||
"Q02_Voeux->GPM" = NA, | ||
"Q03_VoeuxEMIR->EII" = NA, | ||
"Q03_VoeuxEMIR->INFO" = NA, | ||
"Q03_VoeuxEMIR->GPM" = NA, | ||
"Q03_VoeuxEMIR->E&T" = NA, | ||
"Q04_voeuxMICA->GCU" = 4, | ||
"Q04_voeuxMICA->MA" = 1, | ||
"Q04_voeuxMICA->GMA" = 3, | ||
"Q04_voeuxMICA->INFO" = 2, | ||
check.names = FALSE | ||
) | ||
|
||
synth_wishes_output_mica <- c( | ||
"MICA", | ||
"MA", | ||
"INFO", | ||
"GMA", | ||
"GCU" | ||
) | ||
|
||
synth_wishes_input_invalid <- data.frame( | ||
"Q01_Filiere" = "4 : Filière that doesn't exist", | ||
"Q02_Voeux->EII" = NA, | ||
"Q02_Voeux->E&T" = NA, | ||
"Q02_Voeux->INFO" = NA, | ||
"Q02_Voeux->MA" = NA, | ||
"Q02_Voeux->GCU" = NA, | ||
"Q02_Voeux->GMA" = NA, | ||
"Q02_Voeux->GPM" = NA, | ||
"Q03_VoeuxEMIR->EII" = NA, | ||
"Q03_VoeuxEMIR->INFO" = NA, | ||
"Q03_VoeuxEMIR->GPM" = NA, | ||
"Q03_VoeuxEMIR->E&T" = NA, | ||
"Q04_voeuxMICA->GCU" = 4, | ||
"Q04_voeuxMICA->MA" = 1, | ||
"Q04_voeuxMICA->GMA" = 3, | ||
"Q04_voeuxMICA->INFO" = 2, | ||
check.names = FALSE | ||
) | ||
|
||
parse_file_output <- data.frame( | ||
Nom = c("Marchand", "ROZE", "Roze"), | ||
Prenom = c("Laurence", "Laurence", "Laurence"), | ||
Filiere = c("FC_FIRE", "EMIR", "MICA"), | ||
V1 = c("EII", "E&T", "MA"), | ||
V2 = c("E&T", "GPM", "INFO"), | ||
V3 = c("GCU", "INFO", "GMA"), | ||
V4 = c("MA", "EII", "GCU"), | ||
V5 = c("INFO", NA_character_, NA_character_), | ||
V6 = c("GMA", NA_character_, NA_character_), | ||
V7 = c("GPM", NA_character_, NA_character_), | ||
Aff_V1_S1 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V1_S2 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V1_S3 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V2_S1 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V2_S2 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V2_S3 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V3_S1 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V3_S2 = c(NA_character_, NA_character_, NA_character_), | ||
Aff_V3_S3 = c(NA_character_, NA_character_, NA_character_) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Testing read_file | ||
|
||
test_that("read_file reads xlsx files correctly", { | ||
file_path <- "../data/test_file.xlsx" | ||
result <- read_file(file_path) | ||
expect_true(is.data.frame(result)) | ||
expect_equal(ncol(result), 18) | ||
expect_equal(result, read_file_output) | ||
}) | ||
|
||
test_that("read_file reads ods files correctly", { | ||
file_path <- "../data/test_file.ods" | ||
result <- read_file(file_path) | ||
expect_true(is.data.frame(result)) | ||
expect_equal(ncol(result), 18) | ||
expect_equal(result, read_file_output) | ||
}) | ||
|
||
test_that("read_file throws error for unsupported file types", { | ||
file_path <- "../data/test_file.csv" | ||
expect_error(read_file(file_path), "File type not supported") | ||
}) | ||
|
||
test_that("read_file throws error for non existing file", { | ||
file_path <- "../data/imaginary_file.xlsx" | ||
expect_error(read_file(file_path), "File does not exist") | ||
}) | ||
|
||
# Testing synthesize_wishes | ||
|
||
test_that("synthesize_wishes return correct result for FC_FIRE", { | ||
result <- synthesize_wishes(synth_wishes_input_fc_fire) | ||
expect_true(is.vector(result)) | ||
expect_equal(length(result), 8) | ||
expect_equal(result, synth_wishes_output_fc_fire) | ||
}) | ||
|
||
test_that("synthesize_wishes return correct result for EMIR", { | ||
result <- synthesize_wishes(synth_wishes_input_emir) | ||
expect_true(is.vector(result)) | ||
expect_equal(length(result), 5) | ||
expect_equal(result, synth_wishes_output_emir) | ||
}) | ||
|
||
test_that("synthesize_wishes return correct result for MICA", { | ||
result <- synthesize_wishes(synth_wishes_input_mica) | ||
expect_true(is.vector(result)) | ||
expect_equal(length(result), 5) | ||
expect_equal(result, synth_wishes_output_mica) | ||
}) | ||
|
||
test_that("synthesize_wishes throws error for non existing filière", { | ||
expect_error(synthesize_wishes(synth_wishes_input_invalid), "Unknown filiere") | ||
}) | ||
|
||
# Testing parse_file | ||
|
||
test_that("parse_file returns correct result for a valid input file", { | ||
local_mock(read_file = function(file_path) read_file_output) | ||
result <- parse_file("../data/test_file.xlsx") | ||
expect_equal(result, parse_file_output) | ||
}) | ||
|
||
test_that("parse_file throws error for invalid input file type", { | ||
local_mock(read_file = function(file_path) stop("File type not supported")) | ||
expect_error(parse_file("../data/test_file.csv"), "Error while reading the file : File type not supported") | ||
}) | ||
|
||
test_that("parse_file throws error for non existent file", { | ||
local_mock(read_file = function(file_path) stop("File does not exist")) | ||
expect_error(parse_file("../data/imaginary_file.xlsx"), "Error while reading the file : File does not exist") | ||
}) | ||
|
||
test_that("parse_file throws error for invalid data", { | ||
local_mock( | ||
read_file = function(file_path) read_file_output_invalid, | ||
synthesize_wishes = function(wishes) stop("Unknown filière") | ||
) | ||
expect_error(parse_file("../data/test_file.xlsx"), "Error while synthesizing the wishes \\(l\\.1\\): Unknown filière") | ||
}) |
Empty file.