Skip to content

Commit cc6203b

Browse files
committed
format unit tests 2
1 parent b6f285e commit cc6203b

File tree

1 file changed

+42
-73
lines changed

1 file changed

+42
-73
lines changed

test/unit/format/sam_input_test_template.hpp

Lines changed: 42 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,37 @@ using seqan3::operator""_tag;
3131

3232
// global variables for reuse
3333
bio::map_io::reader_options default_options{};
34-
constexpr std::string_view warning_prefix{"[B.I.O sam format warning in line "};
34+
constexpr std::string_view warning_prefix{"[B.I.O sam format warning in line "};
3535

3636
struct sam_file_data : public ::testing::Test
3737
{
3838
sam_file_data()
3939
{
4040
ref_sequences = std::vector<seqan3::dna5_vector>{ref_seq};
41-
ref_ids = std::vector<std::string>{ref_id};
42-
header = seqan3::sam_file_header{ref_ids};
41+
ref_ids = std::vector<std::string>{ref_id};
42+
header = seqan3::sam_file_header{ref_ids};
4343
header.ref_id_info.emplace_back(ref_seq.size(), "");
4444
header.ref_dict[header.ref_ids()[0]] = 0; // set up header which is otherwise done on file level
4545
}
4646

47-
std::vector<seqan3::dna5_vector> seqs
48-
{
49-
"ACGT"_dna5,
50-
"AGGCTGNAG"_dna5,
51-
"GGAGTATA"_dna5
52-
};
47+
std::vector<seqan3::dna5_vector> seqs{"ACGT"_dna5, "AGGCTGNAG"_dna5, "GGAGTATA"_dna5};
5348

54-
std::vector<std::string> ids
55-
{
56-
"read1",
57-
"read2",
58-
"read3"
59-
};
49+
std::vector<std::string> ids{"read1", "read2", "read3"};
6050

61-
std::vector<std::vector<seqan3::phred42>> quals
62-
{
63-
{ "!##$"_phred42 },
64-
{ "!##$&'()*"_phred42 },
65-
{ "!!*+,-./"_phred42 },
51+
std::vector<std::vector<seqan3::phred42>> quals{
52+
{"!##$"_phred42},
53+
{"!##$&'()*"_phred42},
54+
{"!!*+,-./"_phred42},
6655
};
6756

68-
std::vector<int32_t> offsets
69-
{
70-
1,
71-
0,
72-
1
73-
};
57+
std::vector<int32_t> offsets{1, 0, 1};
7458

7559
seqan3::dna5_vector ref_seq = "ACTGATCGAGAGGATCTAGAGGAGATCGTAGGAC"_dna5;
7660

7761
std::string ref_id = "ref";
7862

7963
std::vector<int32_t> positions // 1-based in b.i.o. 0-based in seqan3
80-
{
81-
1,
82-
2,
83-
3
84-
};
64+
{1, 2, 3};
8565

8666
std::vector<std::vector<seqan3::cigar>> cigars
8767
{
@@ -111,36 +91,25 @@ struct sam_file_data : public ::testing::Test
11191
{1, 'S'_cigar_operation}}
11292
};
11393

114-
std::vector<bio::map_io::sam_flag> flags
115-
{
116-
bio::map_io::sam_flag{41u},
117-
bio::map_io::sam_flag{42u},
118-
bio::map_io::sam_flag{43u}
119-
};
94+
std::vector<bio::map_io::sam_flag> flags{bio::map_io::sam_flag{41u},
95+
bio::map_io::sam_flag{42u},
96+
bio::map_io::sam_flag{43u}};
12097

121-
std::vector<uint8_t> mapqs
122-
{
123-
61u,
124-
62u,
125-
63u
126-
};
98+
std::vector<uint8_t> mapqs{61u, 62u, 63u};
12799

128100
std::vector<std::tuple<std::optional<int32_t>, std::optional<int32_t>, int32_t>> mates // position 1-based
129-
{
101+
{
130102
{0, 10, 300},
131103
{0, 10, 300},
132104
{0, 10, 300}
133105
};
134106

135-
std::vector<bio::map_io::sam_tag_dictionary> tag_dicts
136-
{
137-
bio::map_io::sam_tag_dictionary{},
138-
bio::map_io::sam_tag_dictionary{},
139-
bio::map_io::sam_tag_dictionary{}
140-
};
107+
std::vector<bio::map_io::sam_tag_dictionary> tag_dicts{bio::map_io::sam_tag_dictionary{},
108+
bio::map_io::sam_tag_dictionary{},
109+
bio::map_io::sam_tag_dictionary{}};
141110

142-
std::vector<seqan3::dna5_vector> ref_sequences{};
143-
std::vector<std::string> ref_ids{};
111+
std::vector<seqan3::dna5_vector> ref_sequences{};
112+
std::vector<std::string> ref_ids{};
144113
seqan3::sam_file_header<std::vector<std::string>> header{};
145114
};
146115

@@ -177,24 +146,24 @@ TYPED_TEST_P(sam_file_read, full_data_set)
177146
typename TestFixture::stream_type istream{this->verbose_reads_input};
178147
using record_t = bio::record<decltype(default_options.field_ids), decltype(default_options.field_types)>;
179148
bio::format_input_handler<bio::sam> input_handler{istream, default_options};
180-
record_t rec;
149+
record_t rec;
181150

182151
for (unsigned i = 0; i < 3; ++i)
183152
{
184153
input_handler.parse_next_record_into(rec);
185154

186-
EXPECT_EQ(rec.id(), this->ids[i]) << "failed at i = " << i << std::endl;
187-
EXPECT_EQ(rec.flag(), this->flags[i]) << "failed at i = " << i << std::endl;
188-
EXPECT_EQ(rec.rname(), this->ref_id) << "failed at i = " << i << std::endl;
189-
EXPECT_EQ(rec.pos(), this->positions[i]) << "failed at i = " << i << std::endl;
190-
EXPECT_EQ(rec.mapq(), this->mapqs[i]) << "failed at i = " << i << std::endl;
155+
EXPECT_EQ(rec.id(), this->ids[i]) << "failed at i = " << i << std::endl;
156+
EXPECT_EQ(rec.flag(), this->flags[i]) << "failed at i = " << i << std::endl;
157+
EXPECT_EQ(rec.rname(), this->ref_id) << "failed at i = " << i << std::endl;
158+
EXPECT_EQ(rec.pos(), this->positions[i]) << "failed at i = " << i << std::endl;
159+
EXPECT_EQ(rec.mapq(), this->mapqs[i]) << "failed at i = " << i << std::endl;
191160
EXPECT_RANGE_EQ(rec.cigar(), this->cigars[i]);
192-
EXPECT_EQ(rec.rnext(), this->ref_id) << "failed at i = " << i << std::endl;
193-
EXPECT_EQ(rec.pnext(), std::get<1>(this->mates[i])) << "failed at i = " << i << std::endl;
194-
EXPECT_EQ(rec.tlen(), std::get<2>(this->mates[i])) << "failed at i = " << i << std::endl;
195-
EXPECT_RANGE_EQ(rec.seq(), this->seqs[i]);
196-
EXPECT_RANGE_EQ(rec.qual(), this->quals[i]);
197-
EXPECT_EQ(rec.tags(), this->tag_dicts[i]) << "failed at i = " << i << std::endl;
161+
EXPECT_EQ(rec.rnext(), this->ref_id) << "failed at i = " << i << std::endl;
162+
EXPECT_EQ(rec.pnext(), std::get<1>(this->mates[i])) << "failed at i = " << i << std::endl;
163+
EXPECT_EQ(rec.tlen(), std::get<2>(this->mates[i])) << "failed at i = " << i << std::endl;
164+
EXPECT_RANGE_EQ(rec.seq(), this->seqs[i]);
165+
EXPECT_RANGE_EQ(rec.qual(), this->quals[i]);
166+
EXPECT_EQ(rec.tags(), this->tag_dicts[i]) << "failed at i = " << i << std::endl;
198167
}
199168
}
200169

