test annotating a sequence with fasta records in a stream
[mussa.git] / alg / test / test_annotations.cpp
1 #define BOOST_AUTO_TEST_MAIN
2 #include <boost/test/auto_unit_test.hpp>
3
4 #include <boost/shared_ptr.hpp>
5 #include "annotations.hpp"
6 #include "mussa_exceptions.hpp"
7
8 BOOST_AUTO_TEST_CASE( annotations_constructors )
9 {
10   Annotations a;
11   BOOST_CHECK_EQUAL(a.name(), "");
12   
13   Annotations b("bee");
14   BOOST_CHECK_EQUAL(b.name(), "bee");
15   
16   boost::shared_ptr<Annotations> asp(new Annotations);
17   BOOST_CHECK_EQUAL(asp->name(), "");
18   
19   boost::shared_ptr<Annotations> bsp(new Annotations("bee pointer"));
20   BOOST_CHECK_EQUAL(bsp->name(), "bee pointer");
21 }
22
23 BOOST_AUTO_TEST_CASE( annotations_copy_constructor )
24 {
25   AnnotationsRef a(new Annotations("a"));
26   AnnotationsRef b(a);
27   AnnotationsRef c(new Annotations(a));
28
29   // b is a copy of a's pointer and thus changes
30   // to b update a   
31   b->setName("bee");
32   BOOST_CHECK_EQUAL(a->name(), "bee");
33   BOOST_CHECK_EQUAL(b->name(), "bee");
34
35   // c is a copy of a, and not a pointer to a
36   // so updates of a, b wont affect c and vice versa  
37   BOOST_CHECK_EQUAL(c->name(), "a");
38   c->setName("cee");
39   BOOST_CHECK_EQUAL(c->name(), "cee");
40
41   BOOST_CHECK_EQUAL(a->name(), "bee");
42   BOOST_CHECK_EQUAL(b->name(), "bee");
43   
44 }
45
46 BOOST_AUTO_TEST_CASE( annotations_get_metadata )
47 {
48   boost::shared_ptr<Annotations> asp(new Annotations("asp"));
49   asp->set("header", "> amsp");
50   
51   BOOST_CHECK_EQUAL( asp->size(), 2 );
52   BOOST_CHECK_EQUAL( asp->get("header"), "> amsp" );
53   BOOST_CHECK_THROW( asp->get("not there"), annotations_key_error ); 
54 }
55
56
57 BOOST_AUTO_TEST_CASE( annotations_getdefault_metadata )
58 {
59   boost::shared_ptr<Annotations> asp(new Annotations("asp"));
60   asp->set("header", "> amsp");
61   
62   BOOST_CHECK_EQUAL( asp->size(), 2 );
63   BOOST_CHECK_EQUAL( asp->getdefault("header", "foo"), "> amsp" );
64   BOOST_CHECK_EQUAL( asp->getdefault("not there", "foo"), "foo" ); 
65 }
66 BOOST_AUTO_TEST_CASE( annotations_has_key )
67 {
68   boost::shared_ptr<Annotations> asp(new Annotations("asp"));
69   asp->set("header", "> amsp");
70   
71   BOOST_CHECK_EQUAL(asp->has_key("header"), true);
72   BOOST_CHECK_EQUAL(asp->has_key("name"), true);
73   BOOST_CHECK_EQUAL(asp->has_key("secret"), false);
74 }
75