diff --git a/tests/testthat/data/test_data_changed.csv b/tests/testthat/data/test_data_changed.csv index 4f37fdb..fe8246c 100644 --- a/tests/testthat/data/test_data_changed.csv +++ b/tests/testthat/data/test_data_changed.csv @@ -1,6 +1,6 @@ -ID;DECISION;author;title;Abstract -1;exclude;John Doe 2019;A beautiful paper;Lorem ipsum dolor sit mathematics, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit mathematics commodo magna eros quis urna. -2;exclude;John Doe and Jane Roe 2019;A very beautiful paper;Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. -3;include;John Doe and Jane Roe 2020;An enormously interesting paper;Aenean nec lorem. hello hello hello In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy. -4;include;Alan Mathison Turing;The chemical basis of morphogenesis;It is suggested that a system of chemical substances, called morphogens, reacting together and diffusing through a tissue, is adequate to for the main phenomena of morphogenesis. Such a system, although it may originally be quite homogeneous, may later develop a pattern or structure due to an instability of the homogeneous equilibrium, which is triggered off by random disturbances. Such reaction-diffusion systems are considered in some detail in the case of an isolated ring of cells, a mathematically convenient, though biologically unusual system. The investigation is chiefly concerned with the onset of instability. It is found that there are six essentially different forms which this may take. In the most interesting form stationary waves appear on the ring. It is suggested that this might , for instance, for the tentacle patterns on Hydra and for whorled leaves. A system of reactions and diffusion on a sphere is also considered. Such a system appears to for gastrulation. Another reaction system in two dimensions gives rise to patterns reminiscent of dappling. It is also suggested that stationary waves in two dimensions could for the phenomena of phyllotaxis. The purpose of this paper is to discuss a possible mechanism by which the genes of a zygote may determine the anatomical structure of the resulting organism. The theory does not make any new hypotheses, it merely suggests that certain well-known physical laws are sufficient to for many of the facts. The full understanding of the paper requires a good knowledge of mathematics, some biology, and some elementary chemistry. Since readers cannot be expected to be experts in all of these subjects, a number of elementary facts are explained, which can be found in text-books, but whose omission would make the paper difficult reading. -5;exclude;Author;A paper without abstract;NA +ID;author;title;Abstract +1;John Doe 2019;A beautiful paper;Lorem ipsum dolor sit mathematics, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit mathematics commodo magna eros quis urna. +2;John Doe and Jane Roe 2019;A very beautiful paper;Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. +3;John Doe and Jane Roe 2020;An enormously interesting paper;Aenean nec lorem. hello hello hello In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy. +4;Alan Mathison Turing;The chemical basis of morphogenesis;It is suggested that a system of chemical substances, called morphogens, reacting together and diffusing through a tissue, is adequate to for the main phenomena of morphogenesis. Such a system, although it may originally be quite homogeneous, may later develop a pattern or structure due to an instability of the homogeneous equilibrium, which is triggered off by random disturbances. Such reaction-diffusion systems are considered in some detail in the case of an isolated ring of cells, a mathematically convenient, though biologically unusual system. The investigation is chiefly concerned with the onset of instability. It is found that there are six essentially different forms which this may take. In the most interesting form stationary waves appear on the ring. It is suggested that this might , for instance, for the tentacle patterns on Hydra and for whorled leaves. A system of reactions and diffusion on a sphere is also considered. Such a system appears to for gastrulation. Another reaction system in two dimensions gives rise to patterns reminiscent of dappling. It is also suggested that stationary waves in two dimensions could for the phenomena of phyllotaxis. The purpose of this paper is to discuss a possible mechanism by which the genes of a zygote may determine the anatomical structure of the resulting organism. The theory does not make any new hypotheses, it merely suggests that certain well-known physical laws are sufficient to for many of the facts. The full understanding of the paper requires a good knowledge of mathematics, some biology, and some elementary chemistry. Since readers cannot be expected to be experts in all of these subjects, a number of elementary facts are explained, which can be found in text-books, but whose omission would make the paper difficult reading. +5;Author;A paper without abstract;NA diff --git a/tests/testthat/test_constructor.R b/tests/testthat/test_constructor.R index aa7973e..8fdaf2d 100644 --- a/tests/testthat/test_constructor.R +++ b/tests/testthat/test_constructor.R @@ -53,6 +53,17 @@ test_that("constructor works", { MetaNLP(csv), obj ) + # data frame can be created when column decision does not exist + source_path <- test_path("data", "test_data_changed.csv") + obj_no_dec <- MetaNLP(source_path) + + expect_true( + is.null(obj_no_dec@data_frame$decision_) + ) + expect_true( + !is.null(obj@data_frame$decision_) + ) + # throw an error if one column is missing csv1 <- csv[-1] csv2 <- csv[-4] diff --git a/tests/testthat/test_selection.R b/tests/testthat/test_selection.R index 983bd51..03b1591 100644 --- a/tests/testthat/test_selection.R +++ b/tests/testthat/test_selection.R @@ -46,7 +46,14 @@ test_that("Feature selection works", { all(temp) ) - # test 6: the optino "1se" leads to fewer columns than "min" + # test 6: is a seed is set, "lambda = avg" and "lambda = min" return the same results + + sel_feat_const_avg <- select_features(obj, lambda = "avg", seed = 42) + expect_equal( + sel_feat_const@data_frame, sel_feat_const_avg@data_frame + ) + + # test 7: the option "1se" leads to fewer columns than "min" sel_feat_1se <- select_features(obj, lambda = "1se", seed = 42) expect_lt( diff --git a/tests/testthat/test_writecsv.R b/tests/testthat/test_writecsv.R index 51e2bb6..0b4b0e8 100644 --- a/tests/testthat/test_writecsv.R +++ b/tests/testthat/test_writecsv.R @@ -3,27 +3,34 @@ test_that("write_csv works correctly", { source_path <- test_path("data", "test_data.csv") obj <- MetaNLP(source_path) - # test 1: default file name is correct + # test 1: when no path is specified, file is saved in working directory + write_csv(obj) + + expect_true( + file.exists("train_wcm.csv") + ) + + # test 2: default file name is correct write_csv(obj, path = test_path("data")) source_path2 <- test_path("data", "train_wcm.csv") expect_no_error( read.csv2(source_path2) ) - # test 2: file name can be changed + # test 3: file name can be changed write_csv(obj, path = test_path("data"), type = "test") source_path3 <- test_path("data", "test_wcm.csv") expect_no_error( read.csv2(source_path3) ) - # test 3: correct data frame is saved + # test 4: correct data frame is saved data_read <- data.frame(read.csv2(source_path3)) expect_true( all(obj@data_frame == data_read) ) - # test 4: default file name can be overwritten + # test 5: default file name can be overwritten source_path4 <- test_path("data", "written.csv") write_csv(obj, source_path4) @@ -31,6 +38,8 @@ test_that("write_csv works correctly", { read.csv2(source_path4) ) + # remove all the files + file.remove("train_wcm.csv") file.remove(source_path2) file.remove(source_path3) file.remove(source_path4)