MCPcopy Create free account
hub / github.com/danieljfarrell/pvtrace / test_step_sample

Method test_step_sample

tests/test_distibution.py:23–41  ·  view source on GitHub ↗

Sampling a step function should only return two value.

(self)

Source from the content-addressed store, hash-verified

21 assert np.isclose(y_at_xmin, 0.0)
22
23 def test_step_sample(self):
24 """ Sampling a step function should only return two value.
25 """
26 nmedge = 600.0
27 nmmin, nmmax = (400.0, 800.0)
28 spacing = 1.0
29 x = np.arange(nmmin, nmmax + spacing, spacing)
30 abs_spec = np.column_stack((x, bandgap(x, nmedge, 1.0))) # ends a mid range.
31 dist = Distribution(abs_spec[:, 0], abs_spec[:, 1], hist=True)
32 xmin = dist.sample(0)
33 assert np.isclose(xmin, nmmin)
34 xmax = dist.sample(1) # The probabiliity of getting a value > nmedge is zero
35 assert np.isclose(xmax, nmedge)
36 pmin = dist.lookup(nmmin)
37 pmax = dist.lookup(nmmax)
38 assert pmin >= 0.0 and pmin <= dist.lookup(nmmin+spacing)
39 assert pmax == 1.0
40 values = dist.sample(np.linspace(dist.lookup(599-spacing), dist.lookup(600+spacing), 10000))
41 assert len(set(values)) == 3
42

Callers

nothing calls this directly

Calls 4

sampleMethod · 0.95
lookupMethod · 0.95
bandgapFunction · 0.90
DistributionClass · 0.90

Tested by

no test coverage detected