1 package org.simantics.scl.compiler.tests.unit;
\r
3 import gnu.trove.set.hash.THashSet;
\r
5 import java.util.Collection;
\r
7 import junit.framework.Assert;
\r
9 import org.junit.Test;
\r
10 import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
\r
11 import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
\r
12 import org.simantics.scl.compiler.environment.filter.NamespaceFilters;
\r
13 import org.simantics.scl.compiler.environment.filter.NegativeNamespaceFilter;
\r
14 import org.simantics.scl.compiler.environment.filter.PositiveNamespaceFilter;
\r
16 public class TestNamespaceFilter {
\r
18 private void testBooleanOperations(Collection<String> all, NamespaceFilter a, NamespaceFilter b) {
\r
20 NamespaceFilter c = NamespaceFilters.union(a, b);
\r
21 //System.out.println("union(" + a + ", " + b + ") = " + c);
\r
22 for(String name : all)
\r
23 Assert.assertEquals(
\r
24 a.isValueIncluded(name) || b.isValueIncluded(name),
\r
25 c.isValueIncluded(name));
\r
28 NamespaceFilter c = NamespaceFilters.intersection(a, b);
\r
29 //System.out.println("intersection(" + a + ", " + b + ") = " + c);
\r
30 for(String name : all)
\r
31 Assert.assertEquals(
\r
32 a.isValueIncluded(name) && b.isValueIncluded(name),
\r
33 c.isValueIncluded(name));
\r
37 private void testBooleanOperations(THashSet<String> a, THashSet<String> b) {
\r
38 THashSet<String> all = new THashSet<String>();
\r
43 PositiveNamespaceFilter pa = new PositiveNamespaceFilter(a);
\r
44 NegativeNamespaceFilter na = new NegativeNamespaceFilter(a);
\r
45 PositiveNamespaceFilter pb = new PositiveNamespaceFilter(b);
\r
46 NegativeNamespaceFilter nb = new NegativeNamespaceFilter(b);
\r
47 testBooleanOperations(all, pa, pb);
\r
48 testBooleanOperations(all, na, pb);
\r
49 testBooleanOperations(all, pa, nb);
\r
50 testBooleanOperations(all, na, nb);
\r
53 private void testBooleanOperations(THashSet<String> a) {
\r
54 THashSet<String> all = new THashSet<String>();
\r
58 PositiveNamespaceFilter pa = new PositiveNamespaceFilter(a);
\r
59 NegativeNamespaceFilter na = new NegativeNamespaceFilter(a);
\r
60 testBooleanOperations(all, pa, AcceptAllNamespaceFilter.INSTANCE);
\r
61 testBooleanOperations(all, na, AcceptAllNamespaceFilter.INSTANCE);
\r
62 testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, pa);
\r
63 testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, na);
\r
64 testBooleanOperations(all, AcceptAllNamespaceFilter.INSTANCE, AcceptAllNamespaceFilter.INSTANCE);
\r
68 public void testBooleanOperations() {
\r
69 for(int p=0;p<8;++p) {
\r
70 THashSet<String> a = new THashSet<String>();
\r
71 for(int i=0;i<3;++i)
\r
72 if(((p >> i) & 1) == 1)
\r
73 a.add(String.valueOf(i));
\r
74 testBooleanOperations(a);
\r
77 for(int p=0;p<64;++p) {
\r
78 THashSet<String> a = new THashSet<String>();
\r
79 THashSet<String> b = new THashSet<String>();
\r
80 for(int i=0;i<3;++i) {
\r
81 if(((p >> i) & 1) == 1)
\r
82 a.add(String.valueOf(i));
\r
83 if(((p >> (i+3)) & 1) == 1)
\r
84 b.add(String.valueOf(i));
\r
86 testBooleanOperations(a, b);
\r