Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart6.png 80% of files have more coverage
86   213   27   14.33
22   131   0.31   6
6     4.5  
1    
 
  SixDynamicModel       Line # 25 86 27 51.8% 0.51754385
 
  (4)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.logic.model;
17   
18   
19    /**
20    * A model for our mathematical world. It has entities, functions and predicates.
21    * There are also predicate and function constants.
22    *
23    * @author Michael Meyling
24    */
 
25    public final class SixDynamicModel extends DynamicModel {
26   
27    /** "Zero" or empty set. */
28    public static final Entity EMPTY = new Entity(0, "{}", "{} or empty set");
29   
30    /** "One" or set that contains the empty set. */
31    public static final Entity ZERO_ONE = new Entity(1, "1", "1");
32   
33    /** "Two" or set that contains "zero" and "one". */
34    public static final Entity ZERO_TWO = new Entity(2, "2", "2");
35   
36    /** "One" or set that contains the empty set. */
37    public static final Entity ONE_ONE = new Entity(3, "{1}", "{1}");
38   
39    /** "Two" or set that contains "zero" and "one". */
40    public static final Entity ONE_TWO = new Entity(4, "{2}", "{2}");
41   
42    /** "Two" or set that contains "zero" and "one". */
43    public static final Entity TWO_ONE_TWO = new Entity(5, "{1, 2}", "{1, 2}");
44   
45    /** Map to empty class. */
46    public static final Function FUNCTION_EMPTY = Function.createConstant(EMPTY);
47   
48    /** Map to 1. */
49    public static final Function FUNCTION_ZERO_ONE = Function.createConstant(ZERO_ONE);
50   
51    /** Map to 2. */
52    public static final Function FUNCTION_ZERO_TWO = Function.createConstant(ZERO_TWO);
53   
54    /** Map to {1}. */
55    public static final Function FUNCTION_ONE_ONE = Function.createConstant(ONE_ONE);
56   
57    /** Map to {2}. */
58    public static final Function FUNCTION_ONE_TWO = Function.createConstant(ONE_TWO);
59   
60    /** Map to {1, 2}. */
61    public static final Function FUNCTION_TWO_ONE_TWO = Function.createConstant(TWO_ONE_TWO);
62   
63    /** Return true if all values are zero. */
64    public static final Predicate IS_EMPTY = Predicate.isEntity(EMPTY);
65   
66    /** Return true if all values are 1. */
67    public static final Predicate IS_ZERO_ONE = Predicate.isEntity(ZERO_ONE);
68   
69    /** Return true if all values are 2. */
70    public static final Predicate IS_ZERO_TWO = Predicate.isEntity(ZERO_TWO);
71   
72    /** Return true if all values are {1}. */
73    public static final Predicate IS_ONE_ONE = Predicate.isEntity(ONE_ONE);
74   
75    /** Return true if all values are {2}. */
76    public static final Predicate IS_ONE_TWO = Predicate.isEntity(ONE_TWO);
77   
78    /** Return true if all values are {2}. */
79    public static final Predicate IS_TWO_ONE_TWO = Predicate.isEntity(TWO_ONE_TWO);
80   
81    /** Are the entities are not all equal to {2}? */
82    public static final Predicate NOT_IS_ONE_TWO = Predicate.not(IS_ONE_TWO);
83   
84    /** Map to one. */
85    /** Modulo 3. */
86    private final Function functionModulo3 = new Function(0, 99, "% 3", "modulo 3") {
 
87  40 toggle public Entity map(final Entity[] entities) {
88  40 int result = 0;
89  80 for (int i = 0; i < entities.length; i++) {
90  40 result += entities[i].getValue() % 3;
91    }
92  40 result = result % 3;
93  40 return getEntity(result);
94    }
95    };
96   
97    /** +1 Modulo 3. */
98    private final Function functionPlus1Modulo3 = new Function(0, 99, "+1 % 3", "plus 1 modulo 3") {
 
99  36 toggle public Entity map(final Entity[] entities) {
100  36 int result = 1;
101  72 for (int i = 0; i < entities.length; i++) {
102  36 result += entities[i].getValue() % 3;
103    }
104  36 result = result % 3;
105  36 return getEntity(result);
106    }
107    };
108   
109   
110    /**
111    * Constructor.
112    */
 
113  46 toggle public SixDynamicModel() {
114  46 super("six elements");
115   
116  46 addEntity(EMPTY);
117  46 addEntity(ZERO_ONE);
118  46 addEntity(ZERO_TWO);
119  46 addEntity(ONE_ONE);
120  46 addEntity(ONE_TWO);
121  46 addEntity(TWO_ONE_TWO);
122   
123  46 addFunction(0, FUNCTION_EMPTY);
124  46 addFunction(0, FUNCTION_ZERO_ONE);
125  46 addFunction(0, FUNCTION_ZERO_TWO);
126  46 addFunction(0, FUNCTION_ONE_ONE);
127  46 addFunction(0, FUNCTION_ONE_TWO);
128  46 addFunction(0, FUNCTION_TWO_ONE_TWO);
129   
130  46 addFunction(1, FUNCTION_EMPTY);
131  46 addFunction(1, FUNCTION_ZERO_ONE);
132  46 addFunction(1, functionModulo3);
133  46 addFunction(1, functionPlus1Modulo3);
134   
135  46 addFunction(2, FUNCTION_EMPTY);
136  46 addFunction(2, FUNCTION_ZERO_ONE);
137  46 addFunction(2, functionModulo3);
138  46 addFunction(2, functionPlus1Modulo3);
139   
140  46 addPredicate(0, FALSE);
141  46 addPredicate(0, TRUE);
142   
143  46 addPredicate(1, FALSE);
144  46 addPredicate(1, TRUE);
145  46 addPredicate(1, EVEN);
146  46 addPredicate(1, IS_EMPTY);
147  46 addPredicate(1, IS_ZERO_ONE);
148  46 addPredicate(1, IS_ZERO_TWO);
149  46 addPredicate(1, IS_ONE_ONE);
150  46 addPredicate(1, IS_TWO_ONE_TWO);
151   
152  46 addPredicate(2, FALSE);
153  46 addPredicate(2, TRUE);
154  46 addPredicate(2, EVEN);
155  46 addPredicate(2, LESS);
156  46 addPredicate(2, EQUAL);
157  46 addPredicate(2, IS_EMPTY);
158  46 addPredicate(2, IS_ZERO_ONE);
159  46 addPredicate(2, IS_ZERO_TWO);
160  46 addPredicate(2, IS_ONE_ONE);
161  46 addPredicate(2, IS_ONE_TWO);
162   
163  46 addPredicateConstant(new ModelPredicateConstant("in", 2), new Predicate(2, 2, "in", "isSet") {
 
164  0 toggle public boolean calculate(final Entity[] entities) {
165  0 boolean result = false;
166  0 final int a = entities[0].getValue();
167  0 final int b = entities[1].getValue();
168  0 if (a == 1 && (b == 3 || b == 5)) {
169  0 result = true;
170    }
171  0 if (a == 2 && (b == 4 || b == 5)) {
172  0 result = true;
173    }
174  0 return result;
175    }
176    });
177    }
178   
 
179  0 toggle public String getDescription() {
180  0 return "This model has six entities: {}, {1}, {2}, {{1}}, {{2}} and {1, 2}.";
181    }
182   
 
183  0 toggle public Entity comprehension(final Entity[] array) {
184  0 Entity result = EMPTY;
185  0 for (int i = 0; i < array.length; i++) {
186  0 switch (array[i].getValue()) {
187  0 case 0:
188  0 case 3:
189  0 case 4:
190  0 case 5: break;
191  0 case 1: if (result.getValue() != 5) {
192  0 if (result.getValue() == 0) {
193  0 result = ONE_ONE;
194  0 } else if (result.getValue() == 4) {
195  0 result = TWO_ONE_TWO;
196    }
197    }
198  0 break;
199  0 case 2: if (result.getValue() != 5) {
200  0 if (result.getValue() == 0) {
201  0 result = ONE_TWO;
202  0 } else if (result.getValue() == 4) {
203  0 result = TWO_ONE_TWO;
204    }
205    }
206  0 break;
207  0 default: throw new RuntimeException("unknown value for entity " + array[i]);
208    }
209    }
210  0 return result;
211    }
212   
213    }