rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java
changeset 1723 3a1f262311cf
parent 1701 0e061b0f80eb
child 1761 d2a5a7a0e167
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java	Wed Nov 19 19:32:00 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator
     1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. Look for COPYING file in the top folder.
    1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +package org.apidesign.bck2brwsr.compact.tck;
    1.22 +
    1.23 +import java.util.ArrayList;
    1.24 +import java.util.Arrays;
    1.25 +import java.util.Collection;
    1.26 +import java.util.Collections;
    1.27 +import java.util.Comparator;
    1.28 +import java.util.HashMap;
    1.29 +import java.util.HashSet;
    1.30 +import java.util.List;
    1.31 +import java.util.Map;
    1.32 +import java.util.Map.Entry;
    1.33 +import java.util.Vector;
    1.34 +import org.apidesign.bck2brwsr.vmtest.Compare;
    1.35 +import org.apidesign.bck2brwsr.vmtest.VMTest;
    1.36 +import org.testng.annotations.Factory;
    1.37 +
    1.38 +/**
    1.39 + *
    1.40 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.41 + */
    1.42 +public class CollectionsTest {
    1.43 +    @Compare public String sortStringsInArray() {
    1.44 +        List<String> list = new ArrayList<>();
    1.45 +        list.add("one");
    1.46 +        list.add("two");
    1.47 +        list.add("three");
    1.48 +        list.add("four");
    1.49 +        list.add("five");
    1.50 +        list.add("six");
    1.51 +        list.add("seven");
    1.52 +        list.add("eight");
    1.53 +        list.add("nine");
    1.54 +        list.add("ten");
    1.55 +        
    1.56 +        String[] arr = list.toArray(new String[list.size()]);
    1.57 +        Arrays.sort(arr);
    1.58 +        
    1.59 +        return Arrays.asList(arr).toString();
    1.60 +    }
    1.61 +    
    1.62 +    @Compare public String sortStringsInHashSet() {
    1.63 +        Collection<String> list = new HashSet<>();
    1.64 +        list.add("one");
    1.65 +        list.add("two");
    1.66 +        list.add("three");
    1.67 +        list.add("four");
    1.68 +        list.add("five");
    1.69 +        list.add("six");
    1.70 +        list.add("seven");
    1.71 +        list.add("eight");
    1.72 +        list.add("nine");
    1.73 +        list.add("ten");
    1.74 +        
    1.75 +        String[] arr = list.toArray(new String[0]);
    1.76 +        Arrays.sort(arr);
    1.77 +        
    1.78 +        return Arrays.asList(arr).toString();
    1.79 +    }
    1.80 +
    1.81 +    @SuppressWarnings("unchecked")
    1.82 +    @Compare public String sortStringsInHashMapWithComparator() {
    1.83 +        class C implements Comparator<Map.Entry<String,Integer>> {
    1.84 +            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
    1.85 +                return o1.getKey().compareTo(o2.getKey());
    1.86 +            }
    1.87 +        }
    1.88 +        
    1.89 +        Map<String,Integer> map = new HashMap<>();
    1.90 +        map.put("one", 1);
    1.91 +        map.put("two", 2);
    1.92 +        map.put("three", 3);
    1.93 +        map.put("four", 4);
    1.94 +        map.put("five", 5);
    1.95 +        map.put("six", 6);
    1.96 +        map.put("seven", 7);
    1.97 +        map.put("eight", 8);
    1.98 +        map.put("nine", 9);
    1.99 +        map.put("ten", 10);
   1.100 +        
   1.101 +        List<Entry<String,Integer>> arr = new Vector<>();
   1.102 +        arr.addAll(map.entrySet());
   1.103 +        Collections.sort(arr, new C());
   1.104 +        return arr.toString();
   1.105 +    }
   1.106 +    
   1.107 +    @Compare public String jirkaToArray() {
   1.108 +        List<String> appfiles = new ArrayList<>();
   1.109 +        appfiles.add("onefile");
   1.110 +        appfiles.add("2ndfile");
   1.111 +        appfiles.add("3rdfile");
   1.112 +        String[] ret = appfiles.toArray(new String[appfiles.size()]);
   1.113 +        return 
   1.114 +            ret.getClass().getName() + ":" +
   1.115 +            ret.length + ":" +
   1.116 +            Arrays.toString(ret);
   1.117 +    }
   1.118 +    
   1.119 +    @Factory
   1.120 +    public static Object[] create() {
   1.121 +        return VMTest.create(CollectionsTest.class);
   1.122 +    }
   1.123 +    
   1.124 +}