source: trunk/test/index_test.cc @ 1619

Last change on this file since 1619 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

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