Mercurial > hg > orthanc-stone
annotate UnitTestsSources/TestStrategy.cpp @ 708:51976977d2d3
reorganization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 20 May 2019 11:20:01 +0200 |
parents | 14557e550920 |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
695 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "gtest/gtest.h" | |
23 | |
708 | 24 #include "../Framework/Loaders/BasicFetchingStrategy.h" |
25 #include "../Framework/Loaders/BasicFetchingItemsSorter.h" | |
695 | 26 |
708 | 27 #include <Core/OrthancException.h> |
695 | 28 |
29 | |
697
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
30 namespace |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
31 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
32 class StrategyTester : public boost::noncopyable |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
33 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
34 private: |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
35 std::map<unsigned int, unsigned int> qualities_; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
36 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
37 public: |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
38 bool IsValidCommand(unsigned int item, |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
39 unsigned int quality) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
40 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
41 if (qualities_.find(item) != qualities_.end() && |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
42 qualities_[item] >= quality) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
43 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
44 return false; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
45 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
46 else |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
47 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
48 qualities_[item] = quality; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
49 return true; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
50 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
51 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
52 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
53 bool HasFinished(OrthancStone::BasicFetchingStrategy& strategy) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
54 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
55 for (unsigned int i = 0; i < strategy.GetItemsCount(); i++) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
56 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
57 if (qualities_.find(i) == qualities_.end() || |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
58 qualities_[i] != strategy.GetMaxQuality()) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
59 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
60 return false; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
61 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
62 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
63 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
64 return true; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
65 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
66 }; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
67 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
68 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
69 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
70 TEST(BasicFetchingStrategy, Test1) |
695 | 71 { |
697
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
72 ASSERT_THROW(OrthancStone::BasicFetchingStrategy(NULL, 0), Orthanc::OrthancException); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
73 ASSERT_THROW(OrthancStone::BasicFetchingStrategy(new OrthancStone::BasicFetchingItemsSorter(0), 0), Orthanc::OrthancException); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
74 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
75 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
76 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(1), 0); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
77 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
78 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
79 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
80 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
81 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
82 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
83 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(1), 5); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
84 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
85 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(5u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
86 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
87 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
88 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
89 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
90 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(2), 2); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
91 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
92 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
93 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(1u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
94 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
95 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
96 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
97 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
98 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
99 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(3), 2); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
100 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
101 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
102 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(1u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
103 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(1u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
104 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
105 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
106 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
107 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
108 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
109 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
110 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(3), 2); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
111 s.SetBlockSize(1); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
112 s.SetCurrent(0); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
113 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
114 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
115 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(1u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
116 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
117 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
118 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(1u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
119 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(2u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
120 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
121 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
122 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
123 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
124 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(5), 0); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
125 ASSERT_THROW(s.SetCurrent(5), Orthanc::OrthancException); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
126 s.SetCurrent(2); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
127 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
128 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
129 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
130 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(3u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
131 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
132 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(4u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
133 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
134 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
135 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
136 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
137 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
138 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(5), 0); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
139 s.SetCurrent(4); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
140 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
141 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
142 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(4u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
143 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(3u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
144 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(2u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
145 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(1u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
146 ASSERT_TRUE(s.GetNext(i, q)); ASSERT_EQ(0u, i); ASSERT_EQ(0u, q); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
147 ASSERT_FALSE(s.GetNext(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
148 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
149 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
150 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
151 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
152 TEST(BasicFetchingStrategy, Test2) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
153 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
154 OrthancStone::BasicFetchingStrategy s(new OrthancStone::BasicFetchingItemsSorter(20), 2); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
155 ASSERT_EQ(20u, s.GetItemsCount()); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
156 ASSERT_EQ(2u, s.GetMaxQuality()); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
157 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
158 StrategyTester t; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
159 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
160 s.SetCurrent(10); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
161 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
162 unsigned int i, q; |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
163 while (s.GetNext(i, q)) |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
164 { |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
165 ASSERT_TRUE(t.IsValidCommand(i, q)); |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
166 } |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
167 |
14557e550920
BasicFetchingStrategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
695
diff
changeset
|
168 ASSERT_TRUE(t.HasFinished(s)); |
695 | 169 } |
170 | |
171 | |
172 | |
173 | |
174 TEST(BasicFetchingItemsSorter, Small) | |
175 { | |
176 ASSERT_THROW(OrthancStone::BasicFetchingItemsSorter(0), Orthanc::OrthancException); | |
177 std::vector<unsigned int> v; | |
178 | |
179 { | |
180 OrthancStone::BasicFetchingItemsSorter s(1); | |
181 s.Sort(v, 0); | |
182 ASSERT_EQ(1u, v.size()); | |
183 ASSERT_EQ(0u, v[0]); | |
184 | |
185 ASSERT_THROW(s.Sort(v, 1), Orthanc::OrthancException); | |
186 } | |
187 | |
188 { | |
189 OrthancStone::BasicFetchingItemsSorter s(2); | |
190 s.Sort(v, 0); | |
191 ASSERT_EQ(2u, v.size()); | |
192 ASSERT_EQ(0u, v[0]); | |
193 ASSERT_EQ(1u, v[1]); | |
194 | |
195 s.Sort(v, 1); | |
196 ASSERT_EQ(2u, v.size()); | |
197 ASSERT_EQ(1u, v[0]); | |
198 ASSERT_EQ(0u, v[1]); | |
199 | |
200 ASSERT_THROW(s.Sort(v, 2), Orthanc::OrthancException); | |
201 } | |
202 | |
203 { | |
204 OrthancStone::BasicFetchingItemsSorter s(3); | |
205 s.Sort(v, 0); | |
206 ASSERT_EQ(3u, v.size()); | |
207 ASSERT_EQ(0u, v[0]); | |
208 ASSERT_EQ(1u, v[1]); | |
209 ASSERT_EQ(2u, v[2]); | |
210 | |
211 s.Sort(v, 1); | |
212 ASSERT_EQ(3u, v.size()); | |
213 ASSERT_EQ(1u, v[0]); | |
214 ASSERT_EQ(2u, v[1]); | |
215 ASSERT_EQ(0u, v[2]); | |
216 | |
217 s.Sort(v, 2); | |
218 ASSERT_EQ(3u, v.size()); | |
219 ASSERT_EQ(2u, v[0]); | |
220 ASSERT_EQ(1u, v[1]); | |
221 ASSERT_EQ(0u, v[2]); | |
222 | |
223 ASSERT_THROW(s.Sort(v, 3), Orthanc::OrthancException); | |
224 } | |
225 } | |
226 | |
227 | |
228 TEST(BasicFetchingItemsSorter, Odd) | |
229 { | |
230 OrthancStone::BasicFetchingItemsSorter s(7); | |
231 std::vector<unsigned int> v; | |
232 | |
233 ASSERT_THROW(s.Sort(v, 7), Orthanc::OrthancException); | |
234 | |
235 { | |
236 s.Sort(v, 0); | |
237 ASSERT_EQ(7u, v.size()); | |
238 ASSERT_EQ(0u, v[0]); | |
239 ASSERT_EQ(1u, v[1]); | |
240 ASSERT_EQ(2u, v[2]); | |
241 ASSERT_EQ(3u, v[3]); | |
242 ASSERT_EQ(4u, v[4]); | |
243 ASSERT_EQ(5u, v[5]); | |
244 ASSERT_EQ(6u, v[6]); | |
245 } | |
246 | |
247 { | |
248 s.Sort(v, 1); | |
249 ASSERT_EQ(7u, v.size()); | |
250 ASSERT_EQ(1u, v[0]); | |
251 ASSERT_EQ(2u, v[1]); | |
252 ASSERT_EQ(0u, v[2]); | |
253 ASSERT_EQ(3u, v[3]); | |
254 ASSERT_EQ(4u, v[4]); | |
255 ASSERT_EQ(5u, v[5]); | |
256 ASSERT_EQ(6u, v[6]); | |
257 } | |
258 | |
259 { | |
260 s.Sort(v, 2); | |
261 ASSERT_EQ(7u, v.size()); | |
262 ASSERT_EQ(2u, v[0]); | |
263 ASSERT_EQ(3u, v[1]); | |
264 ASSERT_EQ(1u, v[2]); | |
265 ASSERT_EQ(4u, v[3]); | |
266 ASSERT_EQ(0u, v[4]); | |
267 ASSERT_EQ(5u, v[5]); | |
268 ASSERT_EQ(6u, v[6]); | |
269 } | |
270 | |
271 { | |
272 s.Sort(v, 3); | |
273 ASSERT_EQ(7u, v.size()); | |
274 ASSERT_EQ(3u, v[0]); | |
275 ASSERT_EQ(4u, v[1]); | |
276 ASSERT_EQ(2u, v[2]); | |
277 ASSERT_EQ(5u, v[3]); | |
278 ASSERT_EQ(1u, v[4]); | |
279 ASSERT_EQ(6u, v[5]); | |
280 ASSERT_EQ(0u, v[6]); | |
281 } | |
282 | |
283 { | |
284 s.Sort(v, 4); | |
285 ASSERT_EQ(7u, v.size()); | |
286 ASSERT_EQ(4u, v[0]); | |
287 ASSERT_EQ(5u, v[1]); | |
288 ASSERT_EQ(3u, v[2]); | |
289 ASSERT_EQ(6u, v[3]); | |
290 ASSERT_EQ(2u, v[4]); | |
291 ASSERT_EQ(1u, v[5]); | |
292 ASSERT_EQ(0u, v[6]); | |
293 } | |
294 | |
295 { | |
296 s.Sort(v, 5); | |
297 ASSERT_EQ(7u, v.size()); | |
298 ASSERT_EQ(5u, v[0]); | |
299 ASSERT_EQ(6u, v[1]); | |
300 ASSERT_EQ(4u, v[2]); | |
301 ASSERT_EQ(3u, v[3]); | |
302 ASSERT_EQ(2u, v[4]); | |
303 ASSERT_EQ(1u, v[5]); | |
304 ASSERT_EQ(0u, v[6]); | |
305 } | |
306 | |
307 { | |
308 s.Sort(v, 6); | |
309 ASSERT_EQ(7u, v.size()); | |
310 ASSERT_EQ(6u, v[0]); | |
311 ASSERT_EQ(5u, v[1]); | |
312 ASSERT_EQ(4u, v[2]); | |
313 ASSERT_EQ(3u, v[3]); | |
314 ASSERT_EQ(2u, v[4]); | |
315 ASSERT_EQ(1u, v[5]); | |
316 ASSERT_EQ(0u, v[6]); | |
317 } | |
318 } | |
319 | |
320 | |
321 TEST(BasicFetchingItemsSorter, Even) | |
322 { | |
323 OrthancStone::BasicFetchingItemsSorter s(6); | |
324 std::vector<unsigned int> v; | |
325 | |
326 { | |
327 s.Sort(v, 0); | |
328 ASSERT_EQ(6u, v.size()); | |
329 ASSERT_EQ(0u, v[0]); | |
330 ASSERT_EQ(1u, v[1]); | |
331 ASSERT_EQ(2u, v[2]); | |
332 ASSERT_EQ(3u, v[3]); | |
333 ASSERT_EQ(4u, v[4]); | |
334 ASSERT_EQ(5u, v[5]); | |
335 } | |
336 | |
337 { | |
338 s.Sort(v, 1); | |
339 ASSERT_EQ(6u, v.size()); | |
340 ASSERT_EQ(1u, v[0]); | |
341 ASSERT_EQ(2u, v[1]); | |
342 ASSERT_EQ(0u, v[2]); | |
343 ASSERT_EQ(3u, v[3]); | |
344 ASSERT_EQ(4u, v[4]); | |
345 ASSERT_EQ(5u, v[5]); | |
346 } | |
347 | |
348 { | |
349 s.Sort(v, 2); | |
350 ASSERT_EQ(6u, v.size()); | |
351 ASSERT_EQ(2u, v[0]); | |
352 ASSERT_EQ(3u, v[1]); | |
353 ASSERT_EQ(1u, v[2]); | |
354 ASSERT_EQ(4u, v[3]); | |
355 ASSERT_EQ(0u, v[4]); | |
356 ASSERT_EQ(5u, v[5]); | |
357 } | |
358 | |
359 { | |
360 s.Sort(v, 3); | |
361 ASSERT_EQ(6u, v.size()); | |
362 ASSERT_EQ(3u, v[0]); | |
363 ASSERT_EQ(4u, v[1]); | |
364 ASSERT_EQ(2u, v[2]); | |
365 ASSERT_EQ(5u, v[3]); | |
366 ASSERT_EQ(1u, v[4]); | |
367 ASSERT_EQ(0u, v[5]); | |
368 } | |
369 | |
370 { | |
371 s.Sort(v, 4); | |
372 ASSERT_EQ(6u, v.size()); | |
373 ASSERT_EQ(4u, v[0]); | |
374 ASSERT_EQ(5u, v[1]); | |
375 ASSERT_EQ(3u, v[2]); | |
376 ASSERT_EQ(2u, v[3]); | |
377 ASSERT_EQ(1u, v[4]); | |
378 ASSERT_EQ(0u, v[5]); | |
379 } | |
380 | |
381 { | |
382 s.Sort(v, 5); | |
383 ASSERT_EQ(6u, v.size()); | |
384 ASSERT_EQ(5u, v[0]); | |
385 ASSERT_EQ(4u, v[1]); | |
386 ASSERT_EQ(3u, v[2]); | |
387 ASSERT_EQ(2u, v[3]); | |
388 ASSERT_EQ(1u, v[4]); | |
389 ASSERT_EQ(0u, v[5]); | |
390 } | |
391 } |