Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Princess | April
    @NthPortal
    perhaps to ask a slightly different question: would it be safe to freeze the internal Seq of props once Properties#properties is called?
    Aaron S. Hawley
    @ashawley
    @NthPortal I'm not sure. Not a part of the code base I know thoroughly. What would be the purpose or benefit of "freezing"?
    Princess | April
    @NthPortal
    mostly so that you get a sensible error message
    one of the things I'm trying to do is make iterators in the stdlib fail-fast, and adding a property while iterating over them to execute them violates that. with just the core scala change, nesting a property would give you a rather unhelpful error message that "mutation occurred after iterator creation", which is unhelpful
    Princess | April
    @NthPortal
    to put it differently, violating the constraints of the testing framework should fail cleanly, rather than in an unexpected or inconsistent way
    Guillaume Martres
    @smarter
    I don't want to put undue pressure on anyone, but I'd really like to see a 1.15.0 release for scalacheck, there's now an open milestone for that but it's not clear to me how critical the issues in it are for the release: typelevel/scalacheck#668
    Sergey Torgashov
    @satorg
    Hi everyone. I'm struggling to find any guide on when and how Cogen should be used. Could you help me with it please?
    Keir Lawson
    @keirlawson
    Hello, I'm wondering how I can create a generator of a list of values sourced from two other generators, but guaranteeing that one of the generators is used at least once?
    Ie I have a genMobilePhone and a genHomePhone andI want to make a genPhoneListWithAtLeastOneMobile
    Obviously I can do Gen.nonEmptyList(Gen.oneOf(genMobilePhone, genHomePhone)) but that wont guarantee I have at least one mobile...
    Katherine Prevost
    @hypatian
    I'd generate that list then add one mobile to it and optionally shuffle.
    (Or generate a list, a single required item, and a position in the list, would be a way to do that completely in terms of generating a tuple of existing things.)
    Keir Lawson
    @keirlawson
    ok, that makes sense, thanks :)
    Ben Spencer
    @dangerousben
    I'm looking for a way to use magnolia to derive scalacheck generators and google has turned up at least 3 projects, 2 of which have relatively recent commits - is there a preferred / endorsed one?
    Deenar Toraskar
    @deenar
    Hi I was looking to a string generator based on regular expressions, there seems to be a couple of options that turn up https://github.com/wolfendale/scalacheck-gen-regexp and https://github.com/non/antimirov/#scalacheck-support. Has anyone used either of these? Is there a preferred option?
    Ghost
    @ghost~5cc594f1d73408ce4fbee018
    How can I generate an arbitrary instance of final case class VisitActivityQuestionAssignmentStudyEnvironment( id: UUID, description: String, orderIndex: OrderIndex, methodAssignments: Seq[MethodAssignment] ) { require(description.trim.nonEmpty, "Description parameter should not be empty") }
    Aaron S. Hawley
    @ashawley
    Alex
    @jhnsmth
    Hi! Is scalacheck scaladoc available online ? The link on http://www.scalacheck.org/documentation.html seems to be broken and I cant find any other
    Sergey Torgashov
    @satorg
    @jhnsmth , I guess you can find some info here: https://github.com/typelevel/scalacheck/blob/master/doc/UserGuide.md
    Jakub Kozłowski
    @kubukoz
    Hi, is there a way to limit the size of an Arbitrary[Int], without "overriding" the implicit instance for it?
    I was trying to change the sizeRange parameter (I'm using scalatest's ScalaCheckPropertyChecks) but that doesn't seem to have an effect.
    ah, apparently numeric generators don't ask for size
    Julien Truffaut
    @julien-truffaut
    Hi all, as anyone tried to generate a Gen for ExecutionContext?
    Cédric Gourlay
    @kidi

    Hi all, I tried the 1.15.2 with scala 3.0.0-M3 and got a weird error message

    object Gen: org.scalacheck.Gen
    value foreach is not a member of org.scalacheck.Gen[Int]

    it is something new ? I may have missed something...

    Aaron S. Hawley
    @ashawley
    @kidi That's strange. I haven't worked with Scala 3 much, but I also don't recall using foreach with Gen. Would you like to open an issue it so we can study it further?
    Cédric Gourlay
    @kidi
    @ashawley thx for the reply; I tried in 2.13.4 and I actually probably don't use it correctly but with the .sample the option can provide it. Let me know if this kind of usage need an issue ?
    val pw = new PrintWriter(f)
        for {
          sample <- Gen.choose(5000, 100000).sample
          _ <- 0 until sample
          t <- Gen.choose(-500f, 500f).sample
        } {
          pw.write(s"$t\n")
        }
        pw.close()
    Nicolas Rinaudo
    @nrinaudo

    I have a question about the default Shrink[Int] instance.

    From what I can see, it "simply" halves its input it reaches 0. This obviously works, but isn't very precise. Let's say, for example, that you have the following property:

      val propTest = forAll { i: Int =>
        i < 156
      }

    If you get an input of, say, 482, it'll get halved to 241, then get stuck there - it has no way of getting back "up" from (241 / 2) to 156.

    An alternative implementation would be to halve the input, but then explore the larger part of the halved space:

      implicit val intShrink: Shrink[Int] = {
    
        def halves(inf: Int, sup: Int): Stream[Int] = {
          if(math.abs(sup - inf) <= 1) Stream.empty
          else {
            val mid = inf + (sup - inf) / 2
            mid #:: halves(mid, sup)
          }
        }
    
        Shrink(i => halves(0, i))
      }

    I've ran some tests and this seems to consistently find the most precise value possible.

    Was there any reason it wasn't implemented that way? For example, "hoping" for a value closer to 0 and avoiding getting stuck in a local optimum?

    Aaron S. Hawley
    @ashawley
    @nrinaudo Well, complexity would be a concern, but I presume it was implemented this way since it was the simplest thing. Others have raised making this improvement of shrinking on a known range and not just zero. It seems worth pursuing.
    Fortunately, not a lot of property testing is numerical it's structural or algebraic. Not that it's worth improving, but might explain why this doesn't come up, often.
    To be fair to the current implementation, numerical test generators are supposed to run with increasing values so a failure would cause shrinking to use decreasing values, but it's not hard to find trivial cases, as you have, where that doesn't work optimally.
    Nicolas Rinaudo
    @nrinaudo

    @ashawley yeah I've actually pushed the experience further and it's not actually a good idea. Binary search works because you keep a running context - [a, b]. With shrinking, you do have that context while looking for the next failing test case, but you lose it as soon as you find that test case.

    That is, you can be looking for your local minimum in [100, 150], and you'll end up searching in [0, 125].

    You end up spending far more time looking at values you've already explored, and I'm not at all convinced it's safe - there *must be some infinite loop scenario

    Basavaraj Kalloli
    @scalolli
    Hello i have just updated Scala Version to 2.13.4, trying to get rid off these Stream warnings:
    def noShrink[T]: Shrink[T] = Shrink(_ => Stream.empty)
    But I see the scalacheck library still expects a Stream, whats the recommendation here?
    João Costa
    @JD557
    you might have to use @nowarn, not sure if that's the only way
    Aaron S. Hawley
    @ashawley
    @scalolli Doesn't the warning suggest using LazyList?
    Actually, we couldn't overload that method to support LazyList. We had to add a new method withLazyList in #627.
    3 replies
    Aaron S. Hawley
    @ashawley
    If you're having to support 2.12 or earlier, then there may be nothing you can do about the warning.
    Artem Nikiforov
    @nikiforo

    Hi, I want to include some properties into ordinary AnyFunSuite, for example

    MyAwesomeTest extends AnyFunSuite {
      test("ordinary test") {
        assert(true)
      }
    
      test("scalacheck test" {
        val prop = forAll { b: Boolean =>
          b
        }
        prop.check()
      }
    }

    How can I launch property check in that scenario? I want to have a red failed test instead of

    ! Falsified after 0 passed tests.
    > ARG_0: 0
    > ARG_0_ORIGINAL: 71

    I haven't found the answer in https://github.com/typelevel/scalacheck/blob/master/doc/UserGuide.md

    Aaron S. Hawley
    @ashawley
    @nikiforo That looks like Scalatest. You might refer to their docs https://www.scalatest.org/user_guide/writing_scalacheck_style_properties
    You can probably just write
    test("scalacheck test") {
      forAll { b: Boolean =>
          b
        }
    }
    Keir Lawson
    @keirlawson
    Hey, I'm wanting to generate a string up to a given number of characters, what's the best way to do this? I see I can use listOfN for a fixed length, but not sure how to get the "up to"
    Dmitry Polienko
    @nigredo-tori
    @keirlawson,
    Gen.choose(0, max)
      .flatMap(Gen.stringOfN(_, arbitrary[Character]))
    Basavaraj Kalloli
    @scalolli
    Another deprecation warnings I am trying to fix with Scala 2.13.4 is with these:
    Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method dispatch,
    or remove the empty argument list from its definition (Java-defined methods are exempt).
    In Scala 3, an unapplied method like this will be eta-expanded into a function.
          forAll {}
    I cannot find an alternative to the forAll {} syntax, is there any obvious alternative that I am missing in the library?
    2 replies
    Aaron S. Hawley
    @ashawley
    @scalolli What are you doing with forAll that produces that warning?
    2 replies
    Nicolas Rinaudo
    @nrinaudo
    @keirlawson i think that’s what the sized combinator is meant for
    Nicolas Rinaudo
    @nrinaudo
    The resize combinator, I mean
    Nicolas Rinaudo
    @nrinaudo

    Here's a different attempt at shrinking ints (basically a Scala version of the QuickCheck implementation) which seems to have better results than the default one: https://scastie.scala-lang.org/XbfRtWfFRG6rAKy6mUVbjg

    Note that, contrary to the default ScalaCheck instance, it does not explore negative values, simply because QuickCheck doesn't.

    Is there any reason the QuickCheck implementation wasn't ported over as is?

    If not, I'm happy to make a more generic version and submit a PR...