@@ -204,7 +173,7 @@ TYPED_TEST_P(sam_file_read, all_missing_data)
204173

205174
using record_t = bio::record<decltype(default_options.field_ids), decltype(default_options.field_types)>;
206175
bio::format_input_handler<bio::sam> input_handler{istream, default_options};
207-
record_t rec;
176+
record_t rec;
208177

209178
input_handler.parse_next_record_into(rec);
210179

@@ -227,12 +196,12 @@ TYPED_TEST_P(sam_file_read, select_fields)
227196
{
228197
typename TestFixture::stream_type istream{this->verbose_reads_input};
229198

230-
constexpr auto fid = bio::vtag<bio::field::rname, bio::field::pos>;
199+
constexpr auto fid = bio::vtag<bio::field::rname, bio::field::pos>;
231200
constexpr auto ftype = bio::ttag<std::string_view, int64_t>;
232201

233202
using record_t = bio::record<std::remove_cvref_t<decltype(fid)>, std::remove_cvref_t<decltype(ftype)>>;
234203
bio::format_input_handler<bio::sam> input_handler{istream, default_options};
235-
record_t rec;
204+
record_t rec;
236205

237206
for (unsigned i = 0; i < 3; ++i)
238207
{
@@ -246,12 +215,12 @@ TYPED_TEST_P(sam_file_read, warning_rname_not_in_header)
246215
{
247216
typename TestFixture::stream_type istream{this->verbose_reads_input};
248217

249-
constexpr auto fid = bio::vtag<bio::field::rname, bio::field::pos>;
218+
constexpr auto fid = bio::vtag<bio::field::rname, bio::field::pos>;
250219
constexpr auto ftype = bio::ttag<std::string_view, int64_t>;
251220

252221
using record_t = bio::record<std::remove_cvref_t<decltype(fid)>, std::remove_cvref_t<decltype(ftype)>>;
253222
bio::format_input_handler<bio::sam> input_handler{istream, default_options};
254-
record_t rec;
223+
record_t rec;
255224

256225
std::string warning_msg{warning_prefix.data() + std::string{"1] The reference sequence name \""} + this->ref_id +
257226
"\" is not present in the header.\n"};
@@ -271,12 +240,12 @@ TYPED_TEST_P(sam_file_read, warning_rnext_not_in_header)
271240
{
272241
typename TestFixture::stream_type istream{this->verbose_reads_input};
273242

274-
constexpr auto fid = bio::vtag<bio::field::rnext, bio::field::pnext>;
243+
constexpr auto fid = bio::vtag<bio::field::rnext, bio::field::pnext>;
275244
constexpr auto ftype = bio::ttag<std::string_view, int64_t>;
276245

277246
using record_t = bio::record<std::remove_cvref_t<decltype(fid)>, std::remove_cvref_t<decltype(ftype)>>;
278247
bio::format_input_handler<bio::sam> input_handler{istream, default_options};
279-
record_t rec;
248+
record_t rec;
280249

281250
std::string warning_msg{warning_prefix.data() + std::string{"1] The mates reference sequence name \""} +
282251
this->ref_id + "\" is not present in the header.\n"};
@@ -296,12 +265,12 @@ TYPED_TEST_P(sam_file_read, format_error_uneven_hexadecimal_tag)
296265
{
297266
typename TestFixture::stream_type istream{this->wrong_hexadecimal_tag};
298267

299-
constexpr auto fid = bio::vtag<bio::field::tags>;
268+
constexpr auto fid = bio::vtag<bio::field::tags>;
300269
constexpr auto ftype = bio::ttag<bio::map_io::sam_tag_dictionary>;
301270

302271
using record_t = bio::record<std::remove_cvref_t<decltype(fid)>, std::remove_cvref_t<decltype(ftype)>>;
303272
bio::format_input_handler<bio::sam> input_handler{istream, default_options};
304-
record_t rec;
273+
record_t rec;
305274

306275
EXPECT_THROW(input_handler.parse_next_record_into(rec), bio::format_error);
307276
}

0 commit comments

Comments
 (0)