source: trunk/PARSIMONY/test_env.h

Last change on this file was 16880, checked in by westram, 7 years ago
  • reintegrates 'multicore' into 'trunk'
    • derive sequence classes able to be combined from new class AP_combinableSeq
      • elim dummy functions from rest of hierarchy
    • implements non-writing combine for add-species (speedup: 25-35%)
    • introduce type Mutations ⇒ uses long everywhere (before mostly, but not always used float)
    • allows use of futures
      • nucleotide combine is able to calculate async (disabled via define atm → NEVER_COMBINE_ASYNC; needs more work on calling algorithm)
  • adds: log:branches/multicore@16769:16879
File size: 5.1 KB
Line 
1// ================================================================= //
2//                                                                   //
3//   File      : test_env.h                                          //
4//   Purpose   : parsimony unittest toolkit                          //
5//                                                                   //
6//   Coded by Ralf Westram (coder@reallysoft.de) in September 2014   //
7//   http://www.arb-home.de/                                         //
8//                                                                   //
9// ================================================================= //
10
11#ifndef TEST_ENV_H
12#define TEST_ENV_H
13
14void fake_AW_init_color_groups();
15
16template<typename SEQTYPE>
17struct fake_agt FINAL_TYPE : public AWT_graphic_parsimony, virtual Noncopyable {
18    SEQTYPE *templ;
19    LocallyModify<int> permit_flag_updates; // w/o need for AWT_auto_refresh instances in unit tests
20
21    fake_agt(ArbParsimony& parsimony_)
22        : AWT_graphic_parsimony(parsimony_, ap_main->get_gb_main(), NULp),
23          templ(NULp),
24          permit_flag_updates(exports.get_modifying_flag_ref(), -1)
25    {}
26    ~fake_agt() OVERRIDE {
27        delete templ;
28    }
29    void init(AliView *aliview) {
30        fake_AW_init_color_groups(); // acts like color_groups were active
31        delete templ;
32        templ = aliview->has_data() ? new SEQTYPE(aliview) : NULp;
33        AWT_graphic_parsimony::init(aliview, templ, true, false);
34    }
35
36    void read_tree_settings() OVERRIDE {
37        // only needs to set members needed to compute_tree()
38        groupScale.pow    = .33;
39        groupScale.linear = 1.0;
40    }
41};
42
43
44template<typename SEQTYPE>
45class PARSIMONY_testenv : virtual Noncopyable {
46    GB_shell           shell;
47    AP_main            apMain;
48    fake_agt<SEQTYPE> *agt;
49    ArbParsimony       parsimony;
50    long               prev_combine_count;
51    KL_Settings       *klSettings;
52
53    void common_init(const char *dbname) {
54        apMain.open(dbname);
55
56        TEST_EXPECT_NULL(ap_main);
57        ap_main = &apMain;
58
59        agt = new fake_agt<SEQTYPE>(parsimony);
60        parsimony.set_tree(agt);
61
62        prev_combine_count = AP_combinableSeq::combine_count();
63    }
64
65public:
66    PARSIMONY_testenv(const char *dbname)
67        : parsimony(),
68          klSettings(NULp)
69    {
70        common_init(dbname);
71        agt->init(new AliView(ap_main->get_gb_main()));
72    }
73    PARSIMONY_testenv(const char *dbname, const char *aliName);
74    ~PARSIMONY_testenv() {
75        if (root_node()) {
76            AP_tree_edge::destroy(root_node());
77        }
78
79        TEST_EXPECT_EQUAL(ap_main, &apMain);
80        ap_main = NULp;
81
82        delete agt;
83        delete klSettings;
84
85        ap_assert(prev_combine_count == AP_combinableSeq::combine_count()); // please add tests documenting combines_performed()
86    }
87
88    AP_tree_nlen *root_node() {
89        AP_tree_nlen *root = apMain.get_root_node();
90        ap_assert(root == graphic_tree()->get_root_node());
91        return root;
92    }
93    AP_pars_root *tree_root() { return agt->get_tree_root(); }
94
95    GB_ERROR load_tree(const char *tree_name) {
96        GBDATA         *gb_main = ap_main->get_gb_main();
97        GB_transaction  ta(gb_main);     // @@@ do inside AWT_graphic_tree::load?
98        GB_ERROR        error   = agt->load_from_DB(gb_main, tree_name);
99        if (!error) {
100            AP_tree_edge::initialize(rootNode());   // builds edges
101
102            ap_assert(root_node());
103            ap_assert(root_node() == rootNode()); // need tree-access via global 'ap_main' (too much code is based on that)
104            ap_assert(rootEdge());
105
106            ASSERT_VALID_TREE(root_node());
107        }
108        return error;
109    }
110
111    void push() { apMain.remember(); }
112    void push_whole_tree() { apMain.remember_whole_tree(); }
113    void pop() { apMain.revert(); }
114    void accept() { apMain.accept(); }
115    void accept_if(bool cond) { apMain.accept_if(cond); }
116
117#if defined(ASSERTION_USED) || defined(UNIT_TESTS)
118    Validity pop_will_produce_valid_tree() { return apMain.revert_will_produce_valid_tree(); }
119    Validity all_available_pops_will_produce_valid_trees() { return apMain.all_available_reverts_will_produce_valid_trees(); }
120#endif
121
122    Level get_frame_level() { return apMain.get_frameLevel(); }
123    Level get_user_push_counter() { return apMain.get_user_push_counter(); }
124
125    AWT_graphic_parsimony *graphic_tree() { return agt; }
126
127    GBDATA *gbmain() const { return apMain.get_gb_main(); }
128
129    long combines_performed() {
130        long performed     = AP_combinableSeq::combine_count()-prev_combine_count;
131        prev_combine_count = AP_combinableSeq::combine_count();
132        return performed;
133    }
134
135    void compute_tree() { root_node()->compute_tree(); }
136
137    KL_Settings& get_KL_settings() {
138        ap_assert(klSettings);
139        return *klSettings;
140    }
141
142#if defined(PROVIDE_PRINT)
143    void dump2file(const char *name) { apMain.dump2file(name); }
144#endif
145};
146
147// ---------------------------
148//      expected combines
149
150# define TEST_EXPECT_COMBINES_PERFORMED(env,expComb) TEST_EXPECT_EQUAL((env).combines_performed(), expComb)
151
152
153#else
154#error test_env.h included twice
155#endif // TEST_ENV_H
156
157
Note: See TracBrowser for help on using the repository browser.