package fr.pturpin.quickcheck.sample;

import fr.pturpin.quickcheck.annotation.Doubles;
import fr.pturpin.quickcheck.annotation.Nullable;
import fr.pturpin.quickcheck.junit4.QuickCheck;
import fr.pturpin.quickcheck.test.TestResult;
import fr.pturpin.quickcheck.test.configuration.TestConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Created by turpif on 28/04/17.
 */
@RunWith(QuickCheck.class)
public class QuickCheckSample_UT {

  @Test
  public void absoluteValueShouldBePositiveExceptNaN(double value) {
    if (!Double.isNaN(value)) {
      Assert.assertTrue(Math.abs(value) >= 0);
    }
  }

  @Test
  public TestResult ceilValueShouldBeGreaterOrEqThanValueExceptNaN(@Doubles.Exclude({Double.NaN}) @Doubles.Extra double value) {
    if (Double.isNaN(value)) {
      return TestResult.failure(new UnsupportedOperationException("NaN was not excluded"));
    }
    Assert.assertTrue(Math.ceil(value) >= value);
    return TestResult.ok();
  }

  @Test
  @TestConfiguration.Skipped(0.75)
  public TestResult toStringThenParseShouldBeIdentity(@Nullable Double value) {
    return TestResult.when(value != null, () -> {
      double parsed = Double.parseDouble(value.toString());
      Assert.assertEquals(value, parsed, 0.d);
    });
  }
}

@@ -81,16 +81,62 @@
 oubles;%0A
+import fr.pturpin.quickcheck.annotation.Ints;%0A
 import f
@@ -177,16 +177,16 @@
 llable;%0A
-
 import f
@@ -420,16 +420,75 @@
 nWith;%0A%0A
+import static fr.pturpin.quickcheck.test.TestResult.when;%0A%0A
 /**%0A * C
@@ -1234,27 +1234,16 @@
  return 
-TestResult.
 when(val
@@ -1369,16 +1369,16 @@
 , 0.d);%0A
-
     %7D);%0A
@@ -1380,11 +1380,474 @@
  %7D);%0A  %7D
+%0A%0A  @Test%0A  public void absoluteValueWithoutBranchingShouldBeEqualToMathAbs(int value) %7B%0A    Assert.assertEquals(Math.abs(value), myAbs(value));%0A  %7D%0A%0A  @Test%0A  public TestResult absoluteValueShouldBePositive(@Ints.Extra int value) %7B%0A    return when(value != Integer.MIN_VALUE, () -%3E %7B%0A      Assert.assertTrue(myAbs(value) %3E= 0);%0A    %7D);%0A  %7D%0A%0A  private static int myAbs(int value) %7B%0A    int mask = value %3E%3E (Integer.SIZE - 1);%0A    return (value + mask) %5E mask;%0A  %7D
 %0A%7D%0A

Add more test samples