1 | #include "../famfinder.h" |
---|
2 | |
---|
3 | #define BOOST_TEST_MODULE famfinder |
---|
4 | |
---|
5 | #include <boost/test/unit_test.hpp> |
---|
6 | #include <boost/test/data/test_case.hpp> |
---|
7 | namespace bdata = boost::unit_test::data; |
---|
8 | |
---|
9 | #include <boost/filesystem.hpp> |
---|
10 | namespace fs = boost::filesystem; |
---|
11 | |
---|
12 | #include <boost/program_options.hpp> |
---|
13 | namespace po = boost::program_options; |
---|
14 | |
---|
15 | #include <random> |
---|
16 | #include <set> |
---|
17 | #include <algorithm> |
---|
18 | #include <initializer_list> |
---|
19 | |
---|
20 | #include "../query_arb.h" |
---|
21 | |
---|
22 | using namespace sina; |
---|
23 | |
---|
24 | /** shuffles only the first n items **/ |
---|
25 | template<class ITER> |
---|
26 | ITER shuffle_n(ITER begin, ITER end, size_t n) { |
---|
27 | size_t items = std::distance(begin, end); |
---|
28 | while (n--) { |
---|
29 | ITER it = begin; |
---|
30 | int ran = std::rand() % items; |
---|
31 | std::advance(it, ran); |
---|
32 | std::swap(*begin, *it); |
---|
33 | --items, ++begin; |
---|
34 | } |
---|
35 | return begin; |
---|
36 | } |
---|
37 | |
---|
38 | struct Fixture { |
---|
39 | query_arb *arbdb; |
---|
40 | std::vector<std::string> ids; |
---|
41 | const unsigned int N{20}; |
---|
42 | const unsigned int M{50}; |
---|
43 | |
---|
44 | Fixture() { |
---|
45 | std::srand(1234); |
---|
46 | int argc = boost::unit_test::framework::master_test_suite().argc; |
---|
47 | char** argv = boost::unit_test::framework::master_test_suite().argv; |
---|
48 | BOOST_REQUIRE(argc>1); |
---|
49 | fs::path database = argv[1]; |
---|
50 | BOOST_TEST_MESSAGE("Loading test database " << database << " for testing"); |
---|
51 | arbdb = query_arb::getARBDB(database); |
---|
52 | ids = arbdb->getSequenceNames(); |
---|
53 | BOOST_REQUIRE(ids.size() > N); |
---|
54 | shuffle_n(ids.begin(), ids.end(), N); |
---|
55 | } |
---|
56 | |
---|
57 | ~Fixture() { |
---|
58 | BOOST_TEST_MESSAGE("Destroying fixture"); |
---|
59 | } |
---|
60 | }; |
---|
61 | |
---|
62 | |
---|
63 | void configure(std::initializer_list<const char*> l) { |
---|
64 | const char* cmd[l.size()+1]; |
---|
65 | cmd[0] = "sina"; |
---|
66 | int i = 1; |
---|
67 | for (auto lv : l) { |
---|
68 | cmd[i++] = lv; |
---|
69 | } |
---|
70 | po::variables_map vm; |
---|
71 | po::options_description od, adv_od; |
---|
72 | famfinder::get_options_description(od, adv_od); |
---|
73 | od.add(adv_od); |
---|
74 | po::store( |
---|
75 | po::parse_command_line(l.size()+1, cmd, od), |
---|
76 | vm); |
---|
77 | try { |
---|
78 | //BOOST_TEST(vm["db"].as<fs::path>() == "test_data/ltp_reduced.arb"); |
---|
79 | po::notify(vm); |
---|
80 | famfinder::validate_vm(vm, od); |
---|
81 | } catch (std::logic_error &e) { |
---|
82 | BOOST_TEST(e.what() == ""); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | BOOST_AUTO_TEST_SUITE(famfinder_tests) |
---|
87 | |
---|
88 | |
---|
89 | BOOST_DATA_TEST_CASE_F(Fixture, turn, bdata::make({"internal", "pt-server"}), engine) { |
---|
90 | configure({"--db", arbdb->getFileName().c_str(), "--fs-engine", engine}); |
---|
91 | |
---|
92 | famfinder finder; |
---|
93 | |
---|
94 | for (unsigned int i = 0; i < N; i++) { |
---|
95 | cseq query = arbdb->getCseq(ids[i]); |
---|
96 | BOOST_TEST_CONTEXT("Test " << i << "(sequence " << query.getName() << ")") { |
---|
97 | BOOST_TEST_INFO("Unturned; just revcomp"); |
---|
98 | BOOST_TEST(finder.turn_check(query, false) == 0); |
---|
99 | BOOST_TEST_INFO("Unturned; all orientations"); |
---|
100 | BOOST_TEST(finder.turn_check(query, true) == 0); |
---|
101 | query.reverse(); |
---|
102 | BOOST_TEST_INFO("Reversed; all orientations"); |
---|
103 | BOOST_TEST(finder.turn_check(query, true) == 1); |
---|
104 | query.complement(); |
---|
105 | BOOST_TEST_INFO("Revcomp'ed; just revcomp"); |
---|
106 | BOOST_TEST(finder.turn_check(query, false) == 3); |
---|
107 | BOOST_TEST_INFO("Revcomp'ed; all orientations"); |
---|
108 | BOOST_TEST(finder.turn_check(query, true) == 3); |
---|
109 | query.reverse(); |
---|
110 | BOOST_TEST_INFO("Comp'ed; all orientations"); |
---|
111 | BOOST_TEST(finder.turn_check(query, true) == 2); |
---|
112 | } |
---|
113 | std::cerr << "."; |
---|
114 | } |
---|
115 | std::cerr << std::endl; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | BOOST_AUTO_TEST_SUITE_END(); // famfinder_tests |
---|
121 | |
---|
122 | /* |
---|
123 | Local Variables: |
---|
124 | mode:c++ |
---|
125 | c-file-style:"stroustrup" |
---|
126 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
---|
127 | indent-tabs-mode:nil |
---|
128 | fill-column:99 |
---|
129 | End: |
---|
130 | */ |
---|
131 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
---|