X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Funit%2FTestNamespaceFilter.java;h=e1b5dcc5fd4eeaeec9f305a9b85111e0d499d64a;hb=HEAD;hp=3f9c9e4e90e9ff96e2bcd1f468f63e08fadcd42e;hpb=4bf8562ab7cbb3747f9c5844a07469291d43e905;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/unit/TestNamespaceFilter.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/unit/TestNamespaceFilter.java index 3f9c9e4e9..e1b5dcc5f 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/unit/TestNamespaceFilter.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/unit/TestNamespaceFilter.java @@ -1,89 +1,89 @@ -package org.simantics.scl.compiler.tests.unit; - -import java.util.Collection; - -import org.junit.Assert; -import org.junit.Test; -import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter; -import org.simantics.scl.compiler.environment.filter.NamespaceFilter; -import org.simantics.scl.compiler.environment.filter.NamespaceFilters; -import org.simantics.scl.compiler.environment.filter.NegativeNamespaceFilter; -import org.simantics.scl.compiler.environment.filter.PositiveNamespaceFilter; - -import gnu.trove.set.hash.THashSet; - -public class TestNamespaceFilter { - - private void testBooleanOperations(Collection all, NamespaceFilter a, NamespaceFilter b) { - { - NamespaceFilter c = NamespaceFilters.union(a, b); - //System.out.println("union(" + a + ", " + b + ") = " + c); - for(String name : all) - Assert.assertEquals( - a.isValueIncluded(name) || b.isValueIncluded(name), - c.isValueIncluded(name)); - } - { - NamespaceFilter c = NamespaceFilters.intersection(a, b); - //System.out.println("intersection(" + a + ", " + b + ") = " + c); - for(String name : all) - Assert.assertEquals( - a.isValueIncluded(name) && b.isValueIncluded(name), - c.isValueIncluded(name)); - } - } - - private void testBooleanOperations(THashSet a, THashSet b) { - THashSet all = new THashSet(); - all.addAll(a); - all.addAll(b); - all.add("dummy"); - - PositiveNamespaceFilter pa = new PositiveNamespaceFilter(a); - NegativeNamespaceFilter na = new NegativeNamespaceFilter(a); - PositiveNamespaceFilter pb = new PositiveNamespaceFilter(b); - NegativeNamespaceFilter nb = new NegativeNamespaceFilter(b); - testBooleanOperations(all, pa, pb); - testBooleanOperations(all, na, pb); - testBooleanOperations(all, pa, nb); - testBooleanOperations(all, na, nb); - } - - private void testBooleanOperations(THashSet a) { - THashSet all = new THashSet(); - all.addAll(a); - all.add("dummy"); - - PositiveNamespaceFilter pa = new PositiveNamespaceFilter(a); - NegativeNamespaceFilter na = new NegativeNamespaceFilter(a); - testBooleanOperations(all, pa, AcceptAllNamespaceFilter.INSTANCE); - testBooleanOperations(all, na, AcceptAllNamespaceFilter.INSTANCE); - testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, pa); - testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, na); - testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, AcceptAllNamespaceFilter.INSTANCE); - } - - @Test - public void testBooleanOperations() { - for(int p=0;p<8;++p) { - THashSet a = new THashSet(); - for(int i=0;i<3;++i) - if(((p >> i) & 1) == 1) - a.add(String.valueOf(i)); - testBooleanOperations(a); - } - - for(int p=0;p<64;++p) { - THashSet a = new THashSet(); - THashSet b = new THashSet(); - for(int i=0;i<3;++i) { - if(((p >> i) & 1) == 1) - a.add(String.valueOf(i)); - if(((p >> (i+3)) & 1) == 1) - b.add(String.valueOf(i)); - } - testBooleanOperations(a, b); - } - } - -} +package org.simantics.scl.compiler.tests.unit; + +import java.util.Collection; + +import org.junit.Assert; +import org.junit.Test; +import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter; +import org.simantics.scl.compiler.environment.filter.NamespaceFilter; +import org.simantics.scl.compiler.environment.filter.NamespaceFilters; +import org.simantics.scl.compiler.environment.filter.NegativeNamespaceFilter; +import org.simantics.scl.compiler.environment.filter.PositiveNamespaceFilter; + +import gnu.trove.set.hash.THashSet; + +public class TestNamespaceFilter { + + private void testBooleanOperations(Collection all, NamespaceFilter a, NamespaceFilter b) { + { + NamespaceFilter c = NamespaceFilters.union(a, b); + //System.out.println("union(" + a + ", " + b + ") = " + c); + for(String name : all) + Assert.assertEquals( + a.isValueIncluded(name) || b.isValueIncluded(name), + c.isValueIncluded(name)); + } + { + NamespaceFilter c = NamespaceFilters.intersection(a, b); + //System.out.println("intersection(" + a + ", " + b + ") = " + c); + for(String name : all) + Assert.assertEquals( + a.isValueIncluded(name) && b.isValueIncluded(name), + c.isValueIncluded(name)); + } + } + + private void testBooleanOperations(THashSet a, THashSet b) { + THashSet all = new THashSet(); + all.addAll(a); + all.addAll(b); + all.add("dummy"); + + PositiveNamespaceFilter pa = new PositiveNamespaceFilter(a); + NegativeNamespaceFilter na = new NegativeNamespaceFilter(a); + PositiveNamespaceFilter pb = new PositiveNamespaceFilter(b); + NegativeNamespaceFilter nb = new NegativeNamespaceFilter(b); + testBooleanOperations(all, pa, pb); + testBooleanOperations(all, na, pb); + testBooleanOperations(all, pa, nb); + testBooleanOperations(all, na, nb); + } + + private void testBooleanOperations(THashSet a) { + THashSet all = new THashSet(); + all.addAll(a); + all.add("dummy"); + + PositiveNamespaceFilter pa = new PositiveNamespaceFilter(a); + NegativeNamespaceFilter na = new NegativeNamespaceFilter(a); + testBooleanOperations(all, pa, AcceptAllNamespaceFilter.INSTANCE); + testBooleanOperations(all, na, AcceptAllNamespaceFilter.INSTANCE); + testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, pa); + testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, na); + testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, AcceptAllNamespaceFilter.INSTANCE); + } + + @Test + public void testBooleanOperations() { + for(int p=0;p<8;++p) { + THashSet a = new THashSet(); + for(int i=0;i<3;++i) + if(((p >> i) & 1) == 1) + a.add(String.valueOf(i)); + testBooleanOperations(a); + } + + for(int p=0;p<64;++p) { + THashSet a = new THashSet(); + THashSet b = new THashSet(); + for(int i=0;i<3;++i) { + if(((p >> i) & 1) == 1) + a.add(String.valueOf(i)); + if(((p >> (i+3)) & 1) == 1) + b.add(String.valueOf(i)); + } + testBooleanOperations(a, b); + } + } + +}