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

feat(NumericBuiltinFunction): Add random number function #528

Merged
merged 8 commits into from
Oct 6, 2022

Conversation

kaaquist
Copy link
Contributor

@kaaquist kaaquist commented Oct 4, 2022

Description

  • Added random number function and related tests and documentation.

Related issues

closes #506

@CLAassistant
Copy link

CLAassistant commented Oct 4, 2022

CLA assistant check
All committers have signed the CLA.

@kaaquist kaaquist marked this pull request as draft October 4, 2022 21:04
@kaaquist
Copy link
Contributor Author

kaaquist commented Oct 4, 2022

Still needed documentation and I also have a question in regards to test. I would like to test it the number returned is between 0.0f and 1.0f. I have created a test that I would expect would pass but I get an exception.
Test:

it should "return a number between 0.0 and 1.0 " in {
    eval(" random number() ") should (be >= ValNumber(0.0) and be <= ValNumber(1.0))
}

Exception:

overloaded method should with alternatives:
  (endWithWord: org.scalatest.matchers.dsl.EndWithWord)(implicit ev: org.camunda.feel.syntaxtree.Val <:< String): BuiltinNumberFunctionsTest.this.ResultOfEndWithWordForString <and>
  (startWithWord: org.scalatest.matchers.dsl.StartWithWord)(implicit ev: org.camunda.feel.syntaxtree.Val <:< String): BuiltinNumberFunctionsTest.this.ResultOfStartWithWordForString <and>
  (includeWord: org.scalatest.matchers.dsl.IncludeWord)(implicit ev: org.camunda.feel.syntaxtree.Val <:< String): BuiltinNumberFunctionsTest.this.ResultOfIncludeWordForString <and>
  (notExist: org.scalatest.matchers.dsl.ResultOfNotExist)(implicit existence: org.scalatest.enablers.Existence[org.camunda.feel.syntaxtree.Val]): org.scalatest.Assertion <and>
  (existWord: org.scalatest.matchers.dsl.ExistWord)(implicit existence: org.scalatest.enablers.Existence[org.camunda.feel.syntaxtree.Val]): org.scalatest.Assertion <and>
  (containWord: org.scalatest.matchers.dsl.ContainWord)org.scalatest.matchers.dsl.ResultOfContainWord[org.camunda.feel.syntaxtree.Val] <and>
  (haveWord: org.scalatest.matchers.dsl.HaveWord)BuiltinNumberFunctionsTest.this.ResultOfHaveWordForExtent[org.camunda.feel.syntaxtree.Val] <and>
  (beWord: org.scalatest.matchers.dsl.BeWord)BuiltinNumberFunctionsTest.this.ResultOfBeWordForAny[org.camunda.feel.syntaxtree.Val] <and>
  (inv: org.scalactic.TripleEqualsSupport.TripleEqualsInvocationOnSpread[org.camunda.feel.syntaxtree.Val])(implicit ev: Numeric[org.camunda.feel.syntaxtree.Val]): org.scalatest.Assertion <and>
  [U](inv: org.scalactic.TripleEqualsSupport.TripleEqualsInvocation[U])(implicit constraint: org.scalactic.CanEqual[org.camunda.feel.syntaxtree.Val,U]): org.scalatest.Assertion <and>
  (notWord: org.scalatest.matchers.dsl.NotWord)org.scalatest.matchers.dsl.ResultOfNotWordForAny[org.camunda.feel.syntaxtree.Val] <and>
  [TYPECLASS1[_], TYPECLASS2[_]](rightMatcherFactory2: org.scalatest.matchers.dsl.MatcherFactory2[org.camunda.feel.syntaxtree.Val,TYPECLASS1,TYPECLASS2])(implicit typeClass1: TYPECLASS1[org.camunda.feel.syntaxtree.Val], typeClass2: TYPECLASS2[org.camunda.feel.syntaxtree.Val]): org.scalatest.Assertion <and>
  [TYPECLASS1[_]](rightMatcherFactory1: org.scalatest.matchers.dsl.MatcherFactory1[org.camunda.feel.syntaxtree.Val,TYPECLASS1])(implicit typeClass1: TYPECLASS1[org.camunda.feel.syntaxtree.Val]): org.scalatest.Assertion <and>
  (rightMatcherX1: org.scalatest.matchers.Matcher[org.camunda.feel.syntaxtree.Val])org.scalatest.Assertion
 cannot be applied to (org.scalatest.matchers.Matcher[org.camunda.feel.syntaxtree.ValNumber])
    eval(" random number() ") should (be >= ValNumber(0.0) and be <= ValNumber(1.0))

@kaaquist kaaquist changed the title feat(Numeric) - Add random number function feat(NumericBuiltinFunction): Add random number function Oct 5, 2022
@saig0
Copy link
Member

saig0 commented Oct 5, 2022

I would like to test it the number returned is between 0.0f and 1.0f. I have created a test that I would expect would pass but I get an exception.

Nice try. 👍

Instead, you could use a match-case and extract the number first.

For example:

eval(" random number() ") match {
  case ValNumber(x) => x should (be >= 0 and be <= 1)  
  case other => fail()
}

Signed-off-by: Kasper Aaquist Johansen <[email protected]>
Signed-off-by: Kasper Aaquist Johansen <[email protected]>
@kaaquist kaaquist marked this pull request as ready for review October 5, 2022 15:06
@saig0 saig0 self-requested a review October 6, 2022 04:23
Copy link
Member

@saig0 saig0 left a comment

Choose a reason for hiding this comment

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

@kaaquist thank you for your contribution. 🎉

The changes look good. 👍 I have only a few minor comments.

@saig0 saig0 self-requested a review October 6, 2022 11:14
@saig0 saig0 merged commit ad33eab into camunda:main Oct 6, 2022
@saig0
Copy link
Member

saig0 commented Oct 6, 2022

@kaaquist your PR is merged. :tada: Thank you for applying the hints. :cookie:


This pull request counts toward the Hacktoberfest challenge. If you contributed four pull requests then you can complete your Camunda Hacktoberfest challenge here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add new built-in function to generate random numbers
3 participants