IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue 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
Pranav Sampathkumar
corsika
Commits
952c4964
Commit
952c4964
authored
4 years ago
by
Remy Prechelt
Browse files
Options
Downloads
Patches
Plain Diff
Add IsRegistered to RNGManager and unit tests.
parent
f07df1c0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Framework/Random/RNGManager.cc
+10
-8
10 additions, 8 deletions
Framework/Random/RNGManager.cc
Framework/Random/RNGManager.h
+9
-7
9 additions, 7 deletions
Framework/Random/RNGManager.h
Framework/Random/testRandom.cc
+23
-9
23 additions, 9 deletions
Framework/Random/testRandom.cc
with
42 additions
and
24 deletions
Framework/Random/RNGManager.cc
+
10
−
8
View file @
952c4964
...
...
@@ -7,6 +7,7 @@
*/
#include
<corsika/random/RNGManager.h>
#include
<sstream>
void
corsika
::
random
::
RNGManager
::
RegisterRandomStream
(
std
::
string
const
&
pStreamName
)
{
corsika
::
random
::
RNG
rng
;
...
...
@@ -20,7 +21,15 @@ void corsika::random::RNGManager::RegisterRandomStream(std::string const& pStrea
corsika
::
random
::
RNG
&
corsika
::
random
::
RNGManager
::
GetRandomStream
(
std
::
string
const
&
pStreamName
)
{
return
rngs
.
at
(
pStreamName
);
if
(
IsRegistered
(
pStreamName
))
{
return
rngs
.
at
(
pStreamName
);
}
else
{
// this stream name is not in the map
throw
std
::
runtime_error
(
pStreamName
+
" is not a registered stream."
);
}
}
bool
corsika
::
random
::
RNGManager
::
IsRegistered
(
std
::
string
const
&
pStreamName
)
const
{
return
rngs
.
count
(
pStreamName
)
>
0
;
}
std
::
stringstream
corsika
::
random
::
RNGManager
::
dumpState
()
const
{
...
...
@@ -44,10 +53,3 @@ void corsika::random::RNGManager::SeedAll() {
entry
.
second
.
seed
(
sseq
);
}
}
/*
void corsika::random::RNGManager::SetSeedSeq(std::string const& pStreamName,
std::seed_seq const& pSeedSeq) {
seeds[pStreamName] = pSeedSeq;
}
*/
This diff is collapsed.
Click to expand it.
Framework/Random/RNGManager.h
+
9
−
7
View file @
952c4964
...
...
@@ -12,7 +12,6 @@
#include
<map>
#include
<random>
#include
<sstream>
#include
<string>
/*!
...
...
@@ -23,7 +22,10 @@ namespace corsika::random {
using
RNG
=
std
::
mt19937
;
//!< the actual RNG type that will be used
class
RNGManager
:
public
corsika
::
utl
::
Singleton
<
RNGManager
>
{
/*!
* Manage random number generators.
*/
class
RNGManager
final
:
public
corsika
::
utl
::
Singleton
<
RNGManager
>
{
friend
class
corsika
::
utl
::
Singleton
<
RNGManager
>
;
...
...
@@ -48,17 +50,17 @@ namespace corsika::random {
*/
RNG
&
GetRandomStream
(
std
::
string
const
&
pStreamName
);
/*!
* Check whether a stream has been registered.
*/
bool
IsRegistered
(
std
::
string
const
&
pStreamName
)
const
;
/*!
* dumps the names and states of all registered random-number streams
* into a std::stringstream.
*/
std
::
stringstream
dumpState
()
const
;
/**
* set seed_seq of \a pStreamName to \a pSeedSeq
*/
// void SetSeedSeq(std::string const& pStreamName, std::seed_seq& const pSeedSeq);
/**
* Set explicit seeds for all currently registered streams. The actual seed values
* are incremented from \a vSeed.
...
...
This diff is collapsed.
Click to expand it.
Framework/Random/testRandom.cc
+
23
−
9
View file @
952c4964
...
...
@@ -23,18 +23,32 @@ SCENARIO("random-number streams can be registered and retrieved") {
GIVEN
(
"a RNGManager"
)
{
RNGManager
&
rngManager
=
RNGManager
::
GetInstance
();
WHEN
(
"
a
sequence
is
registered
by name
"
)
{
rngManager
.
Register
RandomStream
(
"stream_A"
);
WHEN
(
"
the
sequence
name is not
registered"
)
{
REQUIRE
(
rngManager
.
Is
Register
ed
(
"stream_A"
)
==
false
)
;
THEN
(
"the sequence can be retrieved"
)
{
REQUIRE_NOTHROW
(
rngManager
.
GetRandomStream
(
"stream_A"
));
}
THEN
(
"a sequence is registered by name"
)
{
rngManager
.
RegisterRandomStream
(
"stream_A"
);
THEN
(
"an unknown sequence cannot be retrieved"
)
{
REQUIRE_THROWS
(
rngManager
.
GetRandomStream
(
"stream_UNKNOWN"
));
}
THEN
(
"the sequence can be retrieved"
)
{
REQUIRE_NOTHROW
(
rngManager
.
GetRandomStream
(
"stream_A"
));
THEN
(
"we can check that the sequence exists"
)
{
REQUIRE_NOTHROW
(
rngManager
.
GetRandomStream
(
"stream_A"
));
// seeding not covered yet
THEN
(
"an unknown sequence cannot be retrieved"
)
{
REQUIRE
(
rngManager
.
IsRegistered
(
"stream_A"
)
==
true
);
THEN
(
"an unknown sequence cannot be retrieved"
)
{
REQUIRE_THROWS
(
rngManager
.
GetRandomStream
(
"stream_UNKNOWN"
));
THEN
(
"an unknown sequence is not registered"
)
{
REQUIRE
(
rngManager
.
IsRegistered
(
"stream_UNKNOWN"
)
==
false
);
}
}
}
}
}
}
}
}
}
...
...
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