source: trunk/test/gff.cc @ 2703

Last change on this file since 2703 was 2703, checked in by Peter, 11 years ago

merge release 0.8.1 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: gff.cc 2703 2012-03-12 06:43:10Z peter $
2
3/*
4  Copyright (C) 2011, 2012 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23
24#include "yat/omic/GFF2.h"
25#include "yat/omic/GFF3.h"
26
27#include <cassert>
28#include <fstream>
29
30using namespace theplu::yat;
31using namespace omic;
32
33template<typename T>
34void avoid_pedantic_warning(T t) {}
35
36void gff2(test::Suite&);
37void gff3(test::Suite&);
38
39template<class T>
40void test_gff(test::Suite&, GFF&);
41void test_ticket697(test::Suite&);
42
43int main(int argc, char* argv[])
44{
45  test::Suite suite(argc, argv);
46
47  gff2(suite);
48  gff3(suite);
49  test_ticket697(suite);
50
51  return suite.return_value();
52}
53
54
55void test_gff(test::Suite& suite, GFF& gff)
56{
57  std::string seqid = gff.seqid();
58  std::string source = gff.source();
59  std::string type = gff.type();
60  avoid_pedantic_warning<const std::string&>(gff.start());
61  avoid_pedantic_warning<const std::string&>(gff.end());
62  avoid_pedantic_warning<const std::string&>(gff.score());
63  avoid_pedantic_warning<const std::string&>(gff.strand());
64  avoid_pedantic_warning<const std::string&>(gff.phase());
65  const std::map<std::string, std::string>& m = gff.attributes();
66  avoid_pedantic_warning(m);
67}
68
69void gff2(test::Suite& suite)
70{
71  suite.out() << "testing GFF2\n";
72  std::ifstream is(test::filename("data/small.gff2").c_str());
73  assert(is);
74  GFF2 gff2;
75  suite.add(getline(is, gff2));
76  test_gff(suite, gff2);
77  const std::string& a = gff2.attribute("genotype");
78  if (!suite.add(a=="T or C"))
79    suite.err() << "incorrect genotype value: `" << a << "'\n"
80                << "expected: `T or C'\n";
81  is.close();
82}
83
84void gff3(test::Suite& suite)
85{
86  suite.out() << "testing GFF3\n";
87  std::ifstream is(test::filename("data/small.gff3").c_str());
88  assert(is);
89  GFF3 gff3;
90  if (!suite.add(getline(is, gff3)))
91    suite.err() << "getline failed\n";
92  test_gff(suite, gff3);
93  const std::string& a = gff3.attribute("genotype");
94  if (!suite.add(a=="T"))
95    suite.err() << "incorrect genotype value: `" << a << "'\n"
96                << "expected: `T'\n";
97  is.close();
98}
99
100
101void test_ticket697(test::Suite& suite)
102{
103  suite.out() << "test ticket 697\n";
104  GFF2 gff;
105  std::ifstream is(test::filename("data/small.gff2").c_str());
106  assert(is);
107  getline(is, gff);
108  if (gff.attribute("genotype")!="T or C") {
109    suite.add(false);
110    suite.err() << "error: incorrect genotype: '" << gff.attribute("genotype")
111                << "'; expected: 'T or C'\n";
112  }
113  getline(is, gff);
114  if (gff.attribute("genotype")!="T") {
115    suite.add(false);
116    suite.err() << "error: incorrect genotype: '" << gff.attribute("genotype")
117                << "'; expected: 'T'\n";
118  }
119  is.close();
120}
Note: See TracBrowser for help on using the repository browser.