annotate UnitTestsSources/TestStrategy.cpp @ 695:7bf91c4ebd65

strategy
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 17 May 2019 18:04:14 +0200
parents
children 14557e550920
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
695
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "gtest/gtest.h"
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <Core/OrthancException.h>
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <boost/noncopyable.hpp>
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <vector>
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace OrthancStone
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 class IFetchingStrategy : public boost::noncopyable
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 public:
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 virtual ~IFetchingStrategy()
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 virtual unsigned int GetItemsCount() const = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 virtual unsigned int GetMaxQuality() const = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 virtual bool GetNext(unsigned int& item,
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 unsigned int& quality) = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 virtual void SetCurrent(unsigned int item) = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 // Ask the strategy to re-schedule the item with the lowest
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 // priority in the fetching order. This allows to know which item
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 // should be dropped from a cache.
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 virtual void RecycleFurthest(unsigned int& item) = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 };
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 class IFetchingItemsSorter : public boost::noncopyable
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 public:
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 virtual ~IFetchingItemsSorter()
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 virtual unsigned int GetItemsCount() const = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 // Sort a set of items given the current item
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 virtual void Sort(std::vector<unsigned int>& target,
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 unsigned int current) = 0;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 };
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 class BasicFetchingItemsSorter : public IFetchingItemsSorter
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 private:
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 unsigned int itemsCount_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 public:
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 BasicFetchingItemsSorter(unsigned int itemsCount) :
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 itemsCount_(itemsCount)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 if (itemsCount == 0)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 virtual unsigned int GetItemsCount() const
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 return itemsCount_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 virtual void Sort(std::vector<unsigned int>& target,
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 unsigned int current)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 if (current >= itemsCount_)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 target.clear();
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 target.reserve(itemsCount_);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 target.push_back(current);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const unsigned int countBelow = current;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 const unsigned int countAbove = (itemsCount_ - 1) - current;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 const unsigned int n = std::min(countBelow, countAbove);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 for (unsigned int i = 1; i <= n; i++)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 assert(current + i < itemsCount_ &&
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 current >= i);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 target.push_back(current + i);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 target.push_back(current - i);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 for (unsigned int i = current - n; i > 0; i--)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 target.push_back(i - 1);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 for (unsigned int i = current + n + 1; i < itemsCount_; i++)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 target.push_back(i);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 assert(target.size() == itemsCount_);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 };
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 class BasicFetchingStrategy : public IFetchingStrategy
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 private:
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 struct Item
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 unsigned int item_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 unsigned int quality_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 };
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 std::auto_ptr<IFetchingItemsSorter> sorter_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 std::vector<unsigned int> nextQuality_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 unsigned int maxQuality_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 std::vector<Item> content_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 size_t currentItem_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 public:
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 BasicFetchingStrategy(IFetchingItemsSorter* sorter, // Takes ownership
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 unsigned int maxQuality) :
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 sorter_(sorter),
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 nextQuality_(sorter_->GetItemsCount(), 0),
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 maxQuality_(maxQuality),
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 currentItem_(0)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 if (sorter == NULL)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 SetCurrent(0);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 virtual unsigned int GetItemsCount() const
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 return sorter_->GetItemsCount();
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 virtual unsigned int GetMaxQuality() const
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 return maxQuality_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 virtual bool GetNext(unsigned int& item,
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 unsigned int& quality)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 if (currentItem_ >= content_.size())
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 return false;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 else
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 item = content_[currentItem_].item_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 quality = content_[currentItem_].quality_;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 assert(nextQuality_[item] <= quality);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 nextQuality_[item] = quality + 1;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return true;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 virtual void SetCurrent(unsigned int item)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 std::vector<unsigned int> v;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 sorter_->Sort(v, item);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 assert(v.size() == GetItemsCount());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 content_.clear();
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 content_.reserve(v.size() * maxQuality_);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 for (unsigned int q = 0; q < maxQuality_; q++)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 for (size_t i = 0; i < v.size(); i++)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 // Ask the strategy to re-schedule the item with the lowest
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 // priority in the fetching order. This allows to know which item
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 // should be dropped from a cache.
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 virtual void RecycleFurthest(unsigned int& item)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 };
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 TEST(BasicFetchingStrategy, Test)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(10), 3);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 TEST(BasicFetchingItemsSorter, Small)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 ASSERT_THROW(OrthancStone::BasicFetchingItemsSorter(0), Orthanc::OrthancException);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 std::vector<unsigned int> v;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 OrthancStone::BasicFetchingItemsSorter s(1);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 s.Sort(v, 0);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 ASSERT_EQ(1u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 ASSERT_EQ(0u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 ASSERT_THROW(s.Sort(v, 1), Orthanc::OrthancException);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 OrthancStone::BasicFetchingItemsSorter s(2);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 s.Sort(v, 0);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 ASSERT_EQ(2u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 ASSERT_EQ(0u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 ASSERT_EQ(1u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 s.Sort(v, 1);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 ASSERT_EQ(2u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ASSERT_EQ(1u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 ASSERT_EQ(0u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 ASSERT_THROW(s.Sort(v, 2), Orthanc::OrthancException);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 OrthancStone::BasicFetchingItemsSorter s(3);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 s.Sort(v, 0);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 ASSERT_EQ(3u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 ASSERT_EQ(0u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 ASSERT_EQ(1u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 ASSERT_EQ(2u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 s.Sort(v, 1);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 ASSERT_EQ(3u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 ASSERT_EQ(1u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 ASSERT_EQ(2u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 ASSERT_EQ(0u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 s.Sort(v, 2);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 ASSERT_EQ(3u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 ASSERT_EQ(2u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 ASSERT_EQ(1u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 ASSERT_EQ(0u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 ASSERT_THROW(s.Sort(v, 3), Orthanc::OrthancException);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 TEST(BasicFetchingItemsSorter, Odd)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 OrthancStone::BasicFetchingItemsSorter s(7);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 std::vector<unsigned int> v;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 ASSERT_THROW(s.Sort(v, 7), Orthanc::OrthancException);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 s.Sort(v, 0);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 ASSERT_EQ(0u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 ASSERT_EQ(1u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 ASSERT_EQ(2u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 ASSERT_EQ(3u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 ASSERT_EQ(4u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 ASSERT_EQ(5u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 ASSERT_EQ(6u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 s.Sort(v, 1);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 ASSERT_EQ(1u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 ASSERT_EQ(2u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 ASSERT_EQ(0u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 ASSERT_EQ(3u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ASSERT_EQ(4u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ASSERT_EQ(5u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 ASSERT_EQ(6u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 s.Sort(v, 2);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 ASSERT_EQ(2u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 ASSERT_EQ(3u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 ASSERT_EQ(1u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 ASSERT_EQ(4u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 ASSERT_EQ(0u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 ASSERT_EQ(5u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 ASSERT_EQ(6u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 s.Sort(v, 3);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 ASSERT_EQ(3u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 ASSERT_EQ(4u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 ASSERT_EQ(2u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 ASSERT_EQ(5u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 ASSERT_EQ(1u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 ASSERT_EQ(6u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 ASSERT_EQ(0u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 s.Sort(v, 4);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 ASSERT_EQ(4u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 ASSERT_EQ(5u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 ASSERT_EQ(3u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 ASSERT_EQ(6u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 ASSERT_EQ(2u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 ASSERT_EQ(1u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 ASSERT_EQ(0u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 s.Sort(v, 5);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 ASSERT_EQ(5u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 ASSERT_EQ(6u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 ASSERT_EQ(4u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 ASSERT_EQ(3u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 ASSERT_EQ(2u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 ASSERT_EQ(1u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 ASSERT_EQ(0u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 s.Sort(v, 6);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 ASSERT_EQ(7u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 ASSERT_EQ(6u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 ASSERT_EQ(5u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 ASSERT_EQ(4u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 ASSERT_EQ(3u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 ASSERT_EQ(2u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 ASSERT_EQ(1u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 ASSERT_EQ(0u, v[6]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 TEST(BasicFetchingItemsSorter, Even)
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 OrthancStone::BasicFetchingItemsSorter s(6);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 std::vector<unsigned int> v;
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 s.Sort(v, 0);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 ASSERT_EQ(6u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 ASSERT_EQ(0u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 ASSERT_EQ(1u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 ASSERT_EQ(2u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 ASSERT_EQ(3u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 ASSERT_EQ(4u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 ASSERT_EQ(5u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 s.Sort(v, 1);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 ASSERT_EQ(6u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 ASSERT_EQ(1u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 ASSERT_EQ(2u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 ASSERT_EQ(0u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 ASSERT_EQ(3u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 ASSERT_EQ(4u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 ASSERT_EQ(5u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 s.Sort(v, 2);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 ASSERT_EQ(6u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 ASSERT_EQ(2u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 ASSERT_EQ(3u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 ASSERT_EQ(1u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 ASSERT_EQ(4u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 ASSERT_EQ(0u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 ASSERT_EQ(5u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 s.Sort(v, 3);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 ASSERT_EQ(6u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 ASSERT_EQ(3u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 ASSERT_EQ(4u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 ASSERT_EQ(2u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 ASSERT_EQ(5u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 ASSERT_EQ(1u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 ASSERT_EQ(0u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 s.Sort(v, 4);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 ASSERT_EQ(6u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 ASSERT_EQ(4u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 ASSERT_EQ(5u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 ASSERT_EQ(3u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 ASSERT_EQ(2u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 ASSERT_EQ(1u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 ASSERT_EQ(0u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 s.Sort(v, 5);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 ASSERT_EQ(6u, v.size());
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 ASSERT_EQ(5u, v[0]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 ASSERT_EQ(4u, v[1]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 ASSERT_EQ(3u, v[2]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 ASSERT_EQ(2u, v[3]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 ASSERT_EQ(1u, v[4]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 ASSERT_EQ(0u, v[5]);
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
7bf91c4ebd65 strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }