Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart9.png 45% of files have more coverage
94   200   25   15.67
22   132   0.27   6
6     4.17  
1    
 
  FourDynamicModel       Line # 25 94 25 85.2% 0.852459
 
  (52)
 
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 FourDynamicModel extends DynamicModel {
26   
27    /** "Zero" or empty set. */
28    public static final Entity ZERO = new Entity(0, "{}", "{} or empty set");
29   
30    /** "One" or set that contains the empty set. */
31    public static final Entity ONE = new Entity(1, "{{}}", "{{}} or 1");
32   
33    /** "Two" or set that contains "zero" and "one". */
34    public static final Entity TWO = new Entity(2, "{{}, {{}}}", "{{}, {{}}} or 2");
35   
36    /** "Three" or set that contains "one". */
37    public static final Entity THREE = new Entity(3, "{{{}}}", "{{{}}} or 3");
38   
39    /** Map to empty class. */
40    public static final Function FUNCTION_ZERO = Function.createConstant(ZERO);
41   
42    /** Map to 1. */
43    public static final Function FUNCTION_ONE = Function.createConstant(ONE);
44   
45    /** Map to 2. */
46    public static final Function FUNCTION_TWO = Function.createConstant(TWO);
47   
48    /** Map to 2. */
49    public static final Function FUNCTION_THREE = Function.createConstant(THREE);
50   
51    /** Return true if all values are zero. */
52    public static final Predicate IS_ZERO = Predicate.isEntity(ZERO);
53   
54    /** Return true if all values are 1. */
55    public static final Predicate IS_ONE = Predicate.isEntity(ONE);
56   
57    /** Return true if all values are 2. */
58    public static final Predicate IS_TWO = Predicate.isEntity(TWO);
59   
60    /** Return true if all values are 2. */
61    public static final Predicate IS_THREE = Predicate.isEntity(THREE);
62   
63    /** Map to one. */
64    /** Modulo 3. */
65    private final Function functionModulo3 = new Function(0, 99, "% 3", "modulo 3") {
 
66  26 toggle public Entity map(final Entity[] entities) {
67  26 int result = 0;
68  52 for (int i = 0; i < entities.length; i++) {
69  26 result += entities[i].getValue() % 3;
70    }
71  26 result = result % 3;
72  26 return getEntity(result);
73    }
74    };
75   
76    /** +1 Modulo 3. */
77    private final Function functionPlus1Modulo3 = new Function(0, 99, "+1 % 3", "plus 1 modulo 3") {
 
78  22 toggle public Entity map(final Entity[] entities) {
79  22 int result = 1;
80  44 for (int i = 0; i < entities.length; i++) {
81  22 result += entities[i].getValue() % 3;
82    }
83  22 result = result % 3;
84  22 return getEntity(result);
85    }
86    };
87   
88   
89    /**
90    * Constructor.
91    */
 
92  52 toggle public FourDynamicModel() {
93  52 super("four elements");
94   
95  52 addEntity(ZERO);
96  52 addEntity(ONE);
97  52 addEntity(TWO);
98  52 addEntity(THREE);
99   
100  52 addFunction(0, FUNCTION_ZERO);
101  52 addFunction(0, FUNCTION_ONE);
102  52 addFunction(0, FUNCTION_TWO);
103  52 addFunction(0, FUNCTION_THREE);
104   
105  52 addFunction(1, FUNCTION_ZERO);
106  52 addFunction(1, FUNCTION_ONE);
107  52 addFunction(0, FUNCTION_TWO);
108  52 addFunction(0, FUNCTION_THREE);
109  52 addFunction(1, functionModulo3);
110  52 addFunction(1, functionPlus1Modulo3);
111   
112  52 addFunction(2, FUNCTION_ZERO);
113  52 addFunction(2, FUNCTION_ONE);
114  52 addFunction(0, FUNCTION_TWO);
115  52 addFunction(0, FUNCTION_THREE);
116  52 addFunction(2, functionModulo3);
117  52 addFunction(2, functionPlus1Modulo3);
118   
119  52 addPredicate(0, FALSE);
120  52 addPredicate(0, TRUE);
121   
122  52 addPredicate(1, FALSE);
123  52 addPredicate(1, TRUE);
124  52 addPredicate(1, EVEN);
125  52 addPredicate(1, IS_ZERO);
126  52 addPredicate(1, IS_ONE);
127  52 addPredicate(1, IS_TWO);
128  52 addPredicate(1, IS_THREE);
129   
130  52 addPredicate(2, FALSE);
131  52 addPredicate(2, TRUE);
132  52 addPredicate(2, EVEN);
133  52 addPredicate(2, LESS);
134  52 addPredicate(2, EQUAL);
135  52 addPredicate(2, IS_ZERO);
136  52 addPredicate(2, IS_ONE);
137  52 addPredicate(2, IS_TWO);
138  52 addPredicate(2, IS_THREE);
139   
140  52 addPredicateConstant(new ModelPredicateConstant("in", 2), new Predicate(2, 2, "in", "Element of") {
 
141  47293 toggle public boolean calculate(final Entity[] entities) {
142  47293 if (entities.length != 2) {
143  0 return false;
144    }
145  47293 final int element = entities[0].getValue();
146  47293 switch (entities[1].getValue()) {
147  13980 case 0: return false;
148  14664 case 1: if (element == 0) {
149  5451 return true;
150    }
151  9213 return false;
152  11239 case 2: if (element < 2) {
153  6567 return true;
154    }
155  4672 return false;
156  7410 case 3: if (element == 1) {
157  1637 return true;
158    }
159  5773 return false;
160  0 default: return false;
161    }
162    }
163    });
164    }
165   
 
166  0 toggle public String getDescription() {
167  0 return "This model has four entities: {}, {{}}, {{}, {{}}}, {{{}}}.";
168    }
169   
 
170  6536 toggle public Entity comprehension(final Entity[] array) {
171  6536 Entity result = ZERO;
172  11416 for (int i = 0; i < array.length; i++) {
173  4880 final int element = array[i].getValue();
174  4880 switch (result.getValue()) {
175  3642 case 0:
176  3642 if (element == 0) {
177  2868 result = ONE;
178  774 } else if (element == 1) {
179  774 result = THREE;
180    }
181  3642 break;
182  1238 case 1:
183  1238 if (element == 1) {
184  1238 result = TWO;
185    }
186  1238 break;
187  0 case 2:
188  0 break;
189  0 case 3:
190  0 if (element == 0) {
191  0 result = TWO;
192    }
193  0 break;
194  0 default: throw new RuntimeException("unknown value for entity " + array[i]);
195    }
196    }
197  6536 return result;
198    }
199   
200    }