2 #include <Sequence/FastaExplicit.hpp> 4 #include <boost/test/unit_test.hpp> 8 std::string name(
"seqname is a seq"),seq(
"AGCGTAGACAGTAGAGTGAT"),seq_left(
"AGCGTAGAC"),seq_right(
"AGTAGAGTGAT");
11 BOOST_AUTO_TEST_CASE( ostream_test )
13 const char * filename =
"fasta_exp_ostream_test_out.fasta";
15 std::ofstream o(filename);
18 std::ifstream in(filename);
20 BOOST_REQUIRE_EQUAL(f,f2);
24 BOOST_AUTO_TEST_CASE( ostream_test_3recs )
26 const char * filename =
"fasta_exp_ostream_test_out.fasta";
28 std::ofstream o(filename);
33 std::ifstream in(filename);
38 BOOST_REQUIRE_EQUAL(f,f2);
41 BOOST_REQUIRE_EQUAL( count, 3 );
48 BOOST_AUTO_TEST_CASE( ostream_test_no_newline_end_of_file )
50 const char * filename =
"fasta_exp_ostream_test_out.fasta";
52 std::ofstream o(filename);
57 std::ifstream in(filename);
62 BOOST_REQUIRE_EQUAL(f,f2);
65 BOOST_REQUIRE_EQUAL( count, 3 );
69 BOOST_AUTO_TEST_CASE( ostream_test_newline_within_seq )
71 const char * filename =
"fasta_exp_ostream_test_out.fasta";
73 std::ofstream o(filename);
74 for (
unsigned i = 0 ; i < 3 ; ++i )
76 o << '>
' << name << '\n
' 81 std::ifstream in(filename); 86 BOOST_REQUIRE_EQUAL(f,f2); 89 BOOST_REQUIRE_EQUAL( count, 3 ); 93 BOOST_AUTO_TEST_CASE( ostream_test_really_bad_input ) 95 const char * filename = "fasta_exp_ostream_test_out.fasta"; 96 Sequence::Fasta f(name,seq),f2; 97 std::ofstream o(filename); 98 for ( unsigned i = 0 ; i < 3 ; ++i ) 100 o << '>
' << name << '\n
' 101 << seq_left << "\n\n\n\n\n" //Bad bad bad 102 << seq_right << '\n
'; 105 std::ifstream in(filename); 110 BOOST_REQUIRE_EQUAL(f,f2); 113 BOOST_REQUIRE_EQUAL( count, 3 ); 117 BOOST_AUTO_TEST_CASE( ostream_test_really_bad_input_istream_iterator ) 119 const char * filename = "fasta_exp_ostream_test_out.fasta"; 120 Sequence::Fasta f(name,seq),f2; 121 std::ofstream o(filename); 122 for ( unsigned i = 0 ; i < 3 ; ++i ) 124 o << '>
' << name << '\n
' 125 << seq_left << "\n\n\n\n\n" //Bad bad bad 126 << seq_right << '\n
'; 129 std::ifstream in(filename); 131 std::istream_iterator<Sequence::Fasta> i(in); 132 for( ; i != std::istream_iterator<Sequence::Fasta>() ; ++i ) 136 BOOST_REQUIRE_EQUAL( count, 3 ); 140 BOOST_AUTO_TEST_CASE( exception_test ) 142 const char * filename = "fasta_exp_ostream_test_out.fasta"; 143 std::ofstream out(filename); 144 //Write a badly-formatted FASTA record (we forgot the >) 145 out << name << '\n
' << seq; 148 std::ifstream in(filename); 150 BOOST_CHECK_THROW( in >> f >> std::ws, Sequence::badFormat ); 154 BOOST_AUTO_TEST_SUITE_END()