Passed
Push — master ( b71750...7ebf62 )
by Stefan
01:58
created

test_spectra   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_nflux_norm() 0 10 1
A test_pflux_norm() 0 10 1
1
# -*- coding: utf-8 -*-
2
import numpy as np
3
import pytest
4
5
import eppaurora.spectra as spec
6
7
# unit particle flux
8
PFLUX_NNORM = [
9
	spec.exp_general,
10
	spec.gaussian_general,
11
	spec.maxwell_general,
12
]
13
14
# unit energy flux
15
PFLUX_ENORM = [
16
	spec.pflux_exp,
17
	spec.pflux_gaussian,
18
	spec.pflux_maxwell,
19
]
20
21
22
@pytest.mark.parametrize(
23
	"pflux_func",
24
	PFLUX_NNORM,
25
)
26
def test_nflux_norm(pflux_func):
27
	energies = np.logspace(-2, 4, 257)
28
	spec = pflux_func(energies)
29
	norm = np.trapz(spec, energies)
30
	np.testing.assert_allclose(norm, 1., rtol=1e-3)
31
	return
32
33
34
@pytest.mark.parametrize(
35
	"pflux_func",
36
	PFLUX_ENORM,
37
)
38
def test_pflux_norm(pflux_func):
39
	energies = np.logspace(-2, 4, 257)
40
	spec = pflux_func(energies)
41
	norm = np.trapz(spec * energies, energies)
42
	np.testing.assert_allclose(norm, 1., rtol=1e-3)
43
	return
44