Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
2d50457d
Commit
2d50457d
authored
4 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
added new test for distributions and stellar types
parent
35f91adb
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
binarycpython/tests/main.py
+1
-0
1 addition, 0 deletions
binarycpython/tests/main.py
binarycpython/tests/test_distributions.py
+102
-0
102 additions, 0 deletions
binarycpython/tests/test_distributions.py
binarycpython/tests/test_stellar_types.py
+3
-0
3 additions, 0 deletions
binarycpython/tests/test_stellar_types.py
with
106 additions
and
0 deletions
binarycpython/tests/main.py
+
1
−
0
View file @
2d50457d
...
...
@@ -12,6 +12,7 @@ from binarycpython.tests.test_run_system_wrapper import *
from
binarycpython.tests.test_spacing_functions
import
*
from
binarycpython.tests.test_useful_funcs
import
*
from
binarycpython.tests.test_grid_options_defaults
import
*
from
binarycpython.tests.test_stellar_types
import
*
if
__name__
==
"
__main__
"
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
binarycpython/tests/test_distributions.py
+
102
−
0
View file @
2d50457d
...
...
@@ -25,6 +25,39 @@ class TestDistributions(unittest.TestCase):
self
.
tolerance
=
1e-5
def
test_flat
(
self
):
"""
Unittest for the function flat
"""
output_1
=
flat
()
self
.
assertTrue
(
isinstance
(
output_1
,
float
))
self
.
assertEqual
(
output_1
,
1.0
)
def
test_number
(
self
):
"""
Unittest for function number
"""
input_1
=
1.0
output_1
=
number
(
input_1
)
self
.
assertEqual
(
input_1
,
output_1
)
def
test_const
(
self
):
"""
Unittest for function const
"""
output_1
=
const
(
min_bound
=
0
,
max_bound
=
2
)
self
.
assertEqual
(
output_1
,
0.5
,
msg
=
"
Value should be 0.5, but is {}
"
.
format
(
output_1
))
output_2
=
const
(
min_bound
=
0
,
max_bound
=
2
,
val
=
3
)
self
.
assertEqual
(
output_2
,
0
,
msg
=
"
Value should be 0, but is {}
"
.
format
(
output_2
))
def
test_powerlaw
(
self
):
"""
unittest for the powerlaw test
...
...
@@ -47,6 +80,9 @@ class TestDistributions(unittest.TestCase):
for
i
in
range
(
len
(
python_results
)):
self
.
assertLess
(
np
.
abs
(
python_results
[
i
]
-
perl_results
[
i
]),
self
.
tolerance
)
# extra test for k = -1
self
.
assertRaises
(
ValueError
,
powerlaw
,
1
,
100
,
-
1
,
10
)
def
test_three_part_power_law
(
self
):
"""
unittest for three_part_power_law
...
...
@@ -71,6 +107,11 @@ class TestDistributions(unittest.TestCase):
for
i
in
range
(
len
(
python_results
)):
self
.
assertLess
(
np
.
abs
(
python_results
[
i
]
-
perl_results
[
i
]),
self
.
tolerance
)
# Extra test:
# M < M0
self
.
assertTrue
(
three_part_powerlaw
(
0.05
,
0.08
,
0.1
,
1
,
300
,
-
1.3
,
-
2.3
,
-
2.3
)
==
0
,
msg
=
"
Probability should be zero as M < M0
"
)
def
test_Kroupa2001
(
self
):
"""
unittest for three_part_power_law
...
...
@@ -92,6 +133,9 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance)
for
i
in
range
(
len
(
python_results
)):
self
.
assertLess
(
np
.
abs
(
python_results
[
i
]
-
perl_results
[
i
]),
self
.
tolerance
)
# Extra tests:
self
.
assertEqual
(
Kroupa2001
(
10
,
newopts
=
{
'
mmax
'
:
300
}),
three_part_powerlaw
(
10
,
0.1
,
0.5
,
1
,
300
,
-
1.3
,
-
2.3
,
-
2.3
))
def
test_ktg93
(
self
):
"""
...
...
@@ -114,6 +158,61 @@ class TestDistributions(unittest.TestCase):
# GO over the results and check whether they are equal (within tolerance)
for
i
in
range
(
len
(
python_results
)):
self
.
assertLess
(
np
.
abs
(
python_results
[
i
]
-
perl_results
[
i
]),
self
.
tolerance
)
# extra test:
self
.
assertEqual
(
ktg93
(
10
,
newopts
=
{
'
mmax
'
:
300
}),
three_part_powerlaw
(
10
,
0.1
,
0.5
,
1
,
300
,
-
1.3
,
-
2.2
,
-
2.7
))
def
test_imf_tinsley1980
(
self
):
"""
Unittest for function imf_tinsley1980
"""
m
=
1.2
self
.
assertEqual
(
imf_tinsley1980
(
m
),
three_part_powerlaw
(
m
,
0.1
,
2.0
,
10.0
,
80.0
,
-
2.0
,
-
2.3
,
-
3.3
))
def
test_imf_scalo1986
(
self
):
"""
Unittest for function imf_scalo1986
"""
m
=
1.2
self
.
assertEqual
(
imf_scalo1986
(
m
),
three_part_powerlaw
(
m
,
0.1
,
1.0
,
2.0
,
80.0
,
-
2.35
,
-
2.35
,
-
2.70
))
def
test_imf_scalo1998
(
self
):
"""
Unittest for function imf_scalo1986
"""
m
=
1.2
self
.
assertEqual
(
imf_scalo1998
(
m
),
three_part_powerlaw
(
m
,
0.1
,
1.0
,
10.0
,
80.0
,
-
1.2
,
-
2.7
,
-
2.3
))
def
test_imf_chabrier2003
(
self
):
"""
Unittest for function imf_chabrier2003
"""
input_1
=
0
self
.
assertRaises
(
ValueError
,
imf_chabrier2003
,
input_1
)
# for m=0.5
m
=
0.5
self
.
assertLess
(
np
.
abs
(
imf_chabrier
(
m
)
-
0.581457346702825
),
self
.
tolerance
,
msg
=
"
Difference is bigger than the tolerance
"
)
# For m = 2
m
=
2
self
.
assertLess
(
np
.
abs
(
imf_chabrier
(
m
)
-
0.581457346702825
),
self
.
tolerance
,
msg
=
"
Difference is bigger than the tolerance
"
)
def
test_duquennoy1991
(
self
):
"""
Unittest for function duquennoy1991
"""
self
.
assertEqual
(
duquennoy1991
(
4.2
),
gaussian
(
4.2
,
4.8
,
2.3
,
-
2
,
12
))
def
test_gaussian
(
self
):
"""
...
...
@@ -137,6 +236,9 @@ class TestDistributions(unittest.TestCase):
for
i
in
range
(
len
(
python_results
)):
self
.
assertLess
(
np
.
abs
(
python_results
[
i
]
-
perl_results
[
i
]),
self
.
tolerance
)
# Extra test:
self
.
assertTrue
(
gaussian
(
15
,
4.8
,
2.3
,
-
2.0
,
12.0
)
==
0
,
msg
=
"
Probability should be 0 because the input period is out of bounds
"
)
def
test_Arenou2010_binary_fraction
(
self
):
"""
unittest for three_part_power_law
...
...
This diff is collapsed.
Click to expand it.
binarycpython/tests/test_stellar_types.py
0 → 100644
+
3
−
0
View file @
2d50457d
import
unittest
from
binarycpython.utils.stellar_types
import
*
\ No newline at end of file
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