source: trunk/test/multiprocess.cc @ 4044

Last change on this file since 4044 was 4044, checked in by Peter, 9 months ago

new function multiprocess; closes #958

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: multiprocess.cc 4044 2021-03-01 05:12:06Z peter $
2
3/*
4  Copyright (C) 2021 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 <config.h>
23
24#include "Suite.h"
25
26#include "yat/omic/VCF.h"
27#include "yat/omic/VcfCompare.h"
28#include "yat/omic/VcfFile.h"
29#include "yat/omic/VcfHeader.h"
30#include "yat/omic/VcfIterator.h"
31
32#include "yat/utility/multiprocess.h"
33
34#include <algorithm>
35#include <iterator>
36
37using namespace theplu::yat;
38
39struct Processor
40{
41  bool operator()(omic::VCF& vcf) const
42  {
43    if (vcf.n_alleles() != 1)
44      return false;
45    vcf.id(".");
46    return true;
47  }
48};
49
50
51struct IntFunction
52{
53  bool operator()(int s) const
54  {
55    return true;
56  }
57};
58
59
60int main(int argc, char* argv[])
61{
62  test::Suite suite(argc, argv);
63  omic::VcfFile file("../../data/foo.vcf.gz");
64  omic::VcfCompare compare(file.header());
65  omic::VcfIterator vcf(file);
66  omic::VcfIterator end;
67  std::vector<omic::VCF> result;
68  Processor processor;
69
70  utility::multiprocess(vcf, end, std::back_inserter(result),
71                        100, 4, 100, processor, compare);
72
73  if (result.size() != 7) {
74    suite.add(false);
75    suite.err() << "error: " << result.size()
76                << " resulting entries; expected 8\n";
77  }
78  if (std::is_sorted(result.begin(), result.end(), compare)==false) {
79    suite.add(false);
80    suite.err() << "result is not sorted\n";
81    std::copy(result.begin(), result.end(),
82              std::ostream_iterator<omic::VCF>(suite.err(), "\n"));
83  }
84
85  // test that shorter version compiles
86  std::vector<int> input;
87  std::vector<double> output;
88  IntFunction function;
89  utility::multiprocess(input.begin(), input.end(), output.begin(),
90                        10, 2, 100, function);
91
92  return suite.return_value();
93}
Note: See TracBrowser for help on using the repository browser.