Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mock_slave and lots of magic numbers #539

Merged
merged 1 commit into from
Mar 25, 2020

Conversation

kyllingstad
Copy link
Member

This fixes issue #538, "mock_slave violates assumptions, causing tests to be ill-defined". Basically, what I've done is to make the user-supplied functions act on the outputs rather than on the internal states.

This had quite substantial effects on some of the tests, which depended on the wrong behaviour. To compensate and, to some extent, restore the old behaviour in a "correct" way, I've had to add some new functionality to mock_slave, namely:

  • The possibility to have outputs depend on time as well as inputs.
  • The possibility to have a custom function called at each time step.

Finally, I've taken this opportunity to make some of the tests slightly more readable by replacing magic numbers with named variables/constants. This includes:

  • Simulator indexes, which were assumed to be sequential in some tests
  • Variable references, which were assumed to be 0 and 1 for mock_slave's variables

The magic numbers were making the tests hard to read, and therefore also to fix. Besides, while the above assumptions are correct at the moment, that need not be the case in the future.

This fixes issue #538, "`mock_slave` violates assumptions, causing
tests to be ill-defined".  Basically, what I've done is to make the
user-supplied functions act on the outputs rather than on the internal
states.

This had quite substantial effects on some of the tests, which depended
on the wrong behaviour.  To compensate and, to some extent, restore
the old behaviour in a "correct" way, I've had to add some new
functionality to `mock_slave`, namely:

- The possibility to have outputs depend on time as well as inputs.
- The possibility to have a custom function called at each time step.

Finally, I've taken this opportunity to make some of the tests slightly
more readable by replacing magic numbers with named variables/constants.
This includes:

- Simulator indexes, which were assumed to be sequential in some tests
- Variable references, which were assumed to be 0 and 1 for
  `mock_slave`'s variables

The magic numbers were making the tests hard to read, and therefore also
to fix.  Besides, while the above assumptions are correct at the moment,
that need not be the case in the future.
@kyllingstad kyllingstad added the bug Something isn't working label Mar 16, 2020
@kyllingstad kyllingstad requested review from ljamt and hplatou March 16, 2020 14:04
@kyllingstad kyllingstad self-assigned this Mar 16, 2020
Copy link
Member

@ljamt ljamt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix and clean up!

@kyllingstad kyllingstad merged commit 78a0bce into master Mar 25, 2020
@kyllingstad kyllingstad deleted the bugfix/538-bad-mock_slave-behaviour branch March 25, 2020 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants