Can Autofixture.Create <int> return a negative value?

In fact, the following method always returns a positive integer:

var fixture = new Fixture();
var someInt = fixture.Create<int>();

Is it possible that one day the function evolves and starts to return a negative integer? Or is there an official reason why he really always returns a positive integer
If not, is there some kind of documentation hidden somewhere telling about it?

To continue using the auto object, I would like to know if there are any changes.

+4
source share
3 answers

Autofixture blog. , , " " , , .

AutoFixture - . , . 100% , , . , SpecimenBuilder:

fixture.Customizations.Add(new PositiveIntegerBuilder());

.

+6

prgmtc , - ISpecimenBuilder.

- , RandomNumericSequenceGenerator, :

[Fact]
public void FixtureCreatesNegativeNumbers()
{
    var fixture = new Fixture();
    fixture.Customizations.Add(
        new RandomNumericSequenceGenerator(-900, -100));

    var i = fixture.Create<int>();
    // Prints -> -711
    var l = fixture.Create<long>();
    // Prints -> 618
    var f = fixture.Create<float>();
    // Prints -> -78.0
}
+7

If the data type is capable of supporting negative numbers, yes. Who knows what madness developers can impose on us, but they are unlikely to want to do this.

So maybe? Yes. Probably? No.

-2
source

All Articles