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