4 #include <boost/test/unit_test.hpp> 8 struct fasta_io_fixture
10 std::string name, seq, seq_left, seq_right;
12 : name{
"seqname is a seq" }, seq{
"AGCGTAGACAGTAGAGTGAT" },
13 seq_left{
"AGCGTAGAC" }, seq_right{
"AGTAGAGTGAT" }
18 BOOST_FIXTURE_TEST_SUITE(FastaIOTest,fasta_io_fixture)
20 BOOST_AUTO_TEST_CASE(ostream_test)
22 const char* filename =
"fasta_ostream_test_out.fasta";
24 std::ofstream o(filename);
27 std::ifstream in(filename);
29 BOOST_REQUIRE_EQUAL(f, f2);
33 BOOST_AUTO_TEST_CASE(ostream_test_3recs)
35 const char* filename =
"fasta_ostream_test_out.fasta";
37 std::ofstream o(filename);
38 o << f <<
'\n' << f <<
'\n' << f <<
'\n';
40 std::ifstream in(filename);
45 BOOST_REQUIRE_EQUAL(f.name, f2.name);
46 BOOST_REQUIRE_EQUAL(f.seq, f2.seq);
49 BOOST_REQUIRE_EQUAL(count, 3);
56 BOOST_AUTO_TEST_CASE(ostream_test_no_newline_end_of_file)
58 const char* filename =
"fasta_ostream_test_out.fasta";
60 std::ofstream o(filename);
61 o << f <<
'\n' << f <<
'\n' << f;
63 std::ifstream in(filename);
68 BOOST_REQUIRE_EQUAL(f.name, f2.name);
69 BOOST_REQUIRE_EQUAL(f.seq, f2.seq);
72 BOOST_REQUIRE_EQUAL(count, 3);
76 BOOST_AUTO_TEST_CASE(ostream_test_newline_within_seq)
78 const char* filename =
"fasta_ostream_test_out.fasta";
80 std::ofstream o(filename);
81 for (
unsigned i = 0; i < 3; ++i)
83 o << '>
' << name << '\n
' << seq_left << '\n
' << seq_right << '\n
'; 86 std::ifstream in(filename); 91 BOOST_REQUIRE_EQUAL(f.name, f2.name); 92 BOOST_REQUIRE_EQUAL(f.seq, f2.seq); 95 BOOST_REQUIRE_EQUAL(count, 3); 99 BOOST_AUTO_TEST_CASE(ostream_test_really_bad_input) 101 const char* filename = "fasta_ostream_test_out.fasta"; 102 Sequence::Fasta f(name, seq), f2; 103 std::ofstream o(filename); 104 for (unsigned i = 0; i < 3; ++i) 106 o << '>
' << name << '\n
' 107 << seq_left << "\n\n\n\n\n" //Bad bad bad 108 << seq_right << '\n
'; 111 std::ifstream in(filename); 116 BOOST_REQUIRE_EQUAL(f.name, f2.name); 117 BOOST_REQUIRE_EQUAL(f.seq, f2.seq); 120 BOOST_REQUIRE_EQUAL(count, 3); 124 BOOST_AUTO_TEST_CASE(ostream_test_really_bad_input_istream_iterator) 126 const char* filename = "fasta_ostream_test_out.fasta"; 127 Sequence::Fasta f(name, seq), f2; 128 std::ofstream o(filename); 129 for (unsigned i = 0; i < 3; ++i) 131 o << '>
' << name << '\n
' 132 << seq_left << "\n\n\n\n\n" //Bad bad bad 133 << seq_right << '\n
'; 136 std::ifstream in(filename); 138 std::istream_iterator<Sequence::Fasta> i(in); 139 for (; i != std::istream_iterator<Sequence::Fasta>(); ++i) 143 BOOST_REQUIRE_EQUAL(count, 3); 147 BOOST_AUTO_TEST_CASE(exception_test) 149 const char* filename = "fasta_ostream_test_out.fasta"; 150 std::ofstream out(filename); 151 //Write a badly-formatted FASTA record (we forgot the >) 152 out << name << '\n
' << seq; 155 std::ifstream in(filename); 157 BOOST_CHECK_THROW(in >> f >> std::ws, std::runtime_error); 161 BOOST_AUTO_TEST_SUITE_END()
Declaration of Sequence::Fasta streams.