-
Notifications
You must be signed in to change notification settings - Fork 34
High-level wire implementation, complete with unit tests #189
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb61617
Added crude high level Wire implementation + Wire unit tests.
lsaca05 4989505
Forgot to add new wire test file
lsaca05 13862bc
me dumb and fixed wire tests, though there's an anomaly in compilation
lsaca05 226bc18
Completed wire implementation with address tracking via maps + tests
lsaca05 42aaa39
Wire implementation converted from map to deque, courtesy of James Fo…
lsaca05 6ddd254
Here's a newline for you:
lsaca05 194af8b
Merge branch 'master' of https://github.com/Arduino-CI/arduino_ci int…
lsaca05 d6c3bb8
Cleaned up crude fixes for name clashes in wire header.
lsaca05 2821146
Removed requestFrom() overload to reduce ambiguity. Added wire test c…
lsaca05 01eeaf3
Forgot to add test file to last commit. This is the real commit addin…
lsaca05 7593ab8
Updated wire tests to be more readable. Added additional assertion fo…
lsaca05 f2fd95a
Forgot to scroll down and update half of the last test for last commi…
lsaca05 bb25c28
Merge branch 'master' of https://github.com/Arduino-CI/arduino_ci int…
lsaca05 e4fd2e4
Removed the assertion added 3 commits ago. Didn't realize failed requ…
lsaca05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <ArduinoUnitTests.h> | ||
#include <Arduino.h> | ||
#include <Wire.h> | ||
using std::deque; | ||
|
||
unittest(begin_write_end) { | ||
deque<uint8_t>* mosi = Wire.getMosi(14); | ||
assertEqual(0, mosi->size()); | ||
Wire.begin(); | ||
Wire.beginTransmission(14); | ||
Wire.write(0x07); | ||
Wire.write(0x0E); | ||
Wire.endTransmission(); | ||
assertEqual(2, mosi->size()); | ||
assertEqual(0x07, mosi->front()); | ||
mosi->pop_front(); | ||
assertEqual(0x0E, mosi->front()); | ||
mosi->pop_front(); | ||
assertEqual(0, mosi->size()); | ||
} | ||
|
||
unittest(readTwo_writeOne) { | ||
Wire.begin(); | ||
deque<uint8_t>* miso; | ||
miso = Wire.getMiso(19); | ||
miso->push_back(0x07); | ||
miso->push_back(0x0E); | ||
miso = Wire.getMiso(34); | ||
miso->push_back(1); | ||
miso->push_back(4); | ||
miso->push_back(7); | ||
|
||
assertEqual(0, Wire.requestFrom(19, 3)); | ||
assertEqual(2, Wire.requestFrom(19, 2)); | ||
assertEqual(2, Wire.available()); | ||
assertEqual(0x07, Wire.read()); | ||
assertEqual(1, Wire.available()); | ||
assertEqual(0x0E, Wire.read()); | ||
assertEqual(0, Wire.available()); | ||
assertEqual(3, Wire.requestFrom(34, 3)); | ||
assertEqual(3, Wire.available()); | ||
assertEqual(1, Wire.read()); | ||
assertEqual(2, Wire.available()); | ||
assertEqual(4, Wire.read()); | ||
assertEqual(1, Wire.available()); | ||
assertEqual(7, Wire.read()); | ||
assertEqual(0, Wire.available()); | ||
|
||
Wire.beginTransmission(47); | ||
for (int i = 1; i < 4; i++) { | ||
Wire.write(i * 2); | ||
} | ||
Wire.endTransmission(); | ||
deque<uint8_t>* mosi = Wire.getMosi(47); | ||
|
||
assertEqual(3, mosi->size()); | ||
assertEqual(2, mosi->front()); | ||
mosi->pop_front(); | ||
assertEqual(2, mosi->size()); | ||
assertEqual(4, mosi->front()); | ||
mosi->pop_front(); | ||
assertEqual(1, mosi->size()); | ||
assertEqual(6, mosi->front()); | ||
mosi->pop_front(); | ||
assertEqual(0, mosi->size()); | ||
} | ||
|
||
unittest_main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of random-looking numbers in this unit test, which might be better expressed as named variables. Otherwise, please add some comments that explain the different sections of the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than named variables, let's just add comments along the line of "try some random value (0x07) sent to some random slave (14)."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the aid of your comments I can see what you're after. But I'm going to insist on using named constants.
The reason for this is purely readability; as a maintainer I have to scan a lot of contributions in a short amount of time and solve problems in them. Consider the following chunk of this test as currently written:
This requires me (and any future contributors to this code) to puzzle out things like
1
,4
, and7
, here being conceptually related to each other (and to a definition a dozen lines earlier) even though the values no longer appear on adjacent lines1
inassertEqual(1, Wire.read());
andassertEqual(1, Wire.available());
represent completely different things even though they are are expressed in the exact same wayThis affects numeric tests more than strings or objects (which end up being a bit more self-descriptive).
Here's an example of how I'd like this to be written:
Similar for the values
19
and34
-- these should be named variables, so that the function calls can be more indicative of what is being input.I chose
random
in the naming to reflect your comment, butexpected
(e.g.expectedIntValues
/expectedByteValues
) orinput
also work. Or for things where you just have to pick a wire or port to work with,const int arbitraryIndex = 19
, etc. What needs to be conveyed is the difference between a specific value (e.g. a size) that's expected to be returned and an arbitrary number that just needs to match the input.