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

feature extractor for Iterator.next #1765

Closed
14 tasks
robstoll opened this issue May 23, 2024 · 5 comments · Fixed by #1816
Closed
14 tasks

feature extractor for Iterator.next #1765

robstoll opened this issue May 23, 2024 · 5 comments · Fixed by #1816
Assignees
Labels
Milestone

Comments

@robstoll
Copy link
Owner

Code related feature

expect(iterator).next().toEqual(true)

//instead of
expect(iterator).feature { f(it::next) }.toEqual(true)

However, we also want to show a better error message in case there is not a next

Following the things you need to do:

logic

  • extend IteratorAssertions with a function next (see ListAssertions.get as a guideline)
  • implement next in DefaultIteratorAssertions.kt by using container.extractFeature... (see DefaultListAssertions.get)

api-fluent

  • provide a val which returns Expect<T> in iteratorFeatureExtractors.kt (see listFeatureExtractors.kt as a guideline)
  • provide a fun which expects an assertionCreator-lambda and returns Expect<E> (where E is the element type in Iterator<E>) in iteratorFeatureExtractors.kt (see listFeatureExtractors.kt as a guideline)
  • extend or write a separate Spec named IteratorFeatureExtractorSpec in specs -> commonMain (see for instance ListExpectationsSpec) and extend it in atrium-api-fluent -> commonTest
  • add samples to IteratorFeatureExtractorSamples.kt (see ListFeatureExtractorSamples.kt as guideline -- try to provide the reason why an expectation fails)
  • add @sample with link to your sample method to the two functions in iteratorExpectations.kt
  • add @since 1.3.0 (adapt to current milestone) to KDOC of the two functions in iteratorExpectations.kt

api-infix

  • provide a val which returns Expect<T> in iteratorExpectations.kt (see listExpectations.kt as a guideline)
  • provide a fun which expects an assertionCreator-lambda and returns Expect<E> (where E is the element type in Iterator<E>) in iteratorFeatureExtractors.kt (see listFeatureExtractors.kt as a guideline)
  • extend or write a separate Spec named IteratorFeatureExtractorSpec in specs -> commonMain (see for instance ListExpectationsSpec) and extend it in atrium-api-infix -> commonTest
  • add samples to IteratorFeatureExtractorSamples.kt (see ListFeatureExtractorSamples.kt as guideline -- try to provide the reason why an expectation fails)
  • add @sample with link to your sample method to the two functions in iteratorExpectations.kt
  • add @since 1.3.0 (adapt to current milestone) to KDOC of the two functions in iteratorExpectations.kt

Your first contribution?

  • Write a comment I'll work on this if you would like to take this issue over.
    This way we get the chance to revise the description in case things have changed in the meantime, we might give you additional hints and we can assign the task to you, so that others do not start as well.
  • See Your first code contribution for guidelines.
  • Do not hesitate to ask questions here or to contact us via Atrium's slack channel if you need help
    (Invite yourself in case you do not have an account yet).
@hubtanaka
Copy link
Collaborator

I'll work on this

@hubtanaka
Copy link
Collaborator

My weekend is almost over, but still work in progress.
Therefore, I would like to write a short interim report once.

I'm currently struggling with IteratorExpectationsSpec.kt.
I thought that next function throw an AssertionError when it is invoked by the iterator of the empty list.
However, toThrow , in expect { /* empty list iterator invoke next */ }.toThrow<AssertionError>{ .. } , throws AtriumError.
I've read ListExpectationsSpec.kt and the getFunction related code, but I still can't find what to do.

So it seems better to write samples first.
Then return to the TODO for IteratorExpectationsSpec.kt.

@robstoll
Copy link
Owner Author

AtriumError is an AssertionError, we don't mention it in the API as it is an implementation detail. We might as well change to another AssertionError in the future.

@hubtanaka
Copy link
Collaborator

hubtanaka commented Aug 19, 2024

Thanks for your comment.

AtriumError is an AssertionError

I see. Then I might have been missing something else.

By the way, today I wrote samples for Iterable.next (api-fluent).
As a result, the tests passed.
Therefore, my next function implementation seems not so bad at least.

So, I think I am just misunderstanding something about IteratorExpectationsSpec.
I'll read some related code tomorrow and try to find it out.

@hubtanaka
Copy link
Collaborator

hubtanaka commented Aug 20, 2024

I finally realized what I have missed.

In toThrow<AssertionError>{ .. }, I have passed TO_HAVE into messageToContain.
I fixed it to SIZE_EXCEEDED, then Test passed.

AtriumError is an AssertionError

Thanks to this comment I realized my mistake.

@robstoll robstoll linked a pull request Aug 21, 2024 that will close this issue
14 tasks
@robstoll robstoll added this to the 1.3.0 milestone Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants