home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (GuillaumesMapBug.groovy)

This example Groovy source code file (GuillaumesMapBug.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

groovytestcase, groovytestcase, guillaumesmapbug, guillaumesmapbug

The Groovy GuillaumesMapBug.groovy source code

package groovy.bugs

/**
 * @author Guillaume Laforge
 * @version $Revision: 4996 $
 */
class GuillaumesMapBug extends GroovyTestCase {
    
    void testBug2() {
        def list = [1, 2, 3]
        def map = [:]
        
        doLoop(list, map)
    
        assert map[0] == 1 
        assert map[1] == 2 
        assert map[2] == 3 
    }
    
    void doLoop(list, map) {
        def i = 0
        for (it in list) {
            map[i++] = it
        }
    }
    
    
    void testBug() {
        def list = [1, 2, 3]
        def map = [:]
        doClosureLoop(list, map)
        
        assert map[0] == 1 
        assert map[1] == 2 
        assert map[2] == 3 
    }
    
    void doClosureLoop(list, map) {
        def i = 0
        list.each { map[i++] = it }
    }    
}

Other Groovy examples (source code examples)

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

new blog posts

 

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