Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
dbb3f207
Commit
dbb3f207
authored
6 years ago
by
Bhuvan Bezawada
Browse files
Options
Downloads
Patches
Plain Diff
Updated test file for iterator
re #23145
parent
4a2ae724
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Framework/Geometry/test/DetectorInfoIteratorTest.h
+50
-21
50 additions, 21 deletions
Framework/Geometry/test/DetectorInfoIteratorTest.h
with
50 additions
and
21 deletions
Framework/Geometry/test/DetectorInfoIteratorTest.h
+
50
−
21
View file @
dbb3f207
...
@@ -62,8 +62,12 @@ public:
...
@@ -62,8 +62,12 @@ public:
V3D
(
10
,
0
,
0
),
// Sample position
V3D
(
10
,
0
,
0
),
// Sample position
V3D
(
11
,
0
,
0
));
// Detector position
V3D
(
11
,
0
,
0
));
// Detector position
// Total number of detectors will be 11
// Need to loop until 12
int
numDetectors
=
12
;
// Add 10 more detectors to the instrument
// Add 10 more detectors to the instrument
for
(
int
i
=
2
;
i
<
12
;
i
++
)
{
for
(
int
i
=
2
;
i
<
numDetectors
;
i
++
)
{
Detector
*
det
=
Detector
*
det
=
new
Detector
(
"point-detector"
,
i
/*detector id*/
,
nullptr
);
new
Detector
(
"point-detector"
,
i
/*detector id*/
,
nullptr
);
det
->
setPos
(
V3D
(
10
+
i
,
0
,
0
));
det
->
setPos
(
V3D
(
10
+
i
,
0
,
0
));
...
@@ -98,7 +102,7 @@ public:
...
@@ -98,7 +102,7 @@ public:
TS_ASSERT
(
iter
!=
detectorInfo
->
begin
());
TS_ASSERT
(
iter
!=
detectorInfo
->
begin
());
}
}
void
test_iterator_increment
()
{
void
test_iterator_increment
_and_positions
()
{
// Get the DetectorInfo object
// Get the DetectorInfo object
auto
detectorInfo
=
create_detector_info_object
();
auto
detectorInfo
=
create_detector_info_object
();
auto
iter
=
detectorInfo
->
begin
();
auto
iter
=
detectorInfo
->
begin
();
...
@@ -106,9 +110,21 @@ public:
...
@@ -106,9 +110,21 @@ public:
// Check that we start at the beginning
// Check that we start at the beginning
TS_ASSERT
(
iter
==
detectorInfo
->
begin
());
TS_ASSERT
(
iter
==
detectorInfo
->
begin
());
// Increment and check index
// Doubles for values in the V3D position object
double
xValue
=
0.0
;
double
zero
=
0.0
;
// Increment the iterator and check positions
for
(
int
i
=
0
;
i
<
11
;
++
i
)
{
for
(
int
i
=
0
;
i
<
11
;
++
i
)
{
TS_ASSERT_EQUALS
(
iter
->
getIndex
(),
i
);
// Store expected X as double
xValue
=
11.0
+
(
double
)
i
;
// Assertions
TS_ASSERT_EQUALS
(
iter
->
position
().
X
(),
xValue
);
TS_ASSERT
(
iter
->
position
().
Y
()
==
zero
);
TS_ASSERT
(
iter
->
position
().
Z
()
==
zero
);
// Increment the iterator
++
iter
;
++
iter
;
}
}
...
@@ -116,7 +132,7 @@ public:
...
@@ -116,7 +132,7 @@ public:
TS_ASSERT
(
iter
==
detectorInfo
->
end
());
TS_ASSERT
(
iter
==
detectorInfo
->
end
());
}
}
void
test_iterator_decrement
()
{
void
test_iterator_decrement
_and_positions
()
{
// Get the DetectorInfo object
// Get the DetectorInfo object
auto
detectorInfo
=
create_detector_info_object
();
auto
detectorInfo
=
create_detector_info_object
();
auto
iter
=
detectorInfo
->
end
();
auto
iter
=
detectorInfo
->
end
();
...
@@ -124,39 +140,52 @@ public:
...
@@ -124,39 +140,52 @@ public:
// Check that we start at the end
// Check that we start at the end
TS_ASSERT
(
iter
==
detectorInfo
->
end
());
TS_ASSERT
(
iter
==
detectorInfo
->
end
());
// Decrement and check index
// Doubles for values in the V3D position object
double
xValue
=
0.0
;
double
zero
=
0.0
;
// Increment the iterator and check positions
for
(
int
i
=
11
;
i
>
0
;
--
i
)
{
for
(
int
i
=
11
;
i
>
0
;
--
i
)
{
TS_ASSERT_EQUALS
(
iter
->
getIndex
(),
i
);
// Decrement the iterator
--
iter
;
--
iter
;
// Store expected X as double
xValue
=
10.0
+
(
double
)
i
;
// Assertions
TS_ASSERT_EQUALS
(
iter
->
position
().
X
(),
xValue
);
TS_ASSERT
(
iter
->
position
().
Y
()
==
zero
);
TS_ASSERT
(
iter
->
position
().
Z
()
==
zero
);
}
}
// Check we've reached the beginning
// Check we've reached the beginning
TS_ASSERT
(
iter
==
detectorInfo
->
begin
());
TS_ASSERT
(
iter
==
detectorInfo
->
begin
());
}
}
void
test_iterator_advance
()
{
void
test_iterator_advance
_and_positions
()
{
// Get the DetectorInfo object
// Get the DetectorInfo object
auto
detectorInfo
=
create_detector_info_object
();
auto
detectorInfo
=
create_detector_info_object
();
auto
iter
=
detectorInfo
->
begin
();
auto
iter
=
detectorInfo
->
begin
();
// Store the expected X value
double
xValue
=
0.0
;
// Advance 6 places
// Advance 6 places
xValue
=
17.0
;
std
::
advance
(
iter
,
6
);
std
::
advance
(
iter
,
6
);
TS_ASSERT_EQUALS
(
iter
->
getIndex
(),
6
);
TS_ASSERT_EQUALS
(
iter
->
position
().
X
(),
xValue
)
// Go past end of valid range
std
::
advance
(
iter
,
8
);
TS_ASSERT
(
iter
==
detectorInfo
->
end
());
// Go backwards
// Go backwards 2 places
xValue
=
15.0
;
std
::
advance
(
iter
,
-
2
);
std
::
advance
(
iter
,
-
2
);
TS_ASSERT_EQUALS
(
iter
->
getIndex
(),
9
);
TS_ASSERT_EQUALS
(
iter
->
position
().
X
(),
xValue
)
// Go to the start
// Go to the start
std
::
advance
(
iter
,
-
9
);
std
::
advance
(
iter
,
-
4
);
TS_ASSERT
(
iter
==
detectorInfo
->
begin
());
TS_ASSERT
(
iter
==
detectorInfo
->
begin
());
}
}
void
test_copy_iterator
()
{
void
test_copy_iterator
_and_positions
()
{
// Get the DetectorInfo object
// Get the DetectorInfo object
auto
detectorInfo
=
create_detector_info_object
();
auto
detectorInfo
=
create_detector_info_object
();
auto
iter
=
detectorInfo
->
begin
();
auto
iter
=
detectorInfo
->
begin
();
...
@@ -165,16 +194,16 @@ public:
...
@@ -165,16 +194,16 @@ public:
auto
iterCopy
=
DetectorInfoIterator
(
iter
);
auto
iterCopy
=
DetectorInfoIterator
(
iter
);
// Check
// Check
TS_ASSERT_EQUALS
(
iter
->
getIndex
(),
0
);
TS_ASSERT_EQUALS
(
iter
->
position
().
X
(),
11.
0
);
TS_ASSERT_EQUALS
(
iterCopy
->
getIndex
(),
0
);
TS_ASSERT_EQUALS
(
iterCopy
->
position
().
X
(),
11.
0
);
// Increment
// Increment
++
iter
;
++
iter
;
++
iterCopy
;
++
iterCopy
;
// Check again
// Check again
TS_ASSERT_EQUALS
(
iter
->
getIndex
(),
1
);
TS_ASSERT_EQUALS
(
iter
->
position
().
X
(),
1
2.0
);
TS_ASSERT_EQUALS
(
iterCopy
->
getIndex
(),
1
);
TS_ASSERT_EQUALS
(
iterCopy
->
position
().
X
(),
1
2.0
);
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment