libsequence  1.9.5
fastqIO.cc
1 
2 #include <Sequence/fastq.hpp>
3 #include <fstream>
4 #include <boost/test/unit_test.hpp>
5 #include <unistd.h>
6 #include <iterator>
7 #include <iostream>
8 #include <stdexcept>
9 
10 BOOST_AUTO_TEST_SUITE(FASTQIOTest)
11 
12 BOOST_AUTO_TEST_CASE( input_test )
13 {
14  std::ifstream in("data/data.fastq");
15  if (!in)
16  {
17  std::cerr << "Error, couldn't find input file!\n";
18  exit(1);
19  }
21 
22  unsigned count = 0;
23  BOOST_REQUIRE_NO_THROW
24  (
25  while(!in.eof())
26  {
27  in >> f >> std::ws;
28  ++count;
29  }
30  );
31  BOOST_CHECK_EQUAL(count,50);
32 }
33 
34 BOOST_AUTO_TEST_CASE( input_test2 )
35 {
36  std::ifstream in("data/data.fastq");
37  if (!in)
38  {
39  std::cerr << "Error, couldn't find input file!\n";
40  exit(1);
41  }
43 
44  unsigned count = 0;
45  BOOST_REQUIRE_NO_THROW
46  (
47  unsigned count = 0;
48  std::istream_iterator<Sequence::fastq> i(in);
49  for( ; i != std::istream_iterator<Sequence::fastq>() ; ++i )
50  {
51  ++count;
52  }
53  BOOST_CHECK_EQUAL(count,50);
54  in.close();
55  );
56 }
57 
58 BOOST_AUTO_TEST_CASE( output_test )
59 {
60  BOOST_REQUIRE_NO_THROW
61  (
62  std::ifstream in("data/data.fastq");
63  if (!in)
64  {
65  std::cerr << "Error, couldn't find input file!\n";
66  exit(1);
67  }
68 
70 
71  std::vector<Sequence::fastq> vf;
72  std::ofstream out("fastqIOtest.txt");
73  unsigned count = 0;
74  while(!in.eof())
75  {
76  in >> f >> std::ws;
77  f.repname(false);
78  vf.push_back(f);
79  out << f << '\n';
80  ++count;
81  }
82  BOOST_CHECK_EQUAL(count,50);
83  out.close();
84  in.close();
85  in.open("fastqIOtest.txt");
86  count = 0;
87  while(!in.eof())
88  {
89  in >> f >> std::ws;
90  BOOST_CHECK_EQUAL(f,vf[count]);
91  ++count;
92  }
93  unlink("fastqIOtest.txt");
94  in.close();
95  );
96 }
97 BOOST_AUTO_TEST_SUITE_END()
void repname(const bool &)
Set to true or false for repeating the seq name on third line of output.
Definition: fastq.cc:32
FASTQ class.