source: trunk/test/index_test.cc @ 1237

Last change on this file since 1237 was 1237, checked in by Peter, 15 years ago

working on #223

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: index_test.cc 1237 2008-03-15 16:58:34Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Suite.h"
25
26#include "yat/utility/Index.h"
27#include "yat/utility/SmartPtr.h"
28
29#include <fstream>
30#include <iostream>
31#include <vector>
32
33int main(int argc, char* argv[])
34{ 
35  using namespace theplu::yat;
36  using utility::Index;
37
38  test::Suite suite(argc, argv);
39  suite.err() << "testing Index" << std::endl;
40
41  Index index;
42  if (index.size()){
43    suite.add(false);
44    suite.err() << "Default constructor failed\n";
45  }
46
47  Index index2(10);
48  if (index2.size()!=10){
49    suite.add(false);
50    suite.err() << "Constructor Index(10) failed\n";
51  }
52  for (size_t i=0; i<index2.size(); ++i)
53    if (index2[i]!=i){
54      suite.add(false);
55      suite.err() << "index[" << i << "]=" << index2[i] << " expected " << i
56             << "\n";
57    }
58
59  std::vector<size_t> vec;
60  vec.push_back(1);
61  vec.push_back(3);
62  vec.push_back(5);
63  utility::SmartPtr<const std::vector<size_t> > 
64    sp(new const std::vector<size_t>(vec));
65  Index index3(sp);
66  if (index3.size()!=vec.size()){
67    suite.add(false);
68    suite.err() << "Constructor from SmartPtr failed\n";
69  }
70  for (size_t i=0; i<index3.size(); ++i)
71    if (index3[i]!=vec[i]){
72      suite.add(false);
73      suite.err() << "index[" << i << "]=" << index3[i] << " expected " << vec[i] 
74             << "\n";
75    }
76
77  suite.err() << "  testing creation of sub index\n";
78  Index index4(index2, index3);
79  if (index4.size()!=index3.size()){
80    suite.add(false);
81    suite.err() << "failed\n";
82  }
83  for (size_t i=0; i<index4.size(); ++i)
84    if (index4[i]!=index2[index3[i]]){
85      suite.add(false);
86      suite.err() << "index[" << i << "]=" << index4[i] << " expected " 
87             << index2[index3[i]] << "\n";
88    }
89
90  Index index5(index4);
91  if (index5.size()!=index4.size()){
92    suite.add(false);
93    suite.err() << "failed\n";
94  }
95  for (size_t i=0; i<index5.size(); ++i)
96    if (index5[i]!=index4[i]){
97      suite.add(false);
98      suite.err() << "index[" << i << "]=" << index5[i] << " expected " 
99             << index4[i] << "\n";
100    }
101   
102  return suite.return_value();
103}
Note: See TracBrowser for help on using the repository browser.