Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
d22b2c59
Commit
d22b2c59
authored
Mar 05, 2014
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test random number generator
parent
e4763e78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
dream/tests/testRandomNumberGenerator.py
dream/tests/testRandomNumberGenerator.py
+69
-0
No files found.
dream/tests/testRandomNumberGenerator.py
0 → 100644
View file @
d22b2c59
# ===========================================================================
# Copyright 2014 Nexedi SA
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
from
dream.simulation.RandomNumberGenerator
import
RandomNumberGenerator
from
unittest
import
TestCase
from
dream.simulation.Source
import
Source
obj
=
Source
(
id
=
'dummy_obj'
,
name
=
"Dummy obj to instanciate RNG"
)
class
RandomNumberGeneratorTestCase
(
TestCase
):
def
testFixed
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distributionType
=
'Fixed'
,
mean
=
32
)
self
.
assertEquals
(
rng
.
generateNumber
(),
32
)
self
.
assertEquals
(
rng
.
generateNumber
(),
32
)
def
testExp
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distributionType
=
'Exp'
,
avg
=
10
)
number
=
rng
.
generateNumber
()
# at least we make sure we generate a number
self
.
assertTrue
(
number
>=
0
)
def
testErlang
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distributionType
=
'Erlang'
,
alpha
=
1
,
beta
=
2
)
number
=
rng
.
generateNumber
()
# at least we make sure we generate a number
self
.
assertTrue
(
number
>=
0
)
def
testNormal
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distributionType
=
'Normal'
,
min
=
0
,
max
=
3
,
stdev
=
.
5
,
avg
=
2
)
for
i
in
range
(
10
):
number
=
rng
.
generateNumber
()
self
.
assertTrue
(
number
>=
0
)
self
.
assertTrue
(
number
<=
3
)
def
testNormalWrongParameter
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distributionType
=
'Normal'
,
min
=
3
,
max
=
0
,
# here min > max
stdev
=
.
5
,
avg
=
2
)
self
.
assertRaises
(
ValueError
,
rng
.
generateNumber
)
def
testUnkonwnDistribution
(
self
):
rng
=
RandomNumberGenerator
(
obj
,
distributionType
=
'Unknown'
)
self
.
assertRaises
(
ValueError
,
rng
.
generateNumber
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment