Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
eed439c2
Commit
eed439c2
authored
6 years ago
by
anikhalder
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for RealSpaceBuilderUtils
parent
fbfb8823
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests/UnitTests/GUI/TestGUI.cpp
+1
-0
1 addition, 0 deletions
Tests/UnitTests/GUI/TestGUI.cpp
Tests/UnitTests/GUI/TestRealSpaceBuilderUtils.h
+135
-0
135 additions, 0 deletions
Tests/UnitTests/GUI/TestRealSpaceBuilderUtils.h
with
136 additions
and
0 deletions
Tests/UnitTests/GUI/TestGUI.cpp
+
1
−
0
View file @
eed439c2
...
...
@@ -35,6 +35,7 @@
#include
"TestProjectUtils.h"
#include
"TestPropertyRepeater.h"
#include
"TestProxyModelStrategy.h"
#include
"TestRealSpaceBuilderUtils.h"
#include
"TestSaveService.h"
#include
"TestSessionItemController.h"
#include
"TestSessionItem.h"
...
...
This diff is collapsed.
Click to expand it.
Tests/UnitTests/GUI/TestRealSpaceBuilderUtils.h
+
135
−
0
View file @
eed439c2
#ifndef TESTREALSPACEBUILDERUTILS_H
#define TESTREALSPACEBUILDERUTILS_H
#include
"google_test.h"
#include
<QObject>
#include
"RealSpaceBuilderUtils.h"
#include
"RealSpaceBuilder.h"
#include
"SampleModel.h"
#include
"ParticleLayoutItem.h"
#include
"ParticleItem.h"
#include
"IFormFactor.h"
#include
"IFormFactorDecorator.h"
#include
"Particle.h"
#include
"ApplicationModels.h"
#include
"TransformTo3D.h"
class
TestRealSpaceBuilderUtils
:
public
::
testing
::
Test
{
public:
~
TestRealSpaceBuilderUtils
();
};
TestRealSpaceBuilderUtils
::~
TestRealSpaceBuilderUtils
()
=
default
;
TEST_F
(
TestRealSpaceBuilderUtils
,
test_cumulativeAbundance
)
{
SampleModel
sampleModel
;
auto
layout
=
dynamic_cast
<
ParticleLayoutItem
*>
(
sampleModel
.
insertNewItem
(
Constants
::
ParticleLayoutType
));
auto
particle1
=
sampleModel
.
insertNewItem
(
Constants
::
ParticleType
,
sampleModel
.
indexOfItem
(
layout
),
-
1
,
ParticleLayoutItem
::
T_PARTICLES
);
EXPECT_EQ
(
particle1
->
parent
(),
layout
);
SessionItem
*
particle2
=
sampleModel
.
insertNewItem
(
Constants
::
ParticleType
);
EXPECT_EQ
(
particle2
->
parent
(),
sampleModel
.
rootItem
());
sampleModel
.
moveItem
(
particle2
,
layout
,
-
1
,
ParticleLayoutItem
::
T_PARTICLES
);
EXPECT_EQ
(
particle2
->
parent
(),
layout
);
particle1
->
setItemValue
(
ParticleItem
::
P_ABUNDANCE
,
8.0
);
particle2
->
setItemValue
(
ParticleItem
::
P_ABUNDANCE
,
2.0
);
EXPECT_EQ
(
RealSpaceBuilderUtils
::
computeCumulativeAbundances
(
*
layout
).
last
(),
10.0
);
}
TEST_F
(
TestRealSpaceBuilderUtils
,
test_Particle3DType
)
{
Particle3DType
particle3DType
;
EXPECT_EQ
((
particle3DType
.
m_3Dparticles
).
size
(),
0
);
EXPECT_EQ
(
particle3DType
.
m_cumulative_abundance
,
0
);
EXPECT_EQ
(
particle3DType
.
m_type
,
""
);
// Create a 3D particle directly using constructor
auto
cylinder3D
=
RealSpace
::
Particles
::
Cylinder
(
5
,
10
);
// Associate it to a Particle3DType object
particle3DType
.
m_3Dparticles
.
append
(
&
cylinder3D
);
particle3DType
.
m_cumulative_abundance
=
1
;
particle3DType
.
m_type
=
Constants
::
ParticleType
;
EXPECT_EQ
(
particle3DType
.
m_3Dparticles
.
size
(),
1
);
//EXPECT_TRUE(particle3DType.m_3Dparticles.at(0) != nullptr);
EXPECT_EQ
(
particle3DType
.
m_cumulative_abundance
,
1
);
EXPECT_EQ
(
particle3DType
.
m_type
,
Constants
::
ParticleType
);
}
TEST_F
(
TestRealSpaceBuilderUtils
,
test_getSingleParticle3DType
)
{
ApplicationModels
models
;
SampleModel
*
sampleModel
=
models
.
sampleModel
();
auto
particle
=
sampleModel
->
insertNewItem
(
Constants
::
ParticleType
);
EXPECT_EQ
(
particle
->
getItemValue
(
ParticleItem
::
P_ABUNDANCE
).
toDouble
(),
1.0
);
EXPECT_EQ
(
particle
->
getGroupItem
(
ParticleItem
::
P_FORM_FACTOR
)
->
modelType
(),
Constants
::
CylinderType
);
particle
->
setItemValue
(
ParticleItem
::
P_ABUNDANCE
,
8.0
);
EXPECT_EQ
(
particle
->
getItemValue
(
ParticleItem
::
P_ABUNDANCE
).
toDouble
(),
8.0
);
particle
->
setGroupProperty
(
ParticleItem
::
P_FORM_FACTOR
,
Constants
::
BoxType
);
EXPECT_EQ
(
particle
->
getGroupItem
(
ParticleItem
::
P_FORM_FACTOR
)
->
modelType
(),
Constants
::
BoxType
);
// Create a 3D particle from particleItem and associate it to a Particle3DType object
auto
singleParticle3DType
=
RealSpaceBuilderUtils
::
getSingleParticle3DType
(
particle
,
8
);
EXPECT_EQ
(
singleParticle3DType
.
m_3Dparticles
.
size
(),
1
);
//EXPECT_TRUE(singleParticle3DType.m_3Dparticles.at(0) != nullptr);
EXPECT_EQ
(
singleParticle3DType
.
m_cumulative_abundance
,
1
);
EXPECT_EQ
(
singleParticle3DType
.
m_type
,
Constants
::
ParticleType
);
}
TEST_F
(
TestRealSpaceBuilderUtils
,
test_getParticle3DTypeVector
)
{
ApplicationModels
models
;
SampleModel
*
sampleModel
=
models
.
sampleModel
();
auto
layout
=
dynamic_cast
<
ParticleLayoutItem
*>
(
sampleModel
->
insertNewItem
(
Constants
::
ParticleLayoutType
));
auto
particle1
=
sampleModel
->
insertNewItem
(
Constants
::
ParticleType
);
auto
particle2
=
sampleModel
->
insertNewItem
(
Constants
::
ParticleType
);
auto
particle3
=
sampleModel
->
insertNewItem
(
Constants
::
ParticleType
);
sampleModel
->
moveItem
(
particle1
,
layout
,
-
1
,
ParticleLayoutItem
::
T_PARTICLES
);
sampleModel
->
moveItem
(
particle2
,
layout
,
-
1
,
ParticleLayoutItem
::
T_PARTICLES
);
sampleModel
->
moveItem
(
particle3
,
layout
,
-
1
,
ParticleLayoutItem
::
T_PARTICLES
);
particle1
->
setItemValue
(
ParticleItem
::
P_ABUNDANCE
,
5.0
);
particle2
->
setItemValue
(
ParticleItem
::
P_ABUNDANCE
,
3.0
);
particle3
->
setItemValue
(
ParticleItem
::
P_ABUNDANCE
,
2.0
);
double
total_abundance
=
RealSpaceBuilderUtils
::
computeCumulativeAbundances
(
*
layout
).
last
();
EXPECT_EQ
(
total_abundance
,
10.0
);
particle1
->
setGroupProperty
(
ParticleItem
::
P_FORM_FACTOR
,
Constants
::
BoxType
);
particle2
->
setGroupProperty
(
ParticleItem
::
P_FORM_FACTOR
,
Constants
::
ConeType
);
particle3
->
setGroupProperty
(
ParticleItem
::
P_FORM_FACTOR
,
Constants
::
PyramidType
);
auto
particle3DType_vector
=
RealSpaceBuilderUtils
::
getParticle3DTypeVector
(
*
layout
);
EXPECT_EQ
(
particle3DType_vector
.
size
(),
3
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
0
).
m_3Dparticles
.
size
(),
1
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
0
).
m_cumulative_abundance
,
0.5
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
0
).
m_type
,
Constants
::
ParticleType
);
EXPECT_EQ
((
particle3DType_vector
.
at
(
1
)).
m_3Dparticles
.
size
(),
1
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
1
).
m_cumulative_abundance
,
0.8
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
1
).
m_type
,
Constants
::
ParticleType
);
EXPECT_EQ
((
particle3DType_vector
.
at
(
2
)).
m_3Dparticles
.
size
(),
1
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
2
).
m_cumulative_abundance
,
1.0
);
EXPECT_EQ
(
particle3DType_vector
.
at
(
2
).
m_type
,
Constants
::
ParticleType
);
}
#endif // TESTREALSPACEBUILDERUTILS_H
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