rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.compact.tck;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
29 import java.util.Map.Entry;
30 import java.util.Vector;
31 import org.apidesign.bck2brwsr.vmtest.Compare;
32 import org.apidesign.bck2brwsr.vmtest.VMTest;
33 import org.testng.annotations.Factory;
37 * @author Jaroslav Tulach <jtulach@netbeans.org>
39 public class CollectionsTest {
40 @Compare public String sortStringsInArray() {
41 List<String> list = new ArrayList<>();
53 String[] arr = list.toArray(new String[list.size()]);
56 return Arrays.asList(arr).toString();
59 @Compare public String sortStringsInHashSet() {
60 Collection<String> list = new HashSet<>();
72 String[] arr = list.toArray(new String[0]);
75 return Arrays.asList(arr).toString();
78 @SuppressWarnings("unchecked")
79 @Compare public String sortStringsInHashMapWithComparator() {
80 class C implements Comparator<Map.Entry<String,Integer>> {
81 public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
82 return o1.getKey().compareTo(o2.getKey());
86 Map<String,Integer> map = new HashMap<>();
98 List<Entry<String,Integer>> arr = new Vector<>();
99 arr.addAll(map.entrySet());
100 Collections.sort(arr, new C());
101 return arr.toString();
104 @Compare public String jirkaToArray() {
105 List<String> appfiles = new ArrayList<>();
106 appfiles.add("onefile");
107 appfiles.add("2ndfile");
108 appfiles.add("3rdfile");
109 String[] ret = appfiles.toArray(new String[appfiles.size()]);
111 ret.getClass().getName() + ":" +
113 Arrays.toString(ret);
116 @Compare public int collectionsShuffle() {
117 ArrayList<Integer> positions = new ArrayList<>();
118 for (int i = 0; i < 16; i++) {
121 Collections.shuffle(positions);
124 for (Integer p : positions) {
131 public static Object[] create() {
132 return VMTest.create(CollectionsTest.class);