/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.openjena.atlas.lib; import static org.openjena.atlas.lib.ListUtils.asList ; import java.util.HashSet ; import java.util.List ; import java.util.Set ; import org.junit.Test ; import org.openjena.atlas.junit.BaseTest ; public class TestSetUtils extends BaseTest { @Test public void set01() { Set x = set(1,2,3) ; test(x,1,2,3) ; } @Test public void set02() { Set x1 = set(1,2,3) ; Set x2 = set(1,2,3) ; Set x3 = SetUtils.intersection(x1, x2) ; test(x3, 1,2,3) ; x3 = SetUtils.intersection(x2, x1) ; test(x3, 1,2,3) ; } @Test public void set03() { Set x1 = set(1,2,3) ; Set x2 = set(2,9) ; Set x3 = SetUtils.intersection(x1, x2) ; test(x3, 2) ; x3 = SetUtils.intersection(x2, x1) ; test(x3, 2) ; } @Test public void set04() { Set x1 = set(1,2,3) ; Set x2 = set(6,7,8) ; Set x3 = SetUtils.intersection(x1, x2) ; test(x3) ; x3 = SetUtils.intersection(x2, x1) ; test(x3) ; } @Test public void set05() { Set x1 = set(1,2,3) ; Set x2 = set(1,2,3) ; Set x3 = SetUtils.union(x1, x2) ; test(x3, 1,2,3) ; x3 = SetUtils.union(x2, x1) ; test(x3, 1,2,3) ; } @Test public void set06() { Set x1 = set(1,2,3) ; Set x2 = set(2,9) ; Set x3 = SetUtils.union(x1, x2) ; test(x3, 1,2,3,9) ; x3 = SetUtils.union(x2, x1) ; test(x3, 1,2,3,9) ; } @Test public void set07() { Set x1 = set(1,2,3) ; Set x2 = set() ; Set x3 = SetUtils.union(x1, x2) ; test(x3,1,2,3) ; x3 = SetUtils.union(x2, x1) ; test(x3,1,2,3) ; } @Test public void set08() { Set x1 = set(1,2,3) ; Set x2 = set() ; Set x3 = SetUtils.difference(x1, x2) ; test(x3,1,2,3) ; x3 = SetUtils.difference(x2, x1) ; test(x3) ; } @Test public void set09() { Set x1 = set(1,2,3) ; Set x2 = set(3) ; Set x3 = SetUtils.difference(x1, x2) ; test(x3,1,2) ; x3 = SetUtils.difference(x2, x1) ; test(x3) ; } @Test public void set10() { Set x1 = set(1,2,3) ; Set x2 = set(4,5,6) ; Set x3 = SetUtils.difference(x1, x2) ; test(x3,1,2,3) ; x3 = SetUtils.difference(x2, x1) ; test(x3,4,5,6) ; } // -------- private static Set set(int... values) { return new HashSet(asList(values)) ; } private void test(Set x, int...values) { List y = asList(values) ; assertEquals(y.size(), x.size()) ; for ( int i = 0; i < y.size() ; i++ ) assertTrue(x.contains(y.get(i))) ; } }