OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
ManagedIDsTest.cpp
Go to the documentation of this file.
1 //
2 // Test ManagedIDsTest
3 //
4 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5 // All rights reserved
6 //
7 // Implemented as part of the PhD thesis
8 // "Toward massively parallel multi-objective optimization with application to
9 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #include "Util/ManagedIDs.h"
22 #include "gtest/gtest.h"
23 
24 namespace {
25 
26  // The fixture for testing class Foo.
27  class ManagedIDsTest : public ::testing::Test {
28  protected:
29 
30  ManagedIDsTest() {
31  // You can do set-up work for each test here.
32  ids_.reset(new ManagedIDs());
33  }
34 
35  virtual ~ManagedIDsTest() {
36  // You can do clean-up work that doesn't throw exceptions here.
37  }
38 
39  // If the constructor and destructor are not enough for setting up
40  // and cleaning up each test, you can define the following methods:
41 
42  virtual void SetUp() {
43  // Code here will be called immediately after the constructor (right
44  // before each test).
45  }
46 
47  virtual void TearDown() {
48  // Code here will be called immediately after each test (right
49  // before the destructor).
50  }
51 
52  // Objects declared here can be used by all tests in the test case
53  std::unique_ptr<ManagedIDs> ids_;
54  };
55 
56  TEST_F(ManagedIDsTest, OneID) {
57 
58  size_t id = ids_->nextID();
59  EXPECT_EQ(static_cast<size_t>(0), id) << "first id should be 0";
60  }
61 
62  TEST_F(ManagedIDsTest, IDsContinuous) {
63 
64  size_t id0 = ids_->nextID();
65  size_t id1 = ids_->nextID();
66  EXPECT_EQ(id0 + 1, id1);
67  }
68 
69  TEST_F(ManagedIDsTest, ReusingFreedIDs) {
70 
71  size_t id0 = ids_->nextID();
72  ids_->freeID(id0);
73  size_t id1 = ids_->nextID();
74  EXPECT_EQ(id0, id1);
75  }
76 
77 }
78 
79 int main(int argc, char **argv) {
80  ::testing::InitGoogleTest(&argc, argv);
81  return RUN_ALL_TESTS();
82 }
int main(int argc, char *argv[])
Definition: Main.cpp:139