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

ShouldBeZero matcher #819

Closed
LeoColman opened this issue Jun 10, 2019 · 1 comment · Fixed by #848
Closed

ShouldBeZero matcher #819

LeoColman opened this issue Jun 10, 2019 · 1 comment · Fixed by #848
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones. good-first-issue 👶 Suitable for newcomers looking to contribute to the project.
Milestone

Comments

@LeoColman
Copy link
Member

Int, Double, Long, (...) should have a special matcher to verify if it's zero.

This matcher should also have an opposite, to verify it's not zero.

myInt.shouldBeZero()
myDouble.shouldNotBeZero()

Special cases to pay attention to: Double.NaN and Double.POSITIVE_INFINITY/Double.NEGATIVE_INFINITY.

These can be added to the kotlintest-assertions module. There can be a matcher for each numeric type, or a Number matcher that match them all.

An example on how to start the isZero method:

fun Number.isZero(): Boolean {
  return when(this) {
    is Double -> this == 0.0    // Verification for NaN
    is Float -> this == 0.0     // Verification for NaN
    else -> this.toLong() == 0L
  }
}
@LeoColman LeoColman added enhancement ✨ Suggestions for adding new features or improving existing ones. help wanted good-first-issue 👶 Suitable for newcomers looking to contribute to the project. labels Jun 10, 2019
@LeoColman LeoColman changed the title isZero matcher ShouldBeZero matcher Jun 10, 2019
@sksamuel sksamuel modified the milestones: 3.4, 3.5 Jun 12, 2019
@sksamuel
Copy link
Member

This could go in either 3.4 or 3.5 depending on time.

@sksamuel sksamuel mentioned this issue Jun 12, 2019
39 tasks
sksamuel pushed a commit that referenced this issue Jun 23, 2019
#848)

* added shouldBeZero and shouldNotBeZero matcher for number types

* using infix call for double

* created same matcher for float and added unit tests

* added empty line on end of file

* moved float functions to float package

* added items do matchers docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones. good-first-issue 👶 Suitable for newcomers looking to contribute to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants