// Path: src/main/java/javafixes/math/OverflowUtil.java
// class OverflowUtil {
// 
//     static boolean willNegationOverflow(long value) {
//         return value == Long.MIN_VALUE;
//     }
// 
//     static boolean didOverflowOnLongAddition(long result, long valueA, long valueB) {
//         // HD 2-12 Overflow iff both arguments have the opposite sign of the result
//         return ((valueA ^ result) & (valueB ^ result)) < 0;
//     }
// 
//     static boolean didOverflowOnMultiplication(long result, long valueA, long valueB) {
//         long absA = Math.abs(valueA);
//         long absB = Math.abs(valueB);
// 
//         if (((absA | absB) >>> 31 != 0)) {
//             // Some bits greater than 2^31 that might cause overflow
//             // Check the result using the divide operator
//             // and check for the special case of Long.MIN_VALUE * -1
//             if (((valueB != 0) && (result / valueB != valueA)) || (valueA == Long.MIN_VALUE && valueB == -1)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// }
// 
// Path: src/test/java/javafixes/test/Random.java
//     @SafeVarargs
//     public static long randomLong(long from, long to, Function<Long, Boolean>... validityConditions) {
//         return generateValidValue(
// //                () -> new RandomDataGenerator().nextLong(from, to),
//                 () -> ThreadLocalRandom.current().nextLong(from, to) + (long) randomInt(0, 1),
//                 validityConditions
//         );
//     }


import org.junit.Test;
import static javafixes.math.OverflowUtil.*;
import static javafixes.test.Random.randomLong;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
package javafixes.math;



public class OverflowUtilTest {

    @Test
    public void shouldFindIfNegationWillOverflow() {
        assertThat(willNegationOverflow(Long.MIN_VALUE), is(true));

        assertThat(willNegationOverflow(Long.MIN_VALUE + 1), is(false));
        assertThat(willNegationOverflow(Long.MAX_VALUE), is(false));
        assertThat(willNegationOverflow(1L), is(false));
        assertThat(willNegationOverflow(-1L), is(false));
        assertThat(willNegationOverflow(0L), is(false));

// Path: src/main/java/javafixes/math/OverflowUtil.java
// class OverflowUtil {
// 
//     static boolean willNegationOverflow(long value) {
//         return value == Long.MIN_VALUE;
//     }
// 
//     static boolean didOverflowOnLongAddition(long result, long valueA, long valueB) {
//         // HD 2-12 Overflow iff both arguments have the opposite sign of the result
//         return ((valueA ^ result) & (valueB ^ result)) < 0;
//     }
// 
//     static boolean didOverflowOnMultiplication(long result, long valueA, long valueB) {
//         long absA = Math.abs(valueA);
//         long absB = Math.abs(valueB);
// 
//         if (((absA | absB) >>> 31 != 0)) {
//             // Some bits greater than 2^31 that might cause overflow
//             // Check the result using the divide operator
//             // and check for the special case of Long.MIN_VALUE * -1
//             if (((valueB != 0) && (result / valueB != valueA)) || (valueA == Long.MIN_VALUE && valueB == -1)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// }
// 
// Path: src/test/java/javafixes/test/Random.java
//     @SafeVarargs
//     public static long randomLong(long from, long to, Function<Long, Boolean>... validityConditions) {
//         return generateValidValue(
// //                () -> new RandomDataGenerator().nextLong(from, to),
//                 () -> ThreadLocalRandom.current().nextLong(from, to) + (long) randomInt(0, 1),
//                 validityConditions
//         );
//     }


// Path: src/test/java/javafixes/math/OverflowUtilTest.java
import org.junit.Test;
import static javafixes.math.OverflowUtil.*;
import static javafixes.test.Random.randomLong;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

package javafixes.math;



public class OverflowUtilTest {

    @Test
    public void shouldFindIfNegationWillOverflow() {
        assertThat(willNegationOverflow(Long.MIN_VALUE), is(true));

        assertThat(willNegationOverflow(Long.MIN_VALUE + 1), is(false));
        assertThat(willNegationOverflow(Long.MAX_VALUE), is(false));
        assertThat(willNegationOverflow(1L), is(false));
        assertThat(willNegationOverflow(-1L), is(false));
        assertThat(willNegationOverflow(0L), is(false));

        assertThat(willNegationOverflow(randomLong(Long.MIN_VALUE + 1, Long.MAX_VALUE)), is(false));