Skip to content

min/max, changes + tests#1

Merged
Informaticore merged 6 commits into
Informaticore:masterfrom
davidg238:master
Apr 14, 2023
Merged

min/max, changes + tests#1
Informaticore merged 6 commits into
Informaticore:masterfrom
davidg238:master

Conversation

@davidg238

Copy link
Copy Markdown
Contributor

Added min/max, made suggestions, added tests but do not understand assertException ... see new tests

@Informaticore Informaticore left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hey I reviewed you PR - thank you very much for contributing!

Comment thread src/ringbuffer.toit
Comment thread src/ringbuffer.toit Outdated
buffer[head] = value
head = (head + 1) % size_
count = min (count + 1) size_
count = (min (count + 1) size_)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why you put brackets here? it is a method call, it is not really needed I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no need, delete

Comment thread src/ringbuffer.toit Outdated
maximum -> float:
return reduce : | a b | max a b

//@davidg238: what is this method for?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I just added a minimum methode for some reason to check 2 values to which is the smaller one. Is there a different solution you would suggest? Couldn't find a system call (I also was not checking very hard)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, they are tucked away in core/utils: https://libs.toit.io/core/utils/library-summary#max(2%2C0%2C0%2C)

Comment thread test/test_ringbuffer.toit Outdated
class TestRingbuffer implements TestCase:

run:
// test_ringbuffer_empty //@davidg238: not calling assertException correctly?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes - the assertException method is a bit confusing because Exception can be anything. You basically call the method first and catch the exception, then you check the exception like:

exception := catch:
      ringbuffer.average
assertException exception

I just realized that I used it incorrectly myself in the test for the limit. I think the assertException can be done smarter where you give it a block which the method will run and check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It looked like the test framework (love the name) was young, so I flagged it rather than attempt to fix it. A block would be preferable to simplify use.

Comment thread test/test_ringbuffer.toit Outdated
assertEquals 2.3 ringbuffer.average
assertEquals 2.3 ringbuffer.minimum
assertEquals 2.3 ringbuffer.maximum
// assertEquals 0.0 ringbuffer.std_deviation //@davidg238: should entries be required?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think the deviation can only be calculated if there are at least two entries. so the deviation should be simply return 0.0 if it is called with less then 2 entries, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not do the calculation and return 0.0 ... yes.

@Informaticore Informaticore merged commit 77262a4 into Informaticore:master Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants