Exemple #1
0
 public void NTest_Thermometer_constructor()
 {
     // QuickCheck will generate random values for t, within the range
     // specified by the When-clause. For every t, the body of the lamda
     // expression specifies your test. The test passes if the body returns
     // true. QuickCheck checks whether this is the case for every t it
     // generates.
     // Do note that a plain random algorithm will have to be very lucky if your
     // When-clause is complicated enough.
     Prop.ForAll <float>(
         // note that this is just a lambda-expression
         t =>
     {
         // create a new thermometer(t)
         Thermometer trm = new Thermometer(t);
         // check that the thermometer is configure with temperature |t|
         return((Math.Abs(t) == trm.get())
                .
                // Use a When-clause to specify a sensical range (pre-condition) of valid t values
                When(-1000 <= t && t <= 1000)
                .
                // Use classify-clauses to get statistics of the distribution of your tests
                Classify(t > 0, "positive").
                Classify(t == 0.0f, "zero").
                Classify(t < 0, "negative"));
     }
         )
     .QuickCheckThrowOnFailure();
 }
Exemple #2
0
 public void NTest_Thermometer_demonstrating_customGenerator()
 {
     // Register the class that contains your custom value-generators
     Arb.Register <MyCustomGenerators>();
     Prop.ForAll <float>(
         t =>
     {
         Thermometer trm = new Thermometer(t);
         Console.WriteLine("** t = " + t);
         return(Math.Abs(t) == trm.get());
     }
         )
     .QuickCheckThrowOnFailure();
 }