Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
lschwetlick committed Jun 26, 2023
1 parent 7d1e14a commit a05e952
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion conftest_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def pytest_configure(config):
seed = config.getvalue("seed")
# if seed was not set by the user, we set one now
if seed is None or seed == ('NO', 'DEFAULT'):
config.option.seed = int(np.random.randint(2**31-1))
config.option.seed = int(np.random.randint(2 ** 31 - 1))


def pytest_report_header(config):
Expand Down
14 changes: 7 additions & 7 deletions plot_logfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def plot_trajectory(n, r, x0, fname="single_trajectory.png"):
returns
fig, ax (matplotlib objects)
"""
l = iterate_f(n, x0, r)
xs = iterate_f(n, x0, r)
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(list(range(n)), l)
ax.plot(list(range(n)), xs)
fig.suptitle('Logistic Function')

fig.savefig(fname)
Expand Down Expand Up @@ -57,11 +57,11 @@ def plot_bifurcation(start, end, step, fname="bifurcation.png", it=100000,
y = []

for r in r_range:
l = iterate_f(it, 0.1, r)
ll = l[len(l) - last::].copy()
lll = np.unique(ll)
y.extend(lll)
x.extend(np.ones(len(lll)) * r)
xs = iterate_f(it, 0.1, r)
all_xs = xs[len(xs) - last::].copy()
unique_xs = np.unique(all_xs)
y.extend(unique_xs)
x.extend(np.ones(len(unique_xs)) * r)

fig, ax = plt.subplots(figsize=(20, 10))
ax.scatter(x, y, s=0.1, color='k')
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Make a file `logistic.py` and `test_logistic.py` in the same folder as this
readme and the `plot_logfun.py` file. Implement the code for the logistic map
in the `logistic.py` file:

a) Implement the logistic map f(π‘₯)=π‘Ÿβˆ—π‘₯βˆ—(1βˆ’π‘₯) . Use `@parametrize`
to test the function for the following cases:
a) Implement the logistic map f(π‘₯)=π‘Ÿβˆ—π‘₯βˆ—(1βˆ’π‘₯) . Import pytest and use
`@pytest.mark.parametrize` to test the function for the following cases:
```
x=0.1, r=2.2 => f(x, r)=0.198
x=0.2, r=3.4 => f(x, r)=0.544
Expand All @@ -16,7 +16,7 @@ to test the function for the following cases:

b) Implement the function `iterate_f` that runs `f` for `it`
iterations, each time passing the result back into f.
Use `@parametrize` to test the function for the following cases:
Use `@pytest.mark.parametrize` to test the function for the following cases:
```
x=0.1, r=2.2, it=1 => iterate_f(it, x, r)=[0.198]
x=0.2, r=3.4, it=4 => iterate_f(it, x, r)=[0.544, 0.843418, 0.449019, 0.841163]
Expand All @@ -32,9 +32,9 @@ Try with values `r<3`, `r>4` and `3<r<4` to get a feeling for how the function
behaves differently with different parameters. Note that your input x0 should
be between 0 and 1.

## Exercise 2 -- Check the convergence of an attractor using randomi testing
## Exercise 2 -- Check the convergence of an attractor using random testing
a) Write a randomized test that checks that, for `r=1.5`, all
starting points converge to the attractor `f(x, r) = 1/3`.
starting points x0 converge to the same value (attractor) `f(x, r) = 1/3`.

b) Use `pytest.mark` to mark the tests from the previous exercise with one mark
(they relate to the correct implementation of the logistic map) and the
Expand Down

0 comments on commit a05e952

Please sign in to comment.