From 6a23ffb67281d4051b71e25eee52dc27e3f7c576 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Wed, 25 Sep 2024 19:55:16 +0200 Subject: [PATCH] [TEST] Update tests --- test/api/count_test.cpp | 62 ++-- test/api/estimate_test.cpp | 238 ++++++---------- test/api/ibf_test.cpp | 159 ++++------- test/api/ibfmin_test.cpp | 115 +++----- test/api/insert_delete_test.cpp | 419 +++++++++++----------------- test/api/minimiser_test.cpp | 205 ++++++-------- test/app_test.hpp | 120 ++++++++ test/cli/count_options_test.cpp | 38 +-- test/cli/delete_options_test.cpp | 12 +- test/cli/estimate_options_test.cpp | 24 +- test/cli/ibf_options_test.cpp | 80 +++--- test/cli/insert_options_test.cpp | 16 +- test/cli/minimiser_options_test.cpp | 36 +-- test/cli/needle_options_test.cpp | 10 +- 14 files changed, 686 insertions(+), 848 deletions(-) create mode 100644 test/app_test.hpp diff --git a/test/api/count_test.cpp b/test/api/count_test.cpp index 3bde843..0b43380 100644 --- a/test/api/count_test.cpp +++ b/test/api/count_test.cpp @@ -5,33 +5,31 @@ #include "ibf.h" #include "shared.h" +#include "../app_test.hpp" -#ifndef DATA_INPUT_DIR -# define DATA_INPUT_DIR @DATA_INPUT_DIR@ -#endif - -using seqan3::operator""_shape; -std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory - -void initialization_args(estimate_ibf_arguments & args) +// To prevent issues when running multiple CLI tests in parallel, give each CLI test unique names: +struct count_test : public app_test { - args.compressed = true; - args.k = 4; - args.shape = seqan3::ungapped{args.k}; - args.w_size = seqan3::window_size{4}; - args.s = seqan3::seed{0}; - args.path_out = tmp_dir/"Count_Test_"; -} + void initialization_args(estimate_ibf_arguments & args) + { + args.compressed = true; + args.k = 4; + args.shape = seqan3::ungapped{args.k}; + args.w_size = seqan3::window_size{4}; + args.s = seqan3::seed{0}; + args.path_out = "Count_Test_"; + } +}; -TEST(count, small_example) +TEST_F(count_test, small_example) { estimate_ibf_arguments args{}; initialization_args(args); - count(args, {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}, std::string(DATA_INPUT_DIR) + "mini_gen.fasta", - std::string(DATA_INPUT_DIR) + "mini_gen.genome", false); + count(args, {data("mini_example.fasta")}, data("mini_gen.fasta"), + data("mini_gen.genome"), false); - std::ifstream output_file(tmp_dir/"mini_example.count.out"); + std::ifstream output_file("mini_example.count.out"); std::string line; std::string expected{"gen1\t3"}; if (output_file.is_open()) @@ -42,18 +40,17 @@ TEST(count, small_example) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Count_Test_mini_example.count.out"); } -TEST(count, small_example_paired) +TEST_F(count_test, small_example_paired) { estimate_ibf_arguments args{}; initialization_args(args); - count(args, {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}, - std::string(DATA_INPUT_DIR) + "mini_gen.fasta", std::string(DATA_INPUT_DIR) + "mini_gen.genome", true); + count(args, {data("mini_example.fasta"), data("mini_example.fasta")}, + data("mini_gen.fasta"), data("mini_gen.genome"), true); - std::ifstream output_file(tmp_dir/"mini_example.count.out"); + std::ifstream output_file("mini_example.count.out"); std::string line; std::string expected{"gen1\t6"}; if (output_file.is_open()) @@ -64,18 +61,17 @@ TEST(count, small_example_paired) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Count_Test_mini_example.count.out"); } -TEST(count, small_example_exclude) +TEST_F(count_test, small_example_exclude) { estimate_ibf_arguments args{}; initialization_args(args); - count(args, {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}, std::string(DATA_INPUT_DIR) + "mini_gen.fasta", - std::string(DATA_INPUT_DIR) + "mini_gen2.genome", false); + count(args, {data("mini_example.fasta")}, data("mini_gen.fasta"), + data("mini_gen2.genome"), false); - std::ifstream output_file(tmp_dir/"mini_example.count.out"); + std::ifstream output_file("mini_example.count.out"); std::string line; std::string expected{"gen1\t3"}; if (output_file.is_open()) @@ -86,19 +82,19 @@ TEST(count, small_example_exclude) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Count_Test_mini_example.count.out"); + } -TEST(genome, small_example) +TEST_F(count_test, genome_small_example) { estimate_ibf_arguments args{}; initialization_args(args); - count_genome(args, std::string(DATA_INPUT_DIR) + "mini_gen.fasta", std::string(DATA_INPUT_DIR) + "mini_gen2.fasta"); + count_genome(args, data("mini_gen.fasta"), data("mini_gen2.fasta")); std::ifstream output_file; uint64_t expected{192}; - output_file.open(tmp_dir/"mini_gen.genome", std::ios::binary); + output_file.open("mini_gen.genome", std::ios::binary); uint64_t minimiser; while(output_file.read((char*)&minimiser, sizeof(minimiser))) { diff --git a/test/api/estimate_test.cpp b/test/api/estimate_test.cpp index 2674eb6..d0441c6 100644 --- a/test/api/estimate_test.cpp +++ b/test/api/estimate_test.cpp @@ -6,42 +6,40 @@ #include "ibf.h" #include "shared.h" #include "estimate.h" +#include "../app_test.hpp" -#ifndef DATA_INPUT_DIR -# define DATA_INPUT_DIR @DATA_INPUT_DIR@ -#endif - -using seqan3::operator""_shape; - -void initialization_args(estimate_ibf_arguments & args) +// To prevent issues when running multiple CLI tests in parallel, give each CLI test unique names: +struct estimate_test : public app_test { - args.compressed = true; - args.k = 4; - args.shape = seqan3::ungapped{args.k}; - args.w_size = seqan3::window_size{4}; - args.s = seqan3::seed{0}; -} + void initialization_args(estimate_ibf_arguments & args) + { + args.compressed = true; + args.k = 4; + args.shape = seqan3::ungapped{args.k}; + args.w_size = seqan3::window_size{4}; + args.s = seqan3::seed{0}; + args.path_out = "Estimate_Test_"; + } +}; -TEST(estimate, small_example) +TEST_F(estimate_test, small_example) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"Estimate_Test_"; ibf_args.expression_thresholds = {1, 2, 4}; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; + std::vector sequence_files = {data("mini_example.fasta")}; + estimate_args.search_file = data("mini_gen.fasta"); estimate_args.path_in = ibf_args.path_out; std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - ibf_args.path_out = tmp_dir/"expression.out"; + ibf_args.path_out = "expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"expression.out"); + std::ifstream output_file("expression.out"); std::string line; std::string expected{"gen1\t3\t"}; if (output_file.is_open()) @@ -52,34 +50,27 @@ TEST(estimate, small_example) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_2"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_4"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"expression.out"); } -TEST(estimate, small_example_uncompressed) +TEST_F(estimate_test, small_example_uncompressed) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"Estimate_Test_"; ibf_args.compressed = false; ibf_args.expression_thresholds = {1, 2, 4}; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; + std::vector sequence_files = {data("mini_example.fasta")}; + estimate_args.search_file = data("mini_gen.fasta"); estimate_args.path_in = ibf_args.path_out; std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - ibf_args.path_out = tmp_dir/"expression.out"; + ibf_args.path_out = "expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"expression.out"); + std::ifstream output_file("expression.out"); std::string line; std::string expected{"gen1\t3\t"}; if (output_file.is_open()) @@ -90,34 +81,26 @@ TEST(estimate, small_example_uncompressed) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_1"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_2"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_4"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"expression.out"); } -TEST(estimate, small_example_gene_not_found) +TEST_F(estimate_test, small_example_gene_not_found) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"Estimate_Test_"; ibf_args.expression_thresholds = {2, 4}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "mini_gen2.fasta"; + estimate_args.search_file = data("mini_gen2.fasta"); estimate_args.path_in = ibf_args.path_out; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - ibf_args.path_out = tmp_dir/"expression.out"; + ibf_args.path_out = "expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"expression.out"); + std::ifstream output_file("expression.out"); std::string line; std::string expected{"gen2\t0\t"}; if (output_file.is_open()) @@ -128,38 +111,32 @@ TEST(estimate, small_example_gene_not_found) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_2"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_4"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"expression.out"); } -TEST(estimate, small_example_different_expressions_per_level) +TEST_F(estimate_test, small_example_different_expressions_per_level) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"Estimate_Test0_"; ibf_args.number_expression_thresholds = 2; std::vector fpr = {0.05}; std::vector cutoffs{}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; minimiser(sequence_files, ibf_args, minimiser_args, cutoffs); - std::vector minimiser_files{tmp_dir/"Estimate_Test0_mini_example.minimiser"}; + std::vector minimiser_files{"Estimate_Test_mini_example.minimiser"}; + ASSERT_TRUE(std::filesystem::exists(minimiser_files[0])); ibf_args.expression_thresholds= {}; ibf(minimiser_files, ibf_args, fpr); ibf_args.expression_thresholds = {0, 1, 2}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; + estimate_args.search_file = data("mini_gen.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"Test0_expression.out"; + ibf_args.path_out = "Test0_expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"Test0_expression.out"); + std::ifstream output_file("Test0_expression.out"); std::string line; std::string expected{"gen1\t3\t"}; if (output_file.is_open()) @@ -170,41 +147,33 @@ TEST(estimate, small_example_different_expressions_per_level) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test0_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"Estimate_Test0_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"Estimate_Test0_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"Estimate_Test0_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Estimate_Test0_IBF_Data"); - std::filesystem::remove(tmp_dir/"Test0_expression.out"); - std::filesystem::remove(tmp_dir/"Estimate_Test0_mini_example.minimiser"); } -TEST(estimate, small_example_different_expressions_per_level_normalization_1) +TEST_F(estimate_test, small_example_different_expressions_per_level_normalization_1) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; estimate_args.normalization_method = 1; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"Estimate_Test_"; ibf_args.number_expression_thresholds = 2; std::vector fpr = {0.05}; std::vector cutoffs{}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; minimiser(sequence_files, ibf_args, minimiser_args, cutoffs); - std::vector minimiser_files{tmp_dir/"Estimate_Test_mini_example.minimiser"}; + std::vector minimiser_files{"Estimate_Test_mini_example.minimiser"}; + ASSERT_TRUE(std::filesystem::exists(minimiser_files[0])); ibf_args.expression_thresholds= {}; ibf(minimiser_files, ibf_args, fpr); ibf_args.expression_thresholds = {0, 1, 2}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; + estimate_args.search_file = data("mini_gen.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"expression.out"; + ibf_args.path_out = "expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"expression.out"); + std::ifstream output_file("expression.out"); std::string line; std::string expected{"gen1\t1\t"}; if (output_file.is_open()) @@ -215,41 +184,34 @@ TEST(estimate, small_example_different_expressions_per_level_normalization_1) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"expression.out"); } -TEST(estimate, small_example_different_expressions_per_level_normalization_1_uncompressed) +TEST_F(estimate_test, small_example_different_expressions_per_level_normalization_1_uncompressed) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; estimate_args.normalization_method = 1; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"Estimate_Test2_"; ibf_args.number_expression_thresholds = 2; ibf_args.compressed = false; std::vector fpr = {0.05}; std::vector cutoffs{}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; minimiser(sequence_files, ibf_args, minimiser_args, cutoffs); - std::vector minimiser_files{tmp_dir/"Estimate_Test2_mini_example.minimiser"}; + std::vector minimiser_files{"Estimate_Test_mini_example.minimiser"}; + ASSERT_TRUE(std::filesystem::exists(minimiser_files[0])); ibf_args.expression_thresholds= {}; ibf(minimiser_files, ibf_args, fpr); ibf_args.expression_thresholds = {0, 1, 2}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; + estimate_args.search_file = data("mini_gen.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"Test2_expression.out"; + ibf_args.path_out = "Test2_expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"Test2_expression.out"); + std::ifstream output_file("Test2_expression.out"); std::string line; std::string expected{"gen1\t1\t"}; if (output_file.is_open()) @@ -260,38 +222,28 @@ TEST(estimate, small_example_different_expressions_per_level_normalization_1_unc } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test2_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"Estimate_Test2_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"Estimate_Test2_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"Estimate_Test2_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Estimate_Test2_IBF_Data"); - std::filesystem::remove(tmp_dir/"Test2_expression.out"); - std::filesystem::remove(tmp_dir/"Estimate_Test2_mini_example.minimiser"); } -TEST(estimate, example) +TEST_F(estimate_test, example) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; - ibf_args.path_out = tmp_dir/"Estimate_Test_"; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "exp_01.fasta", std::string(DATA_INPUT_DIR) + "exp_02.fasta", - std::string(DATA_INPUT_DIR) + "exp_11.fasta", std::string(DATA_INPUT_DIR) + "exp_12.fasta"}; + std::vector sequence_files = {data("exp_01.fasta"), data("exp_02.fasta"), + data("exp_11.fasta"), data("exp_12.fasta")}; minimiser_args.samples = {2, 2}; ibf_args.expression_thresholds = {4, 32}; - ibf_args.path_out = tmp_dir/"Estimate_Test_Single_"; ibf_args.compressed = false; std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "gene.fasta"; + estimate_args.search_file = data("gene.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"Single_expression.out"; + ibf_args.path_out = "Single_expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"Single_expression.out"); + std::ifstream output_file("Single_expression.out"); std::string line; std::string expected{"GeneA\t9\t32\t"}; if (output_file.is_open()) @@ -302,37 +254,29 @@ TEST(estimate, example) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_Single_IBF_4"); - std::filesystem::remove(tmp_dir/"Estimate_Test_Single_IBF_32"); - std::filesystem::remove(tmp_dir/"Estimate_Test_Single_IBF_Data"); - std::filesystem::remove(tmp_dir/"Estimate_Test_Single_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Single_expression.out"); } -TEST(estimate, example_multiple_threads) +TEST_F(estimate_test, example_multiple_threads) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; - ibf_args.path_out = tmp_dir/"Estimate_Test_"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "exp_01.fasta", std::string(DATA_INPUT_DIR) + "exp_02.fasta", - std::string(DATA_INPUT_DIR) + "exp_11.fasta", std::string(DATA_INPUT_DIR) + "exp_12.fasta"}; + std::vector sequence_files = {data("exp_01.fasta"), data("exp_02.fasta"), + data("exp_11.fasta"), data("exp_12.fasta")}; minimiser_args.samples = {2,2}; ibf_args.expression_thresholds = {4, 32}; std::vector fpr = {0.05}; - ibf_args.path_out = tmp_dir/"Estimate_Test_Multiple_"; ibf_args.compressed = false; std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); ibf_args.threads = 2; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "gene4.fasta"; + estimate_args.search_file = data("gene4.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"Multiple_expression.out"; + ibf_args.path_out = "Multiple_expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"Multiple_expression.out"); + std::ifstream output_file("Multiple_expression.out"); std::string line; std::string expected{"GeneA\t9\t32\t"}; if (output_file.is_open()) @@ -343,39 +287,33 @@ TEST(estimate, example_multiple_threads) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_Multiple_IBF_32"); - std::filesystem::remove(tmp_dir/"Estimate_Test_Multiple_IBF_4"); - std::filesystem::remove(tmp_dir/"Estimate_Test_Multiple_IBF_Data"); - std::filesystem::remove(tmp_dir/"Estimate_Test_Multiple_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Multiple_expression.out"); } -TEST(estimate, example_different_expressions_per_level) +TEST_F(estimate_test, example_different_expressions_per_level) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; - ibf_args.path_out = tmp_dir/"Estimate_Test_"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "exp_01.fasta", std::string(DATA_INPUT_DIR) + "exp_02.fasta", - std::string(DATA_INPUT_DIR) + "exp_11.fasta", std::string(DATA_INPUT_DIR) + "exp_12.fasta"}; + std::vector sequence_files = {data("exp_01.fasta"), data("exp_02.fasta"), + data("exp_11.fasta"), data("exp_12.fasta")}; std::vector cutoffs = {0, 0}; minimiser_args.samples = {2,2}; ibf_args.number_expression_thresholds = 4; std::vector fpr = {0.05}; - ibf_args.path_out = tmp_dir/"Estimate_Test_"; ibf_args.compressed = false; minimiser(sequence_files, ibf_args, minimiser_args, cutoffs); - std::vector minimiser_files{tmp_dir/"Estimate_Test_exp_01.minimiser", tmp_dir/"Estimate_Test_exp_11.minimiser"}; + std::vector minimiser_files{"exp_01.minimiser", "exp_11.minimiser"}; + ASSERT_TRUE(std::filesystem::exists(minimiser_files[0])); + ASSERT_TRUE(std::filesystem::exists(minimiser_files[1])); ibf(minimiser_files, ibf_args, fpr); ibf_args.expression_thresholds = {0, 1, 2}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "gene.fasta"; + estimate_args.search_file = data("gene.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"expression.out"; + ibf_args.path_out = "expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"expression.out"); + std::ifstream output_file("expression.out"); std::string line; // Count would expect 6 and 34 std::string expected{"GeneA\t7\t26\t"}; @@ -387,43 +325,35 @@ TEST(estimate, example_different_expressions_per_level) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_2"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"expression.out"); } -TEST(estimate, example_different_expressions_per_level_multiple_threads) +TEST_F(estimate_test, example_different_expressions_per_level_multiple_threads) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; estimate_arguments estimate_args{}; - ibf_args.path_out = tmp_dir/"Estimate_Test_"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "exp_01.fasta", std::string(DATA_INPUT_DIR) + "exp_02.fasta", - std::string(DATA_INPUT_DIR) + "exp_11.fasta", std::string(DATA_INPUT_DIR) + "exp_12.fasta"}; + std::vector sequence_files = {data("exp_01.fasta"), data("exp_02.fasta"), + data("exp_11.fasta"), data("exp_12.fasta")}; std::vector cutoffs = {0, 0}; minimiser_args.samples = {2,2}; ibf_args.number_expression_thresholds = 4; std::vector fpr = {0.05}; - ibf_args.path_out = tmp_dir/"Estimate_Test_"; ibf_args.compressed = false; minimiser(sequence_files, ibf_args, minimiser_args, cutoffs); - std::vector minimiser_files{tmp_dir/"Estimate_Test_exp_01.minimiser", tmp_dir/"Estimate_Test_exp_11.minimiser"}; + std::vector minimiser_files{"exp_01.minimiser", "exp_11.minimiser"}; + ASSERT_TRUE(std::filesystem::exists(minimiser_files[0])); + ASSERT_TRUE(std::filesystem::exists(minimiser_files[1])); ibf_args.expression_thresholds= {}; ibf(minimiser_files, ibf_args, fpr); ibf_args.threads = 2; ibf_args.expression_thresholds = {0, 1, 2}; - estimate_args.search_file = std::string(DATA_INPUT_DIR) + "gene4.fasta"; + estimate_args.search_file = data("gene4.fasta"); estimate_args.path_in = ibf_args.path_out; - ibf_args.path_out = tmp_dir/"expression.out"; + ibf_args.path_out = "expression.out"; call_estimate(ibf_args, estimate_args); - std::ifstream output_file(tmp_dir/"expression.out"); + std::ifstream output_file("expression.out"); std::string line; // Count would expect 6 and 34 std::string expected{"GeneA\t7\t26\t"}; @@ -435,14 +365,4 @@ TEST(estimate, example_different_expressions_per_level_multiple_threads) } output_file.close(); } - std::filesystem::remove(tmp_dir/"Estimate_Test_exp_01.minimiser"); - std::filesystem::remove(tmp_dir/"Estimate_Test_exp_11.minimiser"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_2"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Level_3"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Estimate_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"expression.out"); } diff --git a/test/api/ibf_test.cpp b/test/api/ibf_test.cpp index 3f8dab1..d5de94e 100644 --- a/test/api/ibf_test.cpp +++ b/test/api/ibf_test.cpp @@ -5,33 +5,30 @@ #include "ibf.h" #include "shared.h" +#include "../app_test.hpp" -#ifndef DATA_INPUT_DIR -# define DATA_INPUT_DIR @DATA_INPUT_DIR@ -#endif - -using seqan3::operator""_shape; - - -void initialization_args(estimate_ibf_arguments & args) +// To prevent issues when running multiple CLI tests in parallel, give each CLI test unique names: +struct ibf_test : public app_test { - args.compressed = true; - args.k = 4; - args.shape = seqan3::ungapped{args.k}; - args.w_size = seqan3::window_size{4}; - args.s = seqan3::seed{0}; -} + void initialization_args(estimate_ibf_arguments & args) + { + args.compressed = true; + args.k = 4; + args.shape = seqan3::ungapped{args.k}; + args.w_size = seqan3::window_size{4}; + args.s = seqan3::seed{0}; + } +}; -TEST(ibf, given_expression_thresholds) +TEST_F(ibf_test, given_expression_thresholds) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_Exp_"; + ibf_args.path_out = "IBF_Test_Exp_"; ibf_args.expression_thresholds = {1, 2}; minimiser_args.experiment_names = true; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{1, 2}; @@ -42,9 +39,9 @@ TEST(ibf, given_expression_thresholds) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Exp_IBF_1")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Exp_IBF_1")); { - load_ibf(ibf, tmp_dir/"IBF_Test_Exp_IBF_1"); + load_ibf(ibf, "IBF_Test_Exp_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -54,13 +51,11 @@ TEST(ibf, given_expression_thresholds) auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_Exp_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_Test_Exp_IBF_2"); - estimate_ibf_arguments args{}; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Exp_IBF_Data")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Exp_IBF_Data")); { - load_args(args, tmp_dir/"IBF_Test_Exp_IBF_Data"); + estimate_ibf_arguments args{}; + load_args(args, "IBF_Test_Exp_IBF_Data"); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); EXPECT_EQ(0, args.s.get()); @@ -70,21 +65,17 @@ TEST(ibf, given_expression_thresholds) EXPECT_RANGE_EQ(ibf_args.expression_thresholds, args.expression_thresholds); EXPECT_EQ(ibf_args.samplewise, args.samplewise); } - std::filesystem::remove(tmp_dir/"IBF_Test_Exp_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBF_Test_Exp_Stored_Files.txt"); - std::filesystem::remove(tmp_dir/"IBF_Test_Exp_IBF_FPRs.fprs"); } -TEST(ibf, given_expression_thresholds_include_file) +TEST_F(ibf_test, given_expression_thresholds_include_file) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_Include_"; + ibf_args.path_out = "IBF_Test_Include_"; ibf_args.expression_thresholds = {1, 2}; - minimiser_args.include_file = std::string(DATA_INPUT_DIR) + "mini_example.fasta"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + minimiser_args.include_file = data("mini_example.fasta"); + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{1, 2}; @@ -95,9 +86,9 @@ TEST(ibf, given_expression_thresholds_include_file) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Include_IBF_1")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Include_IBF_1")); { - load_ibf(ibf, tmp_dir/"IBF_Test_Include_IBF_1"); + load_ibf(ibf, "IBF_Test_Include_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -107,22 +98,17 @@ TEST(ibf, given_expression_thresholds_include_file) auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_Include_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_Test_Include_IBF_2"); - std::filesystem::remove(tmp_dir/"IBF_Test_Include_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBF_Test_Include_IBF_FPRs.fprs"); } -TEST(ibf, given_expression_thresholds_exclude_file) +TEST_F(ibf_test, given_expression_thresholds_exclude_file) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_Exclude_"; + ibf_args.path_out = "IBF_Test_Exclude_"; ibf_args.expression_thresholds = {1, 2}; - minimiser_args.exclude_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + minimiser_args.exclude_file = data("mini_gen.fasta"); + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{1, 2}; @@ -133,9 +119,9 @@ TEST(ibf, given_expression_thresholds_exclude_file) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Exclude_IBF_1")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Exclude_IBF_1")); { - load_ibf(ibf, tmp_dir/"IBF_Test_Exclude_IBF_1"); + load_ibf(ibf, "IBF_Test_Exclude_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -145,21 +131,16 @@ TEST(ibf, given_expression_thresholds_exclude_file) auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_Exclude_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_Test_Exclude_IBF_2"); - std::filesystem::remove(tmp_dir/"IBF_Test_Exclude_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBF_Test_Exclude_IBF_FPRs.fprs"); } -TEST(ibf, no_given_expression_thresholds) +TEST_F(ibf_test, no_given_expression_thresholds) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_"; + ibf_args.path_out = "IBF_Test_"; ibf_args.number_expression_thresholds = 2; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{}; @@ -171,9 +152,9 @@ TEST(ibf, no_given_expression_thresholds) seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_IBF_Level_0")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_IBF_Level_0")); { - load_ibf(ibf, tmp_dir/"IBF_Test_IBF_Level_0"); + load_ibf(ibf, "IBF_Test_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -183,37 +164,31 @@ TEST(ibf, no_given_expression_thresholds) auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_FPRs.fprs"); } -TEST(ibf, expression_thresholds_by_genome) +TEST_F(ibf_test, expression_thresholds_by_genome) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_"; + ibf_args.path_out = "IBF_Test_"; ibf_args.number_expression_thresholds = 1; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{}; std::vector cutoffs{}; std::vector medians = ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs, - std::string(DATA_INPUT_DIR) + "mini_gen.fasta"); + data("mini_gen.fasta")); EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_IBF_Level_0")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_IBF_Level_0")); { - load_ibf(ibf, tmp_dir/"IBF_Test_IBF_Level_0"); + load_ibf(ibf, "IBF_Test_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -223,21 +198,16 @@ TEST(ibf, expression_thresholds_by_genome) auto & res2 = agent.bulk_contains(192); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBF_Test_IBF_FPRs.fprs"); } -TEST(ibf, throws) +TEST_F(ibf_test, throws) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; std::vector cutoffs{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + ibf_args.path_out = "IBF_Test_"; + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; EXPECT_THROW(ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs), std::invalid_argument); @@ -253,16 +223,15 @@ TEST(ibf, throws) EXPECT_THROW(ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs), std::invalid_argument); } -TEST(ibf, given_cutoffs) +TEST_F(ibf_test, given_cutoffs) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_Cut_"; + ibf_args.path_out = "IBF_Test_Cut_"; ibf_args.expression_thresholds = {1, 2}; std::vector cutoffs = {0}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{1, 2}; @@ -272,9 +241,9 @@ TEST(ibf, given_cutoffs) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Cut_IBF_1")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Cut_IBF_1")); { - load_ibf(ibf, tmp_dir/"IBF_Test_Cut_IBF_1"); + load_ibf(ibf, "IBF_Test_Cut_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -284,13 +253,11 @@ TEST(ibf, given_cutoffs) auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_Cut_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_Test_Cut_IBF_2"); estimate_ibf_arguments args{}; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Cut_IBF_Data")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Cut_IBF_Data")); { - load_args(args, tmp_dir/"IBF_Test_Cut_IBF_Data"); + load_args(args, "IBF_Test_Cut_IBF_Data"); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); EXPECT_EQ(0, args.s.get()); @@ -300,19 +267,16 @@ TEST(ibf, given_cutoffs) EXPECT_RANGE_EQ(ibf_args.expression_thresholds, args.expression_thresholds); EXPECT_EQ(ibf_args.samplewise, args.samplewise); } - std::filesystem::remove(tmp_dir/"IBF_Test_Cut_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBF_Test_Cut_IBF_FPRs.fprs"); } -TEST(ibf, different_file_sizes) +TEST_F(ibf_test, different_file_sizes) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); - ibf_args.path_out = tmp_dir/"IBF_Test_Diff_"; + ibf_args.path_out = "IBF_Test_Diff_"; ibf_args.number_expression_thresholds = 4; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "exp_01.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), data("exp_01.fasta")}; std::vector fpr = {0.05}; std::vector expected{}; @@ -324,9 +288,9 @@ TEST(ibf, different_file_sizes) seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBF_Test_Diff_IBF_Level_0")) + ASSERT_TRUE(std::filesystem::exists("IBF_Test_Diff_IBF_Level_0")); { - load_ibf(ibf, tmp_dir/"IBF_Test_Diff_IBF_Level_0"); + load_ibf(ibf, "IBF_Test_Diff_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -337,11 +301,4 @@ TEST(ibf, different_file_sizes) auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_Level_2"); - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_Level_3"); - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBF_Test_Diff_IBF_Data"); } diff --git a/test/api/ibfmin_test.cpp b/test/api/ibfmin_test.cpp index 28d1252..020448e 100644 --- a/test/api/ibfmin_test.cpp +++ b/test/api/ibfmin_test.cpp @@ -5,32 +5,30 @@ #include "ibf.h" #include "shared.h" +#include "../app_test.hpp" -#ifndef DATA_INPUT_DIR -# define DATA_INPUT_DIR @DATA_INPUT_DIR@ -#endif - -using seqan3::operator""_shape; -std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory - -void initialization_args(estimate_ibf_arguments & args) +// To prevent issues when running multiple CLI tests in parallel, give each CLI test unique names: +struct ibfmin_test : public app_test { - args.compressed = true; - args.k = 4; - args.shape = seqan3::ungapped{args.k}; - args.w_size = seqan3::window_size{4}; - args.s = seqan3::seed{0}; - args.path_out = tmp_dir/"IBFMIN_Test_"; -} + void initialization_args(estimate_ibf_arguments & args) + { + args.compressed = true; + args.k = 4; + args.shape = seqan3::ungapped{args.k}; + args.w_size = seqan3::window_size{4}; + args.s = seqan3::seed{0}; + args.path_out = "IBFMIN_Test_"; + } +}; -TEST(ibfmin, given_expression_thresholds) +TEST_F(ibfmin_test, given_expression_thresholds) { estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.expression_thresholds = {1, 2}; std::vector fpr = {0.05, 0.05}; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Given_"; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + ibf_args.path_out = "IBFMIN_Test_Given_"; + std::vector minimiser_file = {data("mini_example.minimiser")}; std::vector expected{1, 2}; @@ -39,9 +37,9 @@ TEST(ibfmin, given_expression_thresholds) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBFMIN_Test_Given_IBF_1")) + ASSERT_TRUE(std::filesystem::exists("IBFMIN_Test_Given_IBF_1")); { - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_1"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -52,23 +50,18 @@ TEST(ibfmin, given_expression_thresholds) EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); } -#if defined(__GNUC__) && ((__GNUC___ == 10 && __cplusplus == 201703L) || (__GNUC__ <10)) -TEST(ibfmin, given_expression_thresholds_multiple_threads) +TEST_F(ibfmin_test, given_expression_thresholds_multiple_threads) { estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.expression_thresholds = {1, 2}; std::vector fpr = {0.05, 0.05}; ibf_args.threads = 2; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Multiple_"; + ibf_args.path_out = "IBFMIN_Test_Multiple_"; std::vector minimiser_file{}; - minimiser_file.assign(16, std::string(DATA_INPUT_DIR) + "mini_example.minimiser"); + minimiser_file.assign(16, data("mini_example.minimiser")); std::vector expected{1, 2}; @@ -77,7 +70,7 @@ TEST(ibfmin, given_expression_thresholds_multiple_threads) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Multiple_IBF_1"); + load_ibf(ibf, "IBFMIN_Test_Multiple_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(16, 0); @@ -86,20 +79,15 @@ TEST(ibfmin, given_expression_thresholds_multiple_threads) std::vector expected_result2(16, 1); auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result2, res2); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_FPRs.fprs"); } -#endif -TEST(ibfmin, no_given_expression_thresholds) +TEST_F(ibfmin_test, no_given_expression_thresholds) { estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.number_expression_thresholds = 2; std::vector fpr = {0.0025, 0.0025}; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file = {data("mini_example.minimiser")}; std::vector expected{}; @@ -107,10 +95,10 @@ TEST(ibfmin, no_given_expression_thresholds) EXPECT_EQ(expected, medians); - if (std::filesystem::exists(tmp_dir/"IBFMIN_Test_IBF_Level_0")) + ASSERT_TRUE(std::filesystem::exists("IBFMIN_Test_IBF_Level_0")); { seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_IBF_Level_0"); + load_ibf(ibf, "IBFMIN_Test_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -121,31 +109,26 @@ TEST(ibfmin, no_given_expression_thresholds) EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_FPRs.fprs"); } -TEST(ibfmin, expression_thresholds_by_genome) +TEST_F(ibfmin_test, expression_thresholds_by_genome) { estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.number_expression_thresholds = 1; std::vector fpr = {0.05}; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file = {data("mini_example.minimiser")}; std::vector expected{}; - std::vector medians = ibf(minimiser_file, ibf_args, fpr, std::string(DATA_INPUT_DIR) + "mini_gen.fasta"); + std::vector medians = ibf(minimiser_file, ibf_args, fpr, data("mini_gen.fasta")); EXPECT_EQ(expected, medians); - if (std::filesystem::exists(tmp_dir/"IBFMIN_Test_IBF_Level_0")) + ASSERT_TRUE(std::filesystem::exists("IBFMIN_Test_IBF_Level_0")); { seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_IBF_Level_0"); + load_ibf(ibf, "IBFMIN_Test_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -156,23 +139,18 @@ TEST(ibfmin, expression_thresholds_by_genome) EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_IBF_FPRs.fprs"); } -#if defined(__GNUC__) && ((__GNUC___ == 10 && __cplusplus == 201703L) || (__GNUC__ <10)) -TEST(ibfmin, no_given_expression_thresholds_multiple_threads) +TEST_F(ibfmin_test, no_given_expression_thresholds_multiple_threads) { estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.number_expression_thresholds = 2; std::vector fpr = {0.0025, 0.0025}; ibf_args.threads = 2; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Multiple_"; + ibf_args.path_out = "IBFMIN_Test_Multiple_"; std::vector minimiser_file{}; - minimiser_file.assign(128, std::string(DATA_INPUT_DIR) + "mini_example.minimiser"); + minimiser_file.assign(128, data("mini_example.minimiser")); std::vector expected{}; @@ -181,7 +159,7 @@ TEST(ibfmin, no_given_expression_thresholds_multiple_threads) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Multiple_IBF_Level_0"); + load_ibf(ibf, "IBFMIN_Test_Multiple_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(128, 0); @@ -190,15 +168,9 @@ TEST(ibfmin, no_given_expression_thresholds_multiple_threads) std::vector expected_result2(128, 1); auto & res2 = agent.bulk_contains(24); EXPECT_RANGE_EQ(expected_result2, res2); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Multiple_IBF_FPRs.fprs"); } -#endif -TEST(ibfmin, different_shape) +TEST_F(ibfmin_test, different_shape) { estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; @@ -207,10 +179,10 @@ TEST(ibfmin, different_shape) ibf_args.shape = seqan3::bin_literal{11}; ibf_args.expression_thresholds = {1, 2}; std::vector fpr = {0.05, 0.05}; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Shape_"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + ibf_args.path_out = "IBFMIN_Test_Shape_"; + std::vector sequence_files = {data("mini_example.fasta")}; minimiser(sequence_files, ibf_args, minimiser_args, cutoffs); - std::vector minimiser_file = {tmp_dir/"IBFMIN_Test_Shape_mini_example.minimiser"}; + std::vector minimiser_file = {"IBFMIN_Test_Shape_mini_example.minimiser"}; std::vector expected{1, 2}; @@ -219,9 +191,9 @@ TEST(ibfmin, different_shape) EXPECT_EQ(expected, medians); seqan3::interleaved_bloom_filter ibf; - if (std::filesystem::exists(tmp_dir/"IBFMIN_Test_Shape_IBF_1")) + ASSERT_TRUE(std::filesystem::exists("IBFMIN_Test_Shape_IBF_1")); { - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Shape_IBF_1"); + load_ibf(ibf, "IBFMIN_Test_Shape_IBF_1"); auto agent = ibf.membership_agent(); std::vector expected_result(1, 0); @@ -232,9 +204,4 @@ TEST(ibfmin, different_shape) EXPECT_RANGE_EQ(expected_result, res2); } - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Shape_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Shape_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Shape_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Shape_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/("IBFMIN_Test_Shape_mini_example.minimiser")); } diff --git a/test/api/insert_delete_test.cpp b/test/api/insert_delete_test.cpp index d8ca97c..3c68b56 100644 --- a/test/api/insert_delete_test.cpp +++ b/test/api/insert_delete_test.cpp @@ -5,25 +5,65 @@ #include "ibf.h" #include "shared.h" +#include "../app_test.hpp" -#ifndef DATA_INPUT_DIR -# define DATA_INPUT_DIR @DATA_INPUT_DIR@ -#endif - -using seqan3::operator""_shape; - -void initialization_args(estimate_ibf_arguments & args) +// To prevent issues when running multiple CLI tests in parallel, give each CLI test unique names: +struct delete_test : public app_test { - args.compressed = true; - args.k = 4; - args.shape = seqan3::ungapped{args.k}; - args.w_size = seqan3::window_size{4}; - args.s = seqan3::seed{0}; -} + void initialization_args(estimate_ibf_arguments & args) + { + args.compressed = true; + args.k = 4; + args.shape = seqan3::ungapped{args.k}; + args.w_size = seqan3::window_size{4}; + args.s = seqan3::seed{0}; + } +}; + +struct insert_test : public delete_test +{ + // Reads the level file ibf creates + template + void read_levels(std::vector> & expressions, std::filesystem::path filename) + { + ASSERT_TRUE(std::filesystem::exists(filename)) << filename; + std::ifstream fin{filename}; + auto stream_view = seqan3::detail::istreambuf(fin); + auto stream_it = std::ranges::begin(stream_view); + size_t j{0}; + std::vector empty_vector{}; + + std::string buffer{}; -TEST(delete, no_given_thresholds) + // Read line = expression levels + do + { + if (j == expressions.size()) + expressions.push_back(empty_vector); + std::ranges::copy(stream_view | seqan3::detail::take_until_or_throw(seqan3::is_char<' '>), + std::back_inserter(buffer)); + if constexpr(std::same_as) + expressions[j].push_back((uint16_t) std::stoi(buffer)); + else + expressions[j].push_back((double) std::stod(buffer)); + buffer.clear(); + if(*stream_it != '/') + ++stream_it; + + if (*stream_it == '\n') + { + ++stream_it; + j++; + } + } while (*stream_it != '/'); + ++stream_it; + + fin.close(); + } +}; + +TEST_F(delete_test, no_given_thresholds) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory std::vector fpr = {0.05}; std::vector cutoffs_delete{0,0}; estimate_ibf_arguments ibf_args_delete{}; @@ -32,84 +72,40 @@ TEST(delete, no_given_thresholds) ibf_args_delete.compressed = false; ibf_args_delete.number_expression_thresholds = 2; minimiser_args_delete.experiment_names = false; - ibf_args_delete.path_out = tmp_dir/"IBF_delete_Exp_"; - std::vector sequence_files_delete = {std::string(DATA_INPUT_DIR) + "mini_example.fasta",std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + ibf_args_delete.path_out = "IBF_delete_Exp_"; + std::vector sequence_files_delete = {data("mini_example.fasta"),data("mini_example.fasta")}; ibf(sequence_files_delete, ibf_args_delete, minimiser_args_delete, fpr, cutoffs_delete); seqan3::interleaved_bloom_filter ibf{}; - load_ibf(ibf, tmp_dir/"IBF_delete_Exp_IBF_Level_0"); + load_ibf(ibf, "IBF_delete_Exp_IBF_Level_0"); seqan3::interleaved_bloom_filter ibf_0{seqan3::bin_count{2u}, seqan3::bin_size{ibf.bin_size()}, seqan3::hash_function_count{1u}}; - load_ibf(ibf, tmp_dir/"IBF_delete_Exp_IBF_Level_1"); + load_ibf(ibf, "IBF_delete_Exp_IBF_Level_1"); seqan3::interleaved_bloom_filter ibf_1{seqan3::bin_count{2u}, seqan3::bin_size{ibf.bin_size()}, seqan3::hash_function_count{1u}}; - delete_bin({0,1}, ibf_args_delete, tmp_dir/"IBF_delete_Exp_", true); + delete_bin({0,1}, ibf_args_delete, "IBF_delete_Exp_", true); seqan3::interleaved_bloom_filter ibf_delete{}; - load_ibf(ibf_delete, tmp_dir/"IBF_delete_Exp_IBF_Level_0"); + load_ibf(ibf_delete, "IBF_delete_Exp_IBF_Level_0"); EXPECT_TRUE((ibf_0 == ibf_delete)); - load_ibf(ibf_delete, tmp_dir/"IBF_delete_Exp_IBF_Level_1"); + load_ibf(ibf_delete, "IBF_delete_Exp_IBF_Level_1"); EXPECT_TRUE((ibf_1 == ibf_delete)); - - std::filesystem::remove(tmp_dir/"IBF_delete_Exp_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_delete_Exp_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBF_delete_Exp_IBF_Deleted"); } -// Reads the level file ibf creates -template -void read_levels(std::vector> & expressions, std::filesystem::path filename) +TEST_F(insert_test, ibf) { - std::ifstream fin; - fin.open(filename); - auto stream_view = seqan3::detail::istreambuf(fin); - auto stream_it = std::ranges::begin(stream_view); - int j{0}; - std::vector empty_vector{}; - - std::string buffer{}; - - // Read line = expression levels - do - { - if (j == expressions.size()) - expressions.push_back(empty_vector); - std::ranges::copy(stream_view | seqan3::detail::take_until_or_throw(seqan3::is_char<' '>), - std::back_inserter(buffer)); - if constexpr(std::same_as) - expressions[j].push_back((uint16_t) std::stoi(buffer)); - else - expressions[j].push_back((double) std::stod(buffer)); - buffer.clear(); - if(*stream_it != '/') - ++stream_it; - - if (*stream_it == '\n') - { - ++stream_it; - j++; - } - } while (*stream_it != '/'); - ++stream_it; - - fin.close(); -} - -TEST(insert, ibf) -{ - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); ibf_args.compressed = false; - ibf_args.path_out = tmp_dir/"IBF_True_Exp_"; + ibf_args.path_out = "IBF_True_Exp_"; ibf_args.expression_thresholds = {1, 2}; minimiser_args.experiment_names = false; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector cutoffs{0,0}; @@ -120,51 +116,43 @@ TEST(insert, ibf) minimiser_arguments minimiser_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.compressed = false; - ibf_args_insert.path_out = tmp_dir/"IBF_True_Exp_"; + ibf_args_insert.path_out = "IBF_True_Exp_"; ibf_args_insert.expression_thresholds = {1, 2}; minimiser_args_insert.experiment_names = false; - ibf_args_insert.path_out = tmp_dir/"IBF_Insert_Exp_"; - std::vector sequence_files_insert = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + ibf_args_insert.path_out = "IBF_Insert_Exp_"; + std::vector sequence_files_insert = {data("mini_example.fasta")}; ibf(sequence_files_insert, ibf_args_insert, minimiser_args_insert, fpr, cutoffs_insert); - insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", tmp_dir/"IBF_Insert_Exp_", false); + insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", "IBF_Insert_Exp_", false); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_1"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_1"); + load_ibf(ibf, "IBF_True_Exp_IBF_1"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_1"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_2"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_2"); + load_ibf(ibf, "IBF_True_Exp_IBF_2"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_2"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBF_True_Exp_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBF_Insert_Exp_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_2"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_2"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); } -TEST(insert, ibf_no_given_thresholds) +TEST_F(insert_test, ibf_no_given_thresholds) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); ibf_args.compressed = false; - ibf_args.path_out = tmp_dir/"IBF_True_Exp_"; + ibf_args.path_out = "IBF_True_Exp_"; ibf_args.number_expression_thresholds = 2; minimiser_args.experiment_names = false; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), data("mini_example.fasta")}; std::vector fpr = {0.05}; std::vector expected{}; @@ -179,50 +167,44 @@ TEST(insert, ibf_no_given_thresholds) ibf_args_insert.compressed = false; ibf_args_insert.number_expression_thresholds = 2; minimiser_args_insert.experiment_names = false; - ibf_args_insert.path_out = tmp_dir/"IBF_Insert_Exp_"; - std::vector sequence_files_insert = {std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + ibf_args_insert.path_out = "IBF_Insert_Exp_"; + std::vector sequence_files_insert = {data("mini_example.fasta")}; std::vector medians_insert = ibf(sequence_files_insert, ibf_args_insert, minimiser_args_insert, fpr, cutoffs_insert); - insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", tmp_dir/"IBF_Insert_Exp_", true); + insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", "IBF_Insert_Exp_", true); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_Level_0"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_Level_0"); + load_ibf(ibf, "IBF_True_Exp_IBF_Level_0"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_Level_0"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_Level_1"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_Level_1"); + load_ibf(ibf, "IBF_True_Exp_IBF_Level_1"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_Level_1"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> expressions_ibf{}; - read_levels(expressions_ibf, tmp_dir/"IBF_True_Exp_IBF_Levels.levels"); + read_levels(expressions_ibf, "IBF_True_Exp_IBF_Levels.levels"); std::vector> expressions_insert{}; - read_levels(expressions_insert, tmp_dir/"IBF_Insert_Exp_IBF_Levels.levels"); + read_levels(expressions_insert, "IBF_Insert_Exp_IBF_Levels.levels"); EXPECT_EQ(expressions_ibf,expressions_insert); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBF_True_Exp_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBF_Insert_Exp_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Level_1"); } -TEST(insert, ibf_delete) +TEST_F(insert_test, ibf_delete) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); ibf_args.compressed = false; - ibf_args.path_out = tmp_dir/"IBF_True_Exp_"; + ibf_args.path_out = "IBF_True_Exp_"; ibf_args.expression_thresholds = {1, 2}; minimiser_args.experiment_names = false; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example2.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), data("mini_example2.fasta"), data("mini_example.fasta")}; std::vector fpr = {0.05,0.05}; std::vector cutoffs{0,0,0}; @@ -233,54 +215,45 @@ TEST(insert, ibf_delete) minimiser_arguments minimiser_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.compressed = false; - ibf_args_insert.path_out = tmp_dir/"IBF_Insert_Exp_"; + ibf_args_insert.path_out = "IBF_Insert_Exp_"; ibf_args_insert.expression_thresholds = {1, 2}; minimiser_args_insert.experiment_names = false; - std::vector sequence_files_insert = {std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; - std::vector sequence_files_test = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example2.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files_insert = {data("mini_example2.fasta")}; + std::vector sequence_files_test = {data("mini_example.fasta"), data("mini_example2.fasta"), data("mini_example.fasta")}; ibf(sequence_files_test, ibf_args_insert, minimiser_args, fpr, cutoffs); delete_bin({1}, ibf_args_insert, ibf_args_insert.path_out, false); - insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", tmp_dir/"IBF_Insert_Exp_", false); + insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", "IBF_Insert_Exp_", false); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_1"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_1"); + load_ibf(ibf, "IBF_True_Exp_IBF_1"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_1"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_2"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_2"); + load_ibf(ibf, "IBF_True_Exp_IBF_2"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_2"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBF_True_Exp_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBF_Insert_Exp_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_2"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_1"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_2"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Deleted"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); } -TEST(insert, ibf_delete_no_given_threshold) +TEST_F(insert_test, ibf_delete_no_given_threshold) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; minimiser_arguments minimiser_args{}; initialization_args(ibf_args); ibf_args.compressed = false; - ibf_args.path_out = tmp_dir/"IBF_True_Exp_"; + ibf_args.path_out = "IBF_True_Exp_"; ibf_args.number_expression_thresholds = 2; minimiser_args.experiment_names = false; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example2.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), data("mini_example2.fasta"), data("mini_example.fasta")}; std::vector fpr = {0.05,0.05}; std::vector cutoffs{0,0,0}; @@ -291,261 +264,207 @@ TEST(insert, ibf_delete_no_given_threshold) minimiser_arguments minimiser_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.compressed = false; - ibf_args_insert.path_out = tmp_dir/"IBF_Insert_Exp_"; + ibf_args_insert.path_out = "IBF_Insert_Exp_"; ibf_args_insert.number_expression_thresholds = 2; minimiser_args_insert.experiment_names = false; - std::vector sequence_files_insert = {std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; - std::vector sequence_files_test = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", std::string(DATA_INPUT_DIR) + "mini_example2.fasta", std::string(DATA_INPUT_DIR) + "mini_example.fasta"}; + std::vector sequence_files_insert = {data("mini_example2.fasta")}; + std::vector sequence_files_test = {data("mini_example.fasta"), data("mini_example2.fasta"), data("mini_example.fasta")}; ibf(sequence_files_test, ibf_args_insert, minimiser_args, fpr, cutoffs); delete_bin({1}, ibf_args_insert, ibf_args_insert.path_out, true); - insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", tmp_dir/"IBF_Insert_Exp_", true); + insert(sequence_files_insert, ibf_args_insert, minimiser_args_insert, cutoffs_insert, "", "IBF_Insert_Exp_", true); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_Level_0"); + load_ibf(ibf, "IBF_True_Exp_IBF_Level_0"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_Level_0"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_Level_0"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBF_True_Exp_IBF_Level_1"); - load_ibf(ibf_insert, tmp_dir/"IBF_Insert_Exp_IBF_Level_1"); + load_ibf(ibf, "IBF_True_Exp_IBF_Level_1"); + load_ibf(ibf_insert, "IBF_Insert_Exp_IBF_Level_1"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> expressions_ibf{}; - read_levels(expressions_ibf, tmp_dir/"IBF_True_Exp_IBF_Levels.levels"); + read_levels(expressions_ibf, "IBF_True_Exp_IBF_Levels.levels"); std::vector> expressions_insert{}; - read_levels(expressions_insert, tmp_dir/"IBF_Insert_Exp_IBF_Levels.levels"); + read_levels(expressions_insert, "IBF_Insert_Exp_IBF_Levels.levels"); EXPECT_EQ(expressions_ibf,expressions_insert); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBF_True_Exp_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBF_Insert_Exp_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBF_True_Exp_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Deleted"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBF_Insert_Exp_IBF_FPRs.fprs"); } -TEST(insert, ibfmin) +TEST_F(insert_test, ibfmin) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.expression_thresholds = {1, 2}; std::vector fpr = {0.05, 0.05}; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Given_"; + ibf_args.path_out = "IBFMIN_Test_Given_"; ibf_args.compressed = false; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser", std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file = {data("mini_example.minimiser"), data("mini_example.minimiser")}; ibf(minimiser_file, ibf_args, fpr); estimate_ibf_arguments ibf_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.expression_thresholds = {1, 2}; - ibf_args_insert.path_out = tmp_dir/"IBFMIN_Insert_Given_"; + ibf_args_insert.path_out = "IBFMIN_Insert_Given_"; ibf_args_insert.compressed = false; - std::vector minimiser_file_insert = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file_insert = {data("mini_example.minimiser")}; ibf(minimiser_file_insert, ibf_args_insert, fpr); - insert(minimiser_file_insert, ibf_args_insert, "", tmp_dir/"IBFMIN_Insert_Given_", false); + insert(minimiser_file_insert, ibf_args_insert, "", "IBFMIN_Insert_Given_", false); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_1"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_1"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_1"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_IBF_1"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_2"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_2"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_2"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_IBF_2"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBFMIN_Test_Given_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBFMIN_Insert_Given_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Test_Given_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_FPRs.fprs"); } -TEST(insert, ibfmin_delete) +TEST_F(insert_test, ibfmin_delete) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.expression_thresholds = {1, 2}; std::vector fpr = {0.05, 0.05}; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Given_"; + ibf_args.path_out = "IBFMIN_Test_Given_"; ibf_args.compressed = false; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser", std::string(DATA_INPUT_DIR) + "mini_example.minimiser", std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file = {data("mini_example.minimiser"), data("mini_example.minimiser"), data("mini_example.minimiser")}; ibf(minimiser_file, ibf_args, fpr); estimate_ibf_arguments ibf_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.expression_thresholds = {1, 2}; - ibf_args_insert.path_out = tmp_dir/"IBFMIN_Insert_Given_"; + ibf_args_insert.path_out = "IBFMIN_Insert_Given_"; ibf_args_insert.compressed = false; - std::vector minimiser_file_insert = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file_insert = {data("mini_example.minimiser")}; ibf(minimiser_file, ibf_args_insert, fpr); delete_bin({1}, ibf_args_insert, ibf_args_insert.path_out, false); - insert(minimiser_file_insert, ibf_args_insert, "", tmp_dir/"IBFMIN_Insert_Given_", false); + insert(minimiser_file_insert, ibf_args_insert, "", "IBFMIN_Insert_Given_", false); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_1"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_1"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_1"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_IBF_1"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_2"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_2"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_2"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_IBF_2"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBFMIN_Test_Given_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBFMIN_Insert_Given_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Test_Given_IBF_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_2"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Deleted"); } -TEST(insert, ibfmin_no_given_thresholds) +TEST_F(insert_test, ibfmin_no_given_thresholds) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.number_expression_thresholds = 2; std::vector fpr = {0.05, 0.05}; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Given_"; + ibf_args.path_out = "IBFMIN_Test_Given_"; ibf_args.compressed = false; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser", std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file = {data("mini_example.minimiser"), data("mini_example.minimiser")}; ibf(minimiser_file, ibf_args, fpr); estimate_ibf_arguments ibf_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.number_expression_thresholds = 2; - ibf_args_insert.path_out = tmp_dir/"IBFMIN_Insert_Given_"; + ibf_args_insert.path_out = "IBFMIN_Insert_Given_"; ibf_args_insert.compressed = false; fpr = {0.05}; - std::vector minimiser_file_insert = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file_insert = {data("mini_example.minimiser")}; ibf(minimiser_file_insert, ibf_args_insert, fpr); - insert(minimiser_file_insert, ibf_args_insert, "", tmp_dir/"IBFMIN_Insert_Given_", true); + insert(minimiser_file_insert, ibf_args_insert, "", "IBFMIN_Insert_Given_", true); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_Level_0"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_Level_0"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_Level_0"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_IBF_Level_0"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_IBF_Level_1"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_Level_1"); + load_ibf(ibf, "IBFMIN_Test_Given_IBF_Level_1"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_IBF_Level_1"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> expressions_ibf{}; - read_levels(expressions_ibf, tmp_dir/"IBFMIN_Test_Given_IBF_Levels.levels"); + read_levels(expressions_ibf, "IBFMIN_Test_Given_IBF_Levels.levels"); std::vector> expressions_insert{}; - read_levels(expressions_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_Levels.levels"); + read_levels(expressions_insert, "IBFMIN_Insert_Given_IBF_Levels.levels"); EXPECT_EQ(expressions_ibf,expressions_insert); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBFMIN_Test_Given_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBFMIN_Insert_Given_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_IBF_Levels.levels"); } -TEST(insert, delete_ibfmin_no_given_thresholds) +TEST_F(insert_test, delete_ibfmin_no_given_thresholds) { - std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory estimate_ibf_arguments ibf_args{}; initialization_args(ibf_args); ibf_args.number_expression_thresholds = 2; std::vector fpr = {0.05, 0.05}; - ibf_args.path_out = tmp_dir/"IBFMIN_Test_Given_Del_"; + ibf_args.path_out = "IBFMIN_Test_Given_Del_"; ibf_args.compressed = false; - std::vector minimiser_file = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser", std::string(DATA_INPUT_DIR) + "mini_example.minimiser", std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file = {data("mini_example.minimiser"), data("mini_example.minimiser"), data("mini_example.minimiser")}; ibf(minimiser_file, ibf_args, fpr); estimate_ibf_arguments ibf_args_insert{}; initialization_args(ibf_args_insert); ibf_args_insert.number_expression_thresholds = 2; - ibf_args_insert.path_out = tmp_dir/"IBFMIN_Insert_Given_Del_"; + ibf_args_insert.path_out = "IBFMIN_Insert_Given_Del_"; ibf_args_insert.compressed = false; fpr = {0.05}; - std::vector minimiser_file_insert = {std::string(DATA_INPUT_DIR) + "mini_example.minimiser"}; + std::vector minimiser_file_insert = {data("mini_example.minimiser")}; ibf(minimiser_file, ibf_args_insert, fpr); delete_bin({1}, ibf_args_insert, ibf_args_insert.path_out, true); - insert(minimiser_file_insert, ibf_args_insert, "", tmp_dir/"IBFMIN_Insert_Given_Del_", true); + insert(minimiser_file_insert, ibf_args_insert, "", "IBFMIN_Insert_Given_Del_", true); seqan3::interleaved_bloom_filter ibf; seqan3::interleaved_bloom_filter ibf_insert; - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_Del_IBF_Level_0"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Level_0"); + load_ibf(ibf, "IBFMIN_Test_Given_Del_IBF_Level_0"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_Del_IBF_Level_0"); EXPECT_TRUE((ibf == ibf_insert)); - load_ibf(ibf, tmp_dir/"IBFMIN_Test_Given_Del_IBF_Level_1"); - load_ibf(ibf_insert, tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Level_1"); + load_ibf(ibf, "IBFMIN_Test_Given_Del_IBF_Level_1"); + load_ibf(ibf_insert, "IBFMIN_Insert_Given_Del_IBF_Level_1"); EXPECT_TRUE((ibf == ibf_insert)); std::vector> expressions_ibf{}; - read_levels(expressions_ibf, tmp_dir/"IBFMIN_Test_Given_Del_IBF_Levels.levels"); + read_levels(expressions_ibf, "IBFMIN_Test_Given_Del_IBF_Levels.levels"); std::vector> expressions_insert{}; - read_levels(expressions_insert, tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Levels.levels"); + read_levels(expressions_insert, "IBFMIN_Insert_Given_Del_IBF_Levels.levels"); EXPECT_EQ(expressions_ibf,expressions_insert); std::vector> fpr_ibf{}; - read_levels(fpr_ibf, tmp_dir/"IBFMIN_Test_Given_IBF_FPRs.fprs"); + read_levels(fpr_ibf, "IBFMIN_Test_Given_Del_IBF_FPRs.fprs"); std::vector> fpr_insert{}; - read_levels(fpr_insert, tmp_dir/"IBFMIN_Insert_Given_IBF_FPRs.fprs"); + read_levels(fpr_insert, "IBFMIN_Insert_Given_Del_IBF_FPRs.fprs"); EXPECT_EQ(fpr_ibf,fpr_insert); - - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_Del_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_Del_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_Del_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_Del_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBFMIN_Test_Given_Del_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Level_1"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Data"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_Del_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"IBFMIN_Insert_Given_Del_IBF_Deleted"); } diff --git a/test/api/minimiser_test.cpp b/test/api/minimiser_test.cpp index 5c33160..6c8d352 100644 --- a/test/api/minimiser_test.cpp +++ b/test/api/minimiser_test.cpp @@ -5,15 +5,22 @@ #include "ibf.h" #include "shared.h" +#include "../app_test.hpp" -#ifndef DATA_INPUT_DIR -# define DATA_INPUT_DIR @DATA_INPUT_DIR@ -#endif - -using seqan3::operator""_shape; -std::filesystem::path tmp_dir = std::filesystem::temp_directory_path(); // get the temp directory +// To prevent issues when running multiple CLI tests in parallel, give each CLI test unique names: +struct minimiser_test : public app_test +{ + void initialization_args(estimate_ibf_arguments & args) + { + args.k = 4; + args.shape = seqan3::ungapped{args.k}; + args.w_size = seqan3::window_size{4}; + args.s = seqan3::seed{0}; + args.path_out = "Minimiser_Test_"; + args.compressed = true; + } -std::vector> expected_hash_tables{ // minimisers: + std::vector> expected_hash_tables{ // minimisers: {{0,2}, // AAAA {1,4}, // AAAC {6,4}, // AACG @@ -40,18 +47,9 @@ std::vector> expected_hash_ta {165,1}, // GGCC {168,1}, // GGGA },}; +}; -void initialization_args(estimate_ibf_arguments & args) -{ - args.k = 4; - args.shape = seqan3::ungapped{args.k}; - args.w_size = seqan3::window_size{4}; - args.s = seqan3::seed{0}; - args.path_out = tmp_dir/"Minimiser_Test_"; - args.compressed = true; -} - -TEST(minimiser, small_example) +TEST_F(minimiser_test, small_example) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; @@ -59,20 +57,19 @@ TEST(minimiser, small_example) std::vector cutoffs = {0, 0}; args.expression_thresholds = {0}; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); - uint32_t normalized_exp_value{}; robin_hood::unordered_node_map result_hash_table{}; std::vector minimiser_files{}; uint64_t num_of_minimisers{}; std::vector expected_nums{12, 12}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -82,8 +79,8 @@ TEST(minimiser, small_example) EXPECT_EQ(0, cutoff); // Test binary file - read_binary(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); + read_binary(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); + minimiser_files.push_back(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); for (auto & hash : expected_hash_tables[i]) { EXPECT_EQ(expected_hash_tables[i][hash.first], result_hash_table[hash.first]); @@ -94,7 +91,7 @@ TEST(minimiser, small_example) EXPECT_EQ(args.expression_thresholds, ibf(minimiser_files, args, fpr)); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"Minimiser_Test_IBF_0"); + load_ibf(ibf, "Minimiser_Test_IBF_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -107,32 +104,28 @@ TEST(minimiser, small_example) auto & res3 = agent.bulk_contains(27); EXPECT_RANGE_EQ(expected_result, res3); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_0"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example2.minimiser")); } -TEST(minimiser, small_example_different_shape) +TEST_F(minimiser_test, small_example_different_shape) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; initialization_args(args); std::vector cutoffs = {0, 0}; args.shape = seqan3::bin_literal{0b1101}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + EXPECT_EQ(13, args.shape.to_ulong()); + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); uint64_t num_of_minimisers{}; std::vector expected_nums{12, 11}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -142,11 +135,9 @@ TEST(minimiser, small_example_different_shape) EXPECT_EQ(0, cutoff); } - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example2.minimiser")); } -TEST(minimiser, small_example_samplewise) +TEST_F(minimiser_test, small_example_samplewise) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; @@ -155,11 +146,10 @@ TEST(minimiser, small_example_samplewise) std::vector cutoffs = {0, 0}; args.number_expression_thresholds = 1; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); - uint32_t normalized_exp_value{}; std::vector> expected_counts{{7}, {12}}; std::vector expected_levels{}; robin_hood::unordered_node_map result_hash_table{}; @@ -167,12 +157,12 @@ TEST(minimiser, small_example_samplewise) uint64_t num_of_minimisers{}; std::vector expected_nums{12, 12}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file args.expression_thresholds = {}; - read_binary_start(args, tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); EXPECT_EQ(0, args.s.get()); @@ -181,8 +171,8 @@ TEST(minimiser, small_example_samplewise) EXPECT_EQ(0, cutoff); // Test binary file - read_binary(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); + read_binary(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); + minimiser_files.push_back(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); for (auto & hash : expected_hash_tables[i]) { EXPECT_EQ(expected_hash_tables[i][hash.first], result_hash_table[hash.first]); @@ -194,7 +184,7 @@ TEST(minimiser, small_example_samplewise) EXPECT_EQ(expected_levels, ibf(minimiser_files, args, fpr)); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"Minimiser_Test_IBF_Level_0"); + load_ibf(ibf, "Minimiser_Test_IBF_Level_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -206,15 +196,9 @@ TEST(minimiser, small_example_samplewise) expected_result[1] = 1; auto & res3 = agent.bulk_contains(27); EXPECT_RANGE_EQ(expected_result, res3); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_Level_0"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_Levels.levels"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example2.minimiser")); } -TEST(minimiser, cutoff_by_filesize) +TEST_F(minimiser_test, cutoff_by_filesize) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; @@ -222,20 +206,20 @@ TEST(minimiser, cutoff_by_filesize) args.expression_thresholds = {0}; std::vector fpr = {0.05}; std::vector cutoffs{}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); - uint32_t normalized_exp_value{}; + std::vector minimiser_files{}; uint64_t num_of_minimisers{}; std::vector expected_nums{12, 12}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -243,13 +227,13 @@ TEST(minimiser, cutoff_by_filesize) EXPECT_EQ(15, args.shape.to_ulong()); EXPECT_EQ(0, cutoff); EXPECT_EQ(expected_nums[i], num_of_minimisers); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); + minimiser_files.push_back(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); } EXPECT_EQ(args.expression_thresholds, ibf(minimiser_files, args, fpr)); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"Minimiser_Test_IBF_0"); + load_ibf(ibf, "Minimiser_Test_IBF_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -263,14 +247,9 @@ TEST(minimiser, cutoff_by_filesize) auto & res3 = agent.bulk_contains(85); EXPECT_RANGE_EQ(expected_result, res3); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_0"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example2.minimiser")); } -TEST(minimiser, small_example_two_threads) +TEST_F(minimiser_test, small_example_two_threads) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; @@ -279,21 +258,20 @@ TEST(minimiser, small_example_two_threads) std::vector cutoffs = {0, 0}; args.expression_thresholds = {0}; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); args.threads = 1; - uint32_t normalized_exp_value{}; robin_hood::unordered_node_map result_hash_table{}; std::vector minimiser_files{}; uint64_t num_of_minimisers{}; std::vector expected_nums{12, 12}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -303,8 +281,8 @@ TEST(minimiser, small_example_two_threads) EXPECT_EQ(expected_nums[i], num_of_minimisers); // Test binary file - read_binary(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); + read_binary(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); + minimiser_files.push_back(("Minimiser_Test_" + std::string{sequence_files[i].stem()} + ".minimiser")); for (auto & hash : expected_hash_tables[i]) { EXPECT_EQ(expected_hash_tables[i][hash.first], result_hash_table[hash.first]); @@ -316,7 +294,7 @@ TEST(minimiser, small_example_two_threads) EXPECT_EQ(args.expression_thresholds, ibf(minimiser_files, args, fpr)); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"Minimiser_Test_IBF_0"); + load_ibf(ibf, "Minimiser_Test_IBF_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -329,35 +307,29 @@ TEST(minimiser, small_example_two_threads) auto & res3 = agent.bulk_contains(27); EXPECT_RANGE_EQ(expected_result, res3); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_0"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_Data"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_mini_example2.minimiser")); } -TEST(minimiser, small_example_include) +TEST_F(minimiser_test, small_example_include) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; initialization_args(args); - args.path_out = tmp_dir/"Minimiser_Test_In_"; + args.path_out = "Minimiser_Test_In_"; std::vector cutoffs = {0, 0}; - minimiser_args.include_file = std::string(DATA_INPUT_DIR) + "mini_gen.fasta"; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + minimiser_args.include_file = data("mini_gen.fasta"); + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); - uint32_t normalized_exp_value{}; robin_hood::unordered_node_map result_hash_table{}; std::vector minimiser_files{}; uint64_t num_of_minimisers{}; std::vector expected_nums{1, 0}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_In_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_In_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -367,8 +339,8 @@ TEST(minimiser, small_example_include) EXPECT_EQ(expected_nums[i], num_of_minimisers); // Test binary file - read_binary(tmp_dir/("Minimiser_Test_In_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_In_" + std::string{sequence_files[i].stem()} + ".minimiser")); + read_binary(("Minimiser_Test_In_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); + minimiser_files.push_back(("Minimiser_Test_In_" + std::string{sequence_files[i].stem()} + ".minimiser")); if (i==0) { for (auto & hash : result_hash_table) @@ -385,34 +357,31 @@ TEST(minimiser, small_example_include) result_hash_table.clear(); } - std::filesystem::remove(tmp_dir/("Minimiser_Test_In_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_In_mini_example2.minimiser")); } -TEST(minimiser, small_example_exclude) +TEST_F(minimiser_test, small_example_exclude) { estimate_ibf_arguments args{}; minimiser_arguments minimiser_args{}; initialization_args(args); - args.path_out = tmp_dir/"Minimiser_Test_Ex_"; + args.path_out = "Minimiser_Test_Ex_"; std::vector cutoffs = {0, 0}; - minimiser_args.exclude_file = std::string(DATA_INPUT_DIR) + "mini_gen2.fasta"; + minimiser_args.exclude_file = data("mini_gen2.fasta"); args.expression_thresholds = {0}; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); - uint32_t normalized_exp_value{}; robin_hood::unordered_node_map result_hash_table{}; std::vector minimiser_files{}; uint64_t num_of_minimisers{}; std::vector expected_nums{11, 12}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_Ex_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_Ex_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -422,8 +391,8 @@ TEST(minimiser, small_example_exclude) EXPECT_EQ(0, cutoff); // Test binary file - read_binary(tmp_dir/("Minimiser_Test_Ex_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_Ex_" + std::string{sequence_files[i].stem()} + ".minimiser")); + read_binary(("Minimiser_Test_Ex_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); + minimiser_files.push_back(("Minimiser_Test_Ex_" + std::string{sequence_files[i].stem()} + ".minimiser")); EXPECT_TRUE(result_hash_table.find(216) == result_hash_table.end()); //TCGA, only minimiser in mini_gen2 for (auto & hash : expected_hash_tables[i]) { @@ -438,7 +407,7 @@ TEST(minimiser, small_example_exclude) EXPECT_EQ(args.expression_thresholds, ibf(minimiser_files, args, fpr)); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"Minimiser_Test_Ex_IBF_0"); + load_ibf(ibf, "Minimiser_Test_Ex_IBF_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -451,14 +420,9 @@ TEST(minimiser, small_example_exclude) auto & res3 = agent.bulk_contains(27); EXPECT_RANGE_EQ(expected_result, res3); - std::filesystem::remove(tmp_dir/"Minimiser_Test_Ex_IBF_0"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_Ex_IBF_Data"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_Ex_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/("Minimiser_Test_Ex_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_Ex_mini_example2.minimiser")); } -TEST(minimiser, small_example_shape) +TEST_F(minimiser_test, small_example_shape) { std::vector> expected_hash_tables_shape{ // minimisers: { @@ -484,24 +448,24 @@ TEST(minimiser, small_example_shape) minimiser_arguments minimiser_args{}; initialization_args(args); args.shape = seqan3::bin_literal{9}; - args.path_out = tmp_dir/"Minimiser_Test_Shape_"; + EXPECT_EQ(9, args.shape.to_ulong()); + args.path_out = "Minimiser_Test_Shape_"; std::vector cutoffs = {0, 0}; args.expression_thresholds = {0}; std::vector fpr = {0.05}; - std::vector sequence_files = {std::string(DATA_INPUT_DIR) + "mini_example.fasta", - std::string(DATA_INPUT_DIR) + "mini_example2.fasta"}; + std::vector sequence_files = {data("mini_example.fasta"), + data("mini_example2.fasta")}; minimiser(sequence_files, args, minimiser_args, cutoffs); - uint32_t normalized_exp_value{}; robin_hood::unordered_node_map result_hash_table{}; std::vector minimiser_files{}; uint64_t num_of_minimisers{}; std::vector expected_nums{8, 7}; - for (int i = 0; i < sequence_files.size(); ++i) + for (size_t i = 0; i < sequence_files.size(); ++i) { uint8_t cutoff{}; // Test Header file - read_binary_start(args, tmp_dir/("Minimiser_Test_Shape_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); + read_binary_start(args, ("Minimiser_Test_Shape_" + std::string{sequence_files[i].stem()} + ".minimiser"), num_of_minimisers, cutoff); EXPECT_EQ(4, args.k); EXPECT_EQ(4, args.w_size.get()); @@ -511,8 +475,8 @@ TEST(minimiser, small_example_shape) EXPECT_EQ(0, cutoff); // Test binary file - read_binary(tmp_dir/("Minimiser_Test_Shape_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); - minimiser_files.push_back(tmp_dir/("Minimiser_Test_Shape_" + std::string{sequence_files[i].stem()} + ".minimiser")); + read_binary(("Minimiser_Test_Shape_" + std::string{sequence_files[i].stem()} + ".minimiser"), result_hash_table); + minimiser_files.push_back(("Minimiser_Test_Shape_" + std::string{sequence_files[i].stem()} + ".minimiser")); for (auto & hash : expected_hash_tables_shape[i]) EXPECT_EQ(expected_hash_tables_shape[i][hash.first], result_hash_table[hash.first]); @@ -521,7 +485,7 @@ TEST(minimiser, small_example_shape) EXPECT_EQ(args.expression_thresholds, ibf(minimiser_files, args, fpr)); seqan3::interleaved_bloom_filter ibf; - load_ibf(ibf, tmp_dir/"Minimiser_Test_Shape_IBF_0"); + load_ibf(ibf, "Minimiser_Test_Shape_IBF_0"); auto agent = ibf.membership_agent(); std::vector expected_result(2, 0); @@ -534,9 +498,4 @@ TEST(minimiser, small_example_shape) auto & res3 = agent.bulk_contains(2); EXPECT_RANGE_EQ(expected_result, res3); - std::filesystem::remove(tmp_dir/"Minimiser_Test_Shape_IBF_0"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_Shape_IBF_Data"); - std::filesystem::remove(tmp_dir/"Minimiser_Test_Shape_IBF_FPRs.fprs"); - std::filesystem::remove(tmp_dir/("Minimiser_Test_Shape_mini_example.minimiser")); - std::filesystem::remove(tmp_dir/("Minimiser_Test_Shape_mini_example2.minimiser")); } diff --git a/test/app_test.hpp b/test/app_test.hpp new file mode 100644 index 0000000..84ca45f --- /dev/null +++ b/test/app_test.hpp @@ -0,0 +1,120 @@ +// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin +// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik +// SPDX-License-Identifier: CC0-1.0 + +#pragma once + +#include + +#include +#include +#include +#include +#include + +// Checks for CLI test result for success, and prints the command line call if the test fails. +#ifndef EXPECT_SUCCESS +# define EXPECT_SUCCESS(arg) EXPECT_EQ(arg.exit_code, 0) << "Command: " << arg.command +#endif + +// Checks the exit code of a CLI test result for failure, and prints the command line call if the test fails. +#ifndef EXPECT_FAILURE +# define EXPECT_FAILURE(arg) EXPECT_NE(arg.exit_code, 0) << "Command: " << arg.command +#endif + +// Provides functions for CLI test implementation. +struct app_test : public ::testing::Test +{ +private: + // Holds the original work directory where Gtest has been started. + std::filesystem::path original_workdir{}; + +protected: + // Result struct for captured streams and exit code. + struct app_test_result + { + std::string out{}; + std::string err{}; + std::string command{}; + int exit_code{}; + }; + + // Invoke the app execution. The command line call should be given as separate parameters. + template + app_test_result execute_app(CommandItemTypes &&... command_items) + { + app_test_result result{}; + + // Assemble the command string and disable version check. + result.command = [&command_items...]() + { + std::ostringstream command{}; + command << "SEQAN3_NO_VERSION_CHECK=1 " << BINDIR << APPNAME; + (void)((command << ' ' << command_items), ...); // (void) silences "state has no effect" warning if no items + return command.str(); + }(); + + // Always capture the output streams. + testing::internal::CaptureStdout(); + testing::internal::CaptureStderr(); + + // Run the command and return results. + result.exit_code = std::system(result.command.c_str()); + result.out = testing::internal::GetCapturedStdout(); + result.err = testing::internal::GetCapturedStderr(); + return result; + } + + // Generate the full path of a test input file that is provided in the data directory. + static std::filesystem::path data(std::string const & filename) + { + return std::filesystem::path{std::string{DATADIR}}.concat(filename); + } + + // Read the contents of a file into a string. + static std::string const string_from_file(std::filesystem::path const & path, + std::ios_base::openmode const mode = std::ios_base::in) + { + std::ifstream file_stream(path, mode); + if (!file_stream.is_open()) + throw std::logic_error{"Cannot open " + path.string()}; + std::stringstream file_buffer; + file_buffer << file_stream.rdbuf(); + return {file_buffer.str()}; + } + + // Create an individual work directory for the current test. + void SetUp() override + { + // Assemble the directory name. + ::testing::TestInfo const * const info = ::testing::UnitTest::GetInstance()->current_test_info(); + std::filesystem::path const test_dir{std::string{OUTPUTDIR} + // + std::string{info->test_case_name()} + // + std::string{"."} + // + std::string{info->name()}}; + try + { + std::filesystem::remove_all(test_dir); // delete the directory if it exists + std::filesystem::create_directories(test_dir); // create the new empty directory + original_workdir = std::filesystem::current_path(); // store original work dir path + std::filesystem::current_path(test_dir); // change the work dir + } + catch (std::exception const & exc) + { + FAIL() << "Failed to set up the test directory " << test_dir << ":\n" << exc.what(); + } + } + + // Switch back to the initial work directory. + void TearDown() override + { + try + { + std::filesystem::current_path(original_workdir); // restore the original work dir + } + catch (std::exception const & exc) + { + FAIL() << "Failed to set the work directory to " << original_workdir << ":\n" << exc.what(); + } + } +}; diff --git a/test/cli/count_options_test.cpp b/test/cli/count_options_test.cpp index 5621882..43e3310 100644 --- a/test/cli/count_options_test.cpp +++ b/test/cli/count_options_test.cpp @@ -1,12 +1,12 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" -struct count_options_test : public cli_test {}; +struct count_options_test : public app_test {}; TEST_F(count_options_test, no_options) { - cli_test_result result = execute_app("needle count"); + app_test_result result = execute_app("count"); std::string expected { "needle-count - Get expression value depending on minimizers. " @@ -21,91 +21,91 @@ TEST_F(count_options_test, no_options) "==========================================\n " "Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(count_options_test, fail_no_argument) { - cli_test_result result = execute_app("needle count", "--seed 0 --genome", data("mini_gen.genome")," --include", data("mini_gen.fasta")); + app_test_result result = execute_app("count", "--seed 0 --genome", data("mini_gen.genome")," --include", data("mini_gen.fasta")); std::string expected { "Error. Incorrect command line input for count. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{}); EXPECT_EQ(result.err, expected); } TEST_F(count_options_test, with_arguments) { - cli_test_result result = execute_app("needle count -k 4 -w 4 --seed 0 --genome", data("mini_gen.genome")," --include", data("mini_gen.fasta"), data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("count -k 4 -w 4 --seed 0 --genome", data("mini_gen.genome")," --include", data("mini_gen.fasta"), data("mini_example.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(count_options_test, multithreads) { - cli_test_result result = execute_app("needle count -k 4 -w 8 -t 2 --genome", + app_test_result result = execute_app("count -k 4 -w 8 -t 2 --genome", data("mini_gen.genome"), " --include", data("mini_gen.fasta"), data("mini_example.fasta"), data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(count_options_test, paired) { - cli_test_result result = execute_app("needle count -k 4 -w 8 -p --genome", + app_test_result result = execute_app("count -k 4 -w 8 -p --genome", data("mini_gen.genome"), " --include", data("mini_gen.fasta"), data("mini_example.fasta"), data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } -struct genome_options_test : public cli_test {}; +struct genome_options_test : public app_test {}; TEST_F(genome_options_test, no_options) { - cli_test_result result = execute_app("needle genome"); + app_test_result result = execute_app("genome"); std::string expected { "needle-genome - Creates the genome file necessary as an input to count.\n" "=======================================================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(genome_options_test, fail_no_argument) { - cli_test_result result = execute_app("needle genome", "--seed 0"); + app_test_result result = execute_app("genome", "--seed 0"); std::string expected { "Error. Incorrect command line input for count. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{}); EXPECT_EQ(result.err, expected); } TEST_F(genome_options_test, with_arguments) { - cli_test_result result = execute_app("needle genome -k 4 -w 4 --seed 0 ", data("mini_gen.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("genome -k 4 -w 4 --seed 0 ", data("mini_gen.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } diff --git a/test/cli/delete_options_test.cpp b/test/cli/delete_options_test.cpp index d26b11b..fbbe668 100644 --- a/test/cli/delete_options_test.cpp +++ b/test/cli/delete_options_test.cpp @@ -1,22 +1,22 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" #include "ibf.h" #include "shared.h" -struct delete_options_test : public cli_test {}; +struct delete_options_test : public app_test {}; TEST_F(delete_options_test, delete_no_options) { - cli_test_result result = execute_app("needle delete"); + app_test_result result = execute_app("delete"); std::string expected { "needle-delete - Delete experiments specified by their position from the Needle index.\n" "=====================================================================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } @@ -32,8 +32,8 @@ TEST_F(delete_options_test, with_argument) std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - cli_test_result result = execute_app("needle delete -i ", "Test_ ", "0"); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("delete -i ", "Test_ ", "0"); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } diff --git a/test/cli/estimate_options_test.cpp b/test/cli/estimate_options_test.cpp index 53a21ee..1781f6c 100644 --- a/test/cli/estimate_options_test.cpp +++ b/test/cli/estimate_options_test.cpp @@ -1,35 +1,35 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" #include "ibf.h" #include "shared.h" -struct estimate_options_test : public cli_test {}; +struct estimate_options_test : public app_test {}; TEST_F(estimate_options_test, no_options) { - cli_test_result result = execute_app("needle estimate"); + app_test_result result = execute_app("estimate"); std::string expected { "needle-estimate - Estimate expression value of transcript based on the Needle index.\n" "====================================================================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(estimate_options_test, fail_no_argument) { - cli_test_result result = execute_app("needle estimate", "-m"); + app_test_result result = execute_app("estimate", "-m"); std::string expected { "Error. Incorrect command line input for estimate. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{}); EXPECT_EQ(result.err, expected); } @@ -45,8 +45,8 @@ TEST_F(estimate_options_test, with_argument) std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - cli_test_result result = execute_app("needle estimate -i ", "Test_", data("mini_gen.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("estimate -i ", "Test_", data("mini_gen.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } @@ -62,8 +62,8 @@ TEST_F(estimate_options_test, with_argument_normalization_method) std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - cli_test_result result = execute_app("needle estimate -m -i ", "Test_", data("mini_gen.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("estimate -m -i ", "Test_", data("mini_gen.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } @@ -79,8 +79,8 @@ TEST_F(estimate_options_test, with_argument_out) std::vector cutoffs{}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - cli_test_result result = execute_app("needle estimate -o ", "expressions.out","-i ", "Test_", data("mini_gen.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("estimate -o ", "expressions.out","-i ", "Test_", data("mini_gen.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } diff --git a/test/cli/ibf_options_test.cpp b/test/cli/ibf_options_test.cpp index d41b8cf..03178e3 100644 --- a/test/cli/ibf_options_test.cpp +++ b/test/cli/ibf_options_test.cpp @@ -1,51 +1,51 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" -struct ibf_options_test : public cli_test {}; +struct ibf_options_test : public app_test {}; TEST_F(ibf_options_test, ibf_no_options) { - cli_test_result result = execute_app("needle ibf"); + app_test_result result = execute_app("ibf"); std::string expected { "needle-ibf - Constructs the Needle index.\n" "=========================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, ibf_fail_no_argument) { - cli_test_result result = execute_app("needle ibf", "-c"); + app_test_result result = execute_app("ibf", "-c"); std::string expected { "Error. Incorrect command line input for ibf. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibf_fail_contradiction) { - cli_test_result result = execute_app("needle ibf -f 0.05 -e 1 -e 2 -l 1", data("exp_01.fasta")); + app_test_result result = execute_app("ibf -f 0.05 -e 1 -e 2 -l 1", data("exp_01.fasta")); std::string expected { "Error. Please set the expression levels OR give the number of expression levels.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibf_fail_contradiction2) { - cli_test_result result = execute_app("needle ibf -f 0.05 -e 1 -e 2 --levels-by-genome ", data("exp_01.fasta"), + app_test_result result = execute_app("ibf -f 0.05 -e 1 -e 2 --levels-by-genome ", data("exp_01.fasta"), data("exp_01.fasta")); std::string expected { @@ -53,101 +53,101 @@ TEST_F(ibf_options_test, ibf_fail_contradiction2) "the expression levels without the option --level-by-genome OR use the number of expression levels with that option." "\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibf_fail_no_fpr) { - cli_test_result result = execute_app("needle ibf -l 2", data("exp_01.fasta")); + app_test_result result = execute_app("ibf -l 2", data("exp_01.fasta")); std::string expected { "Error. Please give a false positive rate for the IBFs.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibf_fail_incorrect_number_of_fprs) { - cli_test_result result = execute_app("needle ibf -f 0.05 -f 0.01 -f 0.03 -l 2", data("exp_01.fasta")); + app_test_result result = execute_app("ibf -f 0.05 -f 0.01 -f 0.03 -l 2", data("exp_01.fasta")); std::string expected { "Error. Length of false positive rates for IBFs is not equal to length of expression thresholds.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibf_with_argument) { - cli_test_result result = execute_app("needle ibf -f 0.05 -l 1", data("exp_01.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibf -f 0.05 -l 1", data("exp_01.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, ibf_with_argument_with_options) { - cli_test_result result = execute_app("needle ibf -f 0.05 -k 4 -w 8 -l 1", data("exp_01.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibf -f 0.05 -k 4 -w 8 -l 1", data("exp_01.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, ibf_with_argument_with_userdefined_shape) { - cli_test_result result = execute_app("needle ibf -f 0.05 -k 4 -w 8 --shape 11 -l 1", data("exp_01.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibf -f 0.05 -k 4 -w 8 --shape 11 -l 1", data("exp_01.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, ibfmin_no_options) { - cli_test_result result = execute_app("needle ibfmin"); + app_test_result result = execute_app("ibfmin"); std::string expected { "needle-ibfmin - Constructs the Needle index from the minimiser files created by needle minimiser.\n" "=================================================================================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, ibfmin_fail_no_argument) { - cli_test_result result = execute_app("needle ibfmin -c"); + app_test_result result = execute_app("ibfmin -c"); std::string expected { "Error. Incorrect command line input for ibfmin. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibfmin_fail_contradiction) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -e 1 -e 2 -l 1", data("mini_example.minimiser")); + app_test_result result = execute_app("ibfmin -f 0.05 -e 1 -e 2 -l 1", data("mini_example.minimiser")); std::string expected { "Error. Please set the expression levels OR give the number of expression levels.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibfmin_fail_contradiction2) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -e 1 -e 2 --levels-by-genome ", data("exp_01.fasta"), + app_test_result result = execute_app("ibfmin -f 0.05 -e 1 -e 2 --levels-by-genome ", data("exp_01.fasta"), data("mini_example.minimiser")); std::string expected { @@ -155,63 +155,63 @@ TEST_F(ibf_options_test, ibfmin_fail_contradiction2) "the expression levels without the option --level-by-genome OR use the number of expression levels with that option." "\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibfmin_fail_no_fpr) { - cli_test_result result = execute_app("needle ibfmin -l 2", data("mini_example.minimiser")); + app_test_result result = execute_app("ibfmin -l 2", data("mini_example.minimiser")); std::string expected { "Error. Please give a false positive rate for the IBFs.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibfmin_fail_incorrect_number_of_fprs) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -f 0.01 -f 0.03 -l 2", data("mini_example.minimiser")); + app_test_result result = execute_app("ibfmin -f 0.05 -f 0.01 -f 0.03 -l 2", data("mini_example.minimiser")); std::string expected { "Error. Length of false positive rates for IBFs is not equal to length of expression thresholds.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } TEST_F(ibf_options_test, ibfmin_with_argument) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -l 1", data("mini_example.minimiser")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibfmin -f 0.05 -l 1", data("mini_example.minimiser")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, compressed) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -l 1 -c ", data("mini_example.minimiser")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibfmin -f 0.05 -l 1 -c ", data("mini_example.minimiser")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, more_hash_functions) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -l 1 -n 4 ", data("mini_example.minimiser")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibfmin -f 0.05 -l 1 -n 4 ", data("mini_example.minimiser")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(ibf_options_test, expression_thresholds) { - cli_test_result result = execute_app("needle ibfmin -f 0.05 -e 2 -e 4", data("mini_example.minimiser")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("ibfmin -f 0.05 -e 2 -e 4", data("mini_example.minimiser")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } diff --git a/test/cli/insert_options_test.cpp b/test/cli/insert_options_test.cpp index 4499699..3fe3610 100644 --- a/test/cli/insert_options_test.cpp +++ b/test/cli/insert_options_test.cpp @@ -1,35 +1,35 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" #include "ibf.h" #include "shared.h" -struct insert_options_test : public cli_test {}; +struct insert_options_test : public app_test {}; TEST_F(insert_options_test, insert_no_options) { - cli_test_result result = execute_app("needle insert"); + app_test_result result = execute_app("insert"); std::string expected { "needle-insert - Inserts into a given uncompressed Needle index.\n" "===============================================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(insert_options_test, insert_fail_no_argument) { - cli_test_result result = execute_app("needle insert", "-c"); + app_test_result result = execute_app("insert", "-c"); std::string expected { "Error. Incorrect command line input for insert. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{""}); EXPECT_EQ(result.err, expected); } @@ -46,8 +46,8 @@ TEST_F(insert_options_test, with_argument) std::vector cutoffs{1}; ibf(sequence_files, ibf_args, minimiser_args, fpr, cutoffs); - cli_test_result result = execute_app("needle insert -i ", tmp_dir/"Test_", data("exp_01.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("insert -i ", tmp_dir/"Test_", data("exp_01.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } diff --git a/test/cli/minimiser_options_test.cpp b/test/cli/minimiser_options_test.cpp index 975f4b6..d823a6d 100644 --- a/test/cli/minimiser_options_test.cpp +++ b/test/cli/minimiser_options_test.cpp @@ -1,88 +1,88 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" -struct minimiser_options_test : public cli_test {}; +struct minimiser_options_test : public app_test {}; TEST_F(minimiser_options_test, no_options) { - cli_test_result result = execute_app("needle minimiser"); + app_test_result result = execute_app("minimiser"); std::string expected { "needle-minimiser - Calculates minimiser for given experiments.\n" "==============================================================\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(minimiser_options_test, fail_no_argument) { - cli_test_result result = execute_app("needle minimiser", "--seed 0"); + app_test_result result = execute_app("minimiser", "--seed 0"); std::string expected { "Error. Incorrect command line input for minimiser. Not enough positional arguments provided " "(Need at least 1). See -h/--help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, std::string{}); EXPECT_EQ(result.err, expected); } TEST_F(minimiser_options_test, with_arguments) { - cli_test_result result = execute_app("needle minimiser -k 4 -w 4 --seed 0", data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("minimiser -k 4 -w 4 --seed 0", data("mini_example.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(minimiser_options_test, cutoff) { - cli_test_result result = execute_app("needle minimiser -k 4 -w 8 --cutoff 2", data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + app_test_result result = execute_app("minimiser -k 4 -w 8 --cutoff 2", data("mini_example.fasta")); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(minimiser_options_test, multiple_sample) { - cli_test_result result = execute_app("needle minimiser -k 4 -w 8 --samples 2 ", data("mini_example.fasta"), + app_test_result result = execute_app("minimiser -k 4 -w 8 --samples 2 ", data("mini_example.fasta"), data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(minimiser_options_test, multithreads) { - cli_test_result result = execute_app("needle minimiser -k 4 -w 8 -t 2", data("mini_example.fasta"), + app_test_result result = execute_app("minimiser -k 4 -w 8 -t 2", data("mini_example.fasta"), data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(minimiser_options_test, paired) { - cli_test_result result = execute_app("needle minimiser -k 4 -w 8 -p ", data("mini_example.fasta"), + app_test_result result = execute_app("minimiser -k 4 -w 8 -p ", data("mini_example.fasta"), data("mini_example.fasta")); - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, std::string{}); } TEST_F(minimiser_options_test, invalid_argument) { - cli_test_result result = execute_app("needle minimiser -k 4 -w 8 --samples 3 ", data("mini_example.fasta"), + app_test_result result = execute_app("minimiser -k 4 -w 8 --samples 3 ", data("mini_example.fasta"), data("mini_example.fasta")); std::string expected { "Error. Incorrect command line input for multiple-samples.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, ""); EXPECT_EQ(result.err, expected); } diff --git a/test/cli/needle_options_test.cpp b/test/cli/needle_options_test.cpp index 567abab..df40aca 100644 --- a/test/cli/needle_options_test.cpp +++ b/test/cli/needle_options_test.cpp @@ -1,26 +1,26 @@ #include // strings -#include "cli_test.hpp" +#include "../app_test.hpp" -struct needle_options_test : public cli_test {}; +struct needle_options_test : public app_test {}; TEST_F(needle_options_test, no_options) { - cli_test_result result = execute_app("needle"); + app_test_result result = execute_app(); std::string expected { "needle\n" "======\n" " Try -h or --help for more information.\n" }; - EXPECT_EQ(result.exit_code, 0); + EXPECT_SUCCESS(result); EXPECT_EQ(result.out, expected); EXPECT_EQ(result.err, std::string{}); } TEST_F(needle_options_test, fail_no_argument) { - cli_test_result result = execute_app("needle", "-v"); + app_test_result result = execute_app("-v"); std::string expected { "Error. Incorrect command. See needle help for more information.You either forgot or misspelled the subcommand!"