Package org.python.core

Examples of org.python.core.PySet


public class PySetInJavaTest {

    @SuppressWarnings("unchecked")
    public static Set<Object> createPySetContainingJavaObjects() {
        PySet s = new PySet();
        s.add("value");
        s.add(new Random());
        return s;
    }
View Full Code Here


        s.add(new Random());
        return s;
    }

    public static void testPySetAsJavaSet() {
        PySet s = new PySet();
        String v = "value";
        check(s.add(v));// Add a String as it should be wrapped in PyString
        check(!s.add(v));
        String[] asArray = (String[])s.toArray(new String[0]);// The array type should be the same
        // and it should be resized properly
        check(asArray.length == 1);
        check(asArray[0] == v);
        Object[] naiveArray = s.toArray();
        check(naiveArray.length == 1);
        check(naiveArray[0] == v);
        // Add a Random as it should be wrapped in a generic PyObject; go through addAll to give it
        // a little exercise
        Random rand = new Random();
        check(s.addAll(Generic.list(rand)));
        check(!s.addAll(Generic.list(rand, v)));
        naiveArray = s.toArray();
        check(naiveArray.length == 2);
        for (Object object : naiveArray) {
            if (object instanceof String) {
                check(object == v);
            } else {
                check(object == rand, "Should be 'value' or rand, not " + object);
            }
        }
        check(!s.remove(new Random()), "The Random in the set shouldn't match a new Random");
        check(s.remove(rand));
        check(s.removeAll(Generic.list(rand, v)),
              "The set should contain v and indicate it removed it");
        check(s.isEmpty());
        check(s.addAll(Generic.list(rand, v)));
        check(2 == s.size(), "There should be 2 items, not " + s.size());
        check(s.containsAll(Generic.list(rand, v)));
        check(!s.containsAll(Generic.list(rand, v, "other")));
        check(s.retainAll(Generic.list(rand)));
        check(!s.retainAll(Generic.list(rand)));
        check(s.addAll(Generic.list(rand, v)));
        check(2 == s.size(), "There should be 2 items, not " + s.size());
        check(!s.addAll(Generic.list(rand, v)));
        check(2 == s.size(), "There should be 2 items, not " + s.size());
    }
View Full Code Here

                    for (int i = 0; i < n; i++) {
                        items[i] = read_object(depth + 1);
                    }
                    PyTuple v = new PyTuple(items);
                    if (type == TYPE_SET) {
                        return new PySet(v);
                    } else {
                        return new PyFrozenSet(v);
                    }
                }
View Full Code Here

TOP

Related Classes of org.python.core.PySet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.