alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (Groovy4078Bug.groovy)

This example Groovy source code file (Groovy4078Bug.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

bigdecimal, bigdecimal, biginteger, biginteger, groovy4078bug, groovytestcase, intrange, intrange, objectrange, objectrange

The Groovy Groovy4078Bug.groovy source code

package groovy.bugs

class Groovy4078Bug extends GroovyTestCase {
    void testInfiniteLoopDetectionInStepUsage() {
        (2..2).step 0, {assert it != null} //IntRange
        
        ('b'..'b').step 0, {assert it != null} //ObjectRange
        
        5.step( 5, 1 ) { assert it != null } // DGM.step(), int
        
        5.0.step (5.0, 1 ) { assert it != null } // DGM.step(), BigDecimal
        
        def from = new BigInteger(5)
        def to = new BigInteger(5)
        from.step (to, 1 ) { assert it != null }  // DGM.step(), BigInteger

        try{
            (1..2).step 0, {assert it != null} //IntRange
            fail('Should have failed as step size 0 causes infinite loop')
        } catch(ex) {
            assert ex.message.contains('Infinite loop detected due to step size of 0')
        }
                      
        try{
            ('a'..'b').step 0, {assert it != null} // ObjectRange
            fail('Should have failed as step size 0 causes infinite loop')
        } catch(ex) {
            assert ex.message.contains('Infinite loop detected due to step size of 0')
        }
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy Groovy4078Bug.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.