question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DivideByZeroException in Gen.Choose

See original GitHub issue

Hello. I’m started trying to use FsCheck in C# Project. And I use simple example in test to generate any number from all range of int values:

    [Test]
    public void Test_MinMax()
    {
        var generator = Gen.Choose(int.MinValue, int.MaxValue);
        foreach (var val in generator.Sample(10, 10))
            Console.WriteLine(val);
    }

And I got exception in test output in FsCheck:

System.DivideByZeroException : Attempted to divide by zero.
   at FsCheck.Random.stdRange(Int32 l, Int32 h, StdGen rng)
   at FsCheck.Random.range@74-1.Invoke(StdGen rng)
   at FsCheck.Gen.Choose@178.Invoke(Int32 _arg1, StdGen r)
   at FsCheck.Gen.sample@170[a](Int32 size, Gen`1 generator, Int32 i, StdGen seed, FSharpList`1 samples)
   at FsCheck.Gen.Sample[a](Int32 size, Int32 n, Gen`1 generator)
   at FsCheck.GenExtensions.Sample[a](Gen`1 generator, Int32 size, Int32 numberOfSamples)

Is this a bug? Or, i’m doing something wrong?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kharacternykcommented, Apr 14, 2019

DoNotSize<T> types are just a way to tell FsCheck that you want T in the whole range. They are wrappers around T without any additional behaviour.

I see you are an Russian speaker, so you may contact me on The Telegram if you have additional questions (I think issues on GitHub should be readable for everyone and using English here is the right way).

http://t.me/Kharacternyk

Удачи!

1reaction
Kharacternykcommented, Apr 14, 2019

It seems right, except that F# version firstly create an arbitrary for int and then uses Arb.convert to create an arbitrary for DoNotSize<int>. I think shrinking wouldn’t work in your version because Arb.Shrink tries to find an Arbitrary<DoNotSize<int>> that doesn’t exist yet. The F# version is closer to

//your code
return Arb.From(gen, i => (Arb.Shrink i.Item).Select(DoNotSize<int>.NewDoNotSize));
Read more comments on GitHub >

github_iconTop Results From Across the Web

DivideByZeroException Class (System)
The exception that is thrown when there is an attempt to divide an integral or Decimal value by zero.
Read more >
C# DivideByZeroException won't execute [duplicate]
You are going to get divide by zero error only in case of integer input in c#. For double the desired output is...
Read more >
.NET Exceptions - System.DivideByZeroException
DivideByZeroException is thrown when attempting to divide an integer or a decimal by zero. Normally divide by zero errors are pretty boring, but ......
Read more >
C# - DivideByZeroException Exception Example
DivideByZeroException Exception. Here, we are demonstrating the divide by zero exception. We will divide a number by 0 then the program will ...
Read more >
c# - Dividing two numbers then handle the divide by zero ...
but I want to check the possible errors so I used from try/catch for DivideByZeroException and all of the other errors by Exception...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found