Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lundberg committed Jun 3, 2018
1 parent 2a8e1c0 commit d0a754a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ venv/
docs/build
__pycache__/
*.egg-info/
.eggs/
dist/
build/
.pytest_cache/
.tox/
*.pyc
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ To eliminate overshoot in certain types of systems, you can calculate the [propo
pid.proportional_on_measurement = True
```

## Tests
Use the following to run tests:
```
tox
```

## License
Licensed under the [MIT License](https://github.com/m-lundberg/simple-pid/blob/master/LICENSE.md).
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='simple-pid',
version='0.1.2',
version='0.1.3',
description='A simple, easy to use PID controller',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
35 changes: 35 additions & 0 deletions tests/test_pid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import time
import pytest
from simple_pid import PID


def test_zero():
pid = PID(1, 1, 1, setpoint=0)
assert pid(0) == 0


def test_P():
pid = PID(1, 0, 0, setpoint=10, sample_time=None)
assert pid(0) == 10
assert pid(5) == 5


def test_control():
pid = PID(2, 1, 1, setpoint=10)
PV = 0

def update_system(C, dt):
return PV + C*dt - 1*dt

start_time = time.time()
last_time = start_time

while time.time() - start_time < 10:
C = pid(PV)
PV = update_system(C, time.time()-last_time)

last_time = time.time()

# check if system has converged
assert abs(PV - 10) < 0.1
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[tox]
envlist = py27, py36, pypy

[testenv]
commands = pytest
deps =
pytest

0 comments on commit d0a754a

Please sign in to comment.