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