Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Katherine Prevost
    @hypatian

    Yup, I remembered where I ran into that and looking over my code again I have places where I'm using containerOfN[Array, Short](8, ...) and then I also guard that with a .suchThat({ _.length == 8 }). This is because scalacheck will try to "shrink" failing cases to something smaller that minimally illustrates the problem—but in my case, the length of the array must be 8 and if it's not an error is reported a different way (and that is tested for).

    So, everything would work fine right up until a test failure, and then the test failure would be reported on a value that it seemed like should never be generated anyway. And the suchThat check prevented that.

    Joao Azevedo
    @jcazevedo
    @hypatian: Makes sense. Thanks for the explanation!
    Mark de Jong
    @Fristi
    Hi, is there a way to run before or after each Prop invocation?
    Mark de Jong
    @Fristi
    I hacked around it for now Prop(params => after(prop(params)))
    after is a def after[B](a: B): B which cleans up my stuff
    efim
    @efim

    Hello everyone!

    In the work project while updating scalatest to 3.1.0-RC2 and scalacheck to 1.14.2
    one of the tests started failing with exceeding limit of discarded values

    I've tried to look at the arbitraries my colleague had set up, and don't see any obvious places where any discarding could take place

    Is there a way to figure out reason and place where the discards happen?

    efim
    @efim

    The problem goes away when in one of arbitraries I use Gen.oneOf(List(<stuff>))
    instead of Gen.oneOf(arbitrary1, arbitrary1, ..., arbitraryK)

    So maybe the problem is in
    /** Picks a random generator from a list */ def oneOf[T](g0: Gen[T], g1: Gen[T], gn: Gen[T]*): Gen[T] = { val gs = g0 +: g1 +: gn choose(0,gs.size-1).flatMap(gs(_)).suchThat(x => gs.exists(_.sieveCopy(x))) }

    but I'm at a loss in figuring this out. _.sieveCopy looks like being defined as true and maybe causes discards somehow, but nothing is clear for now

    efim
    @efim

    Problem turned out to be

    arbitrary of List of Gen.PosNum
    PosNum discards values and with possibly long lists by default discarded a lot

    I don't know why that worked in previous version of scalacheck
    Charles O'Farrell
    @charleso
    @efim If I had to guess it might have been this change: typelevel/scalacheck#451
    I'm not 100% sure but I believe suchThat will discard. I would have been tempted to use retryUntil (if that's the case).
    Charles O'Farrell
    @charleso
    Actually ignore that last comment, or at least the solution for int/long shouldn't need to filter at all. I'm not sure of the best way to make a generic solution across Num though.
    msinton
    @msinton
    Can anyone point me to how to reduce the number of cases a single test checks?
    I'm working with "scalatestplus-scalacheck" % "3.1.0.0-RC2"
    Sergey Kolbasov
    @sergeykolbasov

    Hi there

    Is there a similar to quickcheck Function http://hackage.haskell.org/package/QuickCheck-2.13.2/docs/Test-QuickCheck-Function.html#t:Function type class in scalacheck that allows to actually show the generated function?

    Aaron S. Hawley
    @ashawley
    What does this output mean? I don't do Haskell regularly.
    {"elephant"->1, "monkey"->1, _->0}
    Sergey Kolbasov
    @sergeykolbasov
    @ashawley it says "given elephant or monkey it produces 1, otherwise 0"
    it's essentially the show of Function
    Georgi Krastev
    @joroKr21
    But how could it be so simple? If you have String => Int there infinitely many possibilities
    Sergey Kolbasov
    @sergeykolbasov
    You need to have a table of [(String, Int)] and start shrinking it
    answer is a bit longer and involves partial functions, I'd sugest to watch https://www.youtube.com/watch?v=CH8UQJiv9Q4
    I could take some time to translate original implementation into Scala one, though I didn't work with scalacheck internals before
    (if folks find it useful)
    Georgi Krastev
    @joroKr21
    Ah I see that's interesting thanks for the video
    I don't know how useful it would be, I never found myself wanting to show a function
    Sergey Kolbasov
    @sergeykolbasov
    It's quite useful when you write laws for any functorial/monadic stuff
    Also when generating things like ReaderT, StateT
    Aaron S. Hawley
    @ashawley
    That's interesting. Maybe it's a capability that would be suited in Claimant. https://github.com/typelevel/claimant
    Jem Mawson
    @Synesso
    Hi. I have a scalacheck heavy project. When Specs2 upgraded scalacheck to 1.14.1-RC2 and I upgraded specs2, my project tests no longer terminate and instead thrash the cpu. etorreborre/specs2#788
    Aaron S. Hawley
    @ashawley
    I'm not sure. The only thing that comes to mind is https://github.com/typelevel/scalacheck/issues/401#issuecomment-512447262. Although, that resulted in stackoverflows for recursive Option generators.
    Christopher Davenport
    @ChristopherDavenport
    Is there a utf8 compatible string Gen somewhere I’m missing?
    Martijn Hoekstra
    @martijnhoekstra
    what's an utf8 compatible string? A string that can be encoded in UTF-8?
    Martijn Hoekstra
    @martijnhoekstra
    UTF-8 should never encode codepoints that are unpaired surrogates, but I wouldn't count on that for anything
    Adrian Legaspi
    @akilegaspi
    Hi everyone, I tried accessing the scalacheck documentation on the website and it seems that it's down with the error
    <Error>
      <Code>NoSuchKey</Code>
      <Message>The specified key does not exist.</Message>
    </Error>
    Ryan Tomczik
    @Tomczik76
      val durationArb: Arbitrary[Double] = Arbitrary(
        arbitrary[Double].map(Math.abs)
          .map(BigDecimal(_).setScale(5).toDouble)
      )
    am I doing this wrong?
    I want a positive double with a precision to be 5 decimal places
    Fredrik Wärnsberg
    @frekw

    Hi!

    I'm trying to write stateful tests for an API. When I create a resource, I get an ID back that I want to keep track of in my state (because it's needed for subsequent API calls). The API doesn't allow me to provide an ID I've generated myself to the create call, and I can't seem to find a way to get data from a Command.run-call into my state

    Is that possible to solve somehow?
    Ryan Peters
    @sloshy
    @frekw are you trying to get a new ID for every test run, or do you want to generate one ID upfront and reuse that for all of your test iterations?
    Fredrik Wärnsberg
    @frekw
    @sloshy I'm trying to generate a new one per test run
    Fredrik Wärnsberg
    @frekw
    Having dug through the issues on GitHub I stumbled across this; typelevel/scalacheck#199
    Would the current solution be to issue the create call in newSut and store it in the sut?
    Jonas Amundsen
    @badeball
    Can this be found elsewhere?
    Aaron S. Hawley
    @ashawley
    Yeah, it is in need of update. Fortunately, not much has changed since 1.14.0. https://www.scalacheck.org/files/scalacheck_2.11-1.14.0-api/index.html
    Jonas Amundsen
    @badeball
    Thanks a lot :)