Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MLIP
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tadah
MLIP
Commits
9c11cfee
Commit
9c11cfee
authored
5 months ago
by
mkirsz
Browse files
Options
Downloads
Patches
Plain Diff
replaced std::tmpnam
parent
81e181ae
No related branches found
No related tags found
1 merge request
!12
Develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_structure.cpp
+68
-47
68 additions, 47 deletions
tests/test_structure.cpp
with
68 additions
and
47 deletions
tests/test_structure.cpp
+
68
−
47
View file @
9c11cfee
...
@@ -56,63 +56,84 @@ TEST_CASE( "Testing Structure virial pressure calculations", "[structure_virial_
...
@@ -56,63 +56,84 @@ TEST_CASE( "Testing Structure virial pressure calculations", "[structure_virial_
REQUIRE
(
fac
*
st
.
get_virial_pressure
()
==
Approx
(
499.93
));
REQUIRE
(
fac
*
st
.
get_virial_pressure
()
==
Approx
(
499.93
));
}
}
TEST_CASE
(
"Testing Structure read and write"
,
"[structure_read_write]"
)
{
TEST_CASE
(
"Testing Structure read and write"
,
"[structure_read_write]"
)
{
Structure
st
;
Structure
st
;
st
.
read
(
"tests_data/structure_1.dat"
);
st
.
read
(
"tests_data/structure_1.dat"
);
REQUIRE
(
st
.
get_volume
()
==
Approx
(
989.521812
));
REQUIRE
(
st
.
get_volume
()
==
Approx
(
989.521812
));
REQUIRE
(
fac
*
st
.
get_virial_pressure
()
==
Approx
(
26.705578
));
REQUIRE
(
fac
*
st
.
get_pressure
(
300
)
==
Approx
(
28.965914
));
REQUIRE
(
fac
*
st
.
get_pressure
(
0
)
==
Approx
(
26.705578
));
REQUIRE
(
fac
*
st
.
get_virial_pressure
()
==
Approx
(
26.705578
));
// Create a temporary file
REQUIRE
(
fac
*
st
.
get_pressure
(
300
)
==
Approx
(
28.965914
));
std
::
FILE
*
tmpFile
=
std
::
tmpfile
();
REQUIRE
(
fac
*
st
.
get_pressure
(
0
)
==
Approx
(
26.705578
));
if
(
!
tmpFile
)
{
FAIL
(
"Unable to create temporary file"
);
}
std
::
st
r
in
g
tempfile
=
std
::
tmpnam
(
nullptr
);
con
st
in
t
fd
=
fileno
(
tmpFile
);
st
.
save
(
tempfile
);
REQUIRE
(
fd
!=
-
1
);
Structure
st_temp
;
char
tempfile
[
256
]
;
s
t_temp
.
read
(
tempfile
);
s
nprintf
(
tempfile
,
sizeof
(
tempfile
),
"/proc/self/fd/%d"
,
fd
);
REQUIRE
(
st_temp
.
get_volume
()
==
Approx
(
989.521812
)
);
st
.
save
(
tempfile
);
REQUIRE
(
fac
*
st_temp
.
get_virial_pressure
()
==
Approx
(
26.705578
));
Structure
st_temp
;
REQUIRE
(
fac
*
st_temp
.
get_pressure
(
300
)
==
Approx
(
28.965914
));
st_temp
.
read
(
tempfile
);
REQUIRE
(
fac
*
st_temp
.
get_pressure
(
0
)
==
Approx
(
26.705578
));
REQUIRE
(
st
==
st_temp
);
REQUIRE
(
st_temp
.
get_volume
()
==
Approx
(
989.521812
));
REQUIRE
(
fac
*
st_temp
.
get_virial_pressure
()
==
Approx
(
26.705578
));
REQUIRE
(
fac
*
st_temp
.
get_pressure
(
300
)
==
Approx
(
28.965914
));
REQUIRE
(
fac
*
st_temp
.
get_pressure
(
0
)
==
Approx
(
26.705578
));
std
::
remove
(
tempfile
.
c_str
()
);
REQUIRE
(
st
==
st_temp
);
// Temporary file will be closed automatically
}
}
TEST_CASE
(
"Testing Structure compare"
,
"[structure_compare]"
)
{
TEST_CASE
(
"Testing Structure compare"
,
"[structure_compare]"
)
{
Structure
st
;
Structure
st
;
st
.
read
(
"tests_data/structure_1.dat"
);
st
.
read
(
"tests_data/structure_1.dat"
);
std
::
string
tempfile
=
std
::
tmpnam
(
nullptr
);
st
.
save
(
tempfile
);
// Create a temporary file
std
::
FILE
*
tmpFile
=
std
::
tmpfile
();
Structure
st_temp
;
if
(
!
tmpFile
)
{
st_temp
.
read
(
tempfile
);
FAIL
(
"Unable to create temporary file"
);
}
SECTION
(
"Compare unchanged"
)
{
REQUIRE
(
st
==
st_temp
);
const
int
fd
=
fileno
(
tmpFile
);
}
REQUIRE
(
fd
!=
-
1
);
SECTION
(
"Compare symbols"
)
{
REQUIRE
(
st
==
st_temp
);
char
tempfile
[
256
];
st_temp
.
atoms
[
0
].
symbol
[
0
]
=
'X'
;
snprintf
(
tempfile
,
sizeof
(
tempfile
),
"/proc/self/fd/%d"
,
fd
);
st_temp
.
atoms
[
0
].
symbol
[
1
]
=
'X'
;
REQUIRE
(
!
(
st
==
st_temp
));
st
.
save
(
tempfile
);
}
SECTION
(
"Compare position"
)
{
Structure
st_temp
;
REQUIRE
(
st
==
st_temp
);
st_temp
.
read
(
tempfile
);
st_temp
.
atoms
[
0
].
position
(
0.12
,
0.13
,
10.14
);
REQUIRE
(
!
(
st
==
st_temp
));
SECTION
(
"Compare unchanged"
)
{
}
REQUIRE
(
st
==
st_temp
);
SECTION
(
"Compare force"
)
{
}
REQUIRE
(
st
==
st_temp
);
SECTION
(
"Compare symbols"
)
{
st_temp
.
atoms
[
0
].
force
(
1.12
,
0.13
,
0.134
);
REQUIRE
(
st
==
st_temp
);
REQUIRE
(
!
(
st
==
st_temp
));
st_temp
.
atoms
[
0
].
symbol
[
0
]
=
'X'
;
}
st_temp
.
atoms
[
0
].
symbol
[
1
]
=
'X'
;
REQUIRE
(
!
(
st
==
st_temp
));
std
::
remove
(
tempfile
.
c_str
());
}
SECTION
(
"Compare position"
)
{
REQUIRE
(
st
==
st_temp
);
st_temp
.
atoms
[
0
].
position
(
0.12
,
0.13
,
10.14
);
REQUIRE
(
!
(
st
==
st_temp
));
}
SECTION
(
"Compare force"
)
{
REQUIRE
(
st
==
st_temp
);
st_temp
.
atoms
[
0
].
force
(
1.12
,
0.13
,
0.134
);
REQUIRE
(
!
(
st
==
st_temp
));
}
// Temporary file will be closed automatically
}
}
TEST_CASE
(
"Testing Structure copy"
,
"[structure_copy]"
)
{
TEST_CASE
(
"Testing Structure copy"
,
"[structure_copy]"
)
{
Structure
st
;
Structure
st
;
...
...
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