Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../../img/srcFileCovDistChart9.png 45% of files have more coverage
58   150   12   11.6
8   88   0.21   5
5     2.4  
1    
 
  ThreeDynamicModel       Line # 25 58 12 90.1% 0.90140843
 
  (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 ThreeDynamicModel 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    /** Map to empty class. */
37    public static final Function FUNCTION_ZERO = Function.createConstant(ZERO);
38   
39    /** Map to 1. */
40    public static final Function FUNCTION_ONE = Function.createConstant(ONE);
41   
42    /** Map to 2. */
43    public static final Function FUNCTION_TWO = Function.createConstant(TWO);
44   
45    /** Return true if all values are zero. */
46    public static final Predicate IS_ZERO = Predicate.isEntity(ZERO);
47   
48    /** Return true if all values are 1. */
49    public static final Predicate IS_ONE = Predicate.isEntity(ONE);
50   
51    /** Return true if all values are 2. */
52    public static final Predicate IS_TWO = Predicate.isEntity(TWO);
53   
54    /** Map to one. */
55    /** Modulo 3. */
56    private final Function functionModulo3 = new Function(0, 99, "% 3", "modulo 3") {
 
57  22 toggle public Entity map(final Entity[] entities) {
58  22 int result = 0;
59  44 for (int i = 0; i < entities.length; i++) {
60  22 result += entities[i].getValue() % 3;
61    }
62  22 result = result % 3;
63  22 return getEntity(result);
64    }
65    };
66   
67    /** +1 Modulo 3. */
68    private final Function functionPlus1Modulo3 = new Function(0, 99, "+1 % 3", "plus 1 modulo 3") {
 
69  18 toggle public Entity map(final Entity[] entities) {
70  18 int result = 1;
71  36 for (int i = 0; i < entities.length; i++) {
72  18 result += entities[i].getValue() % 3;
73    }
74  18 result = result % 3;
75  18 return getEntity(result);
76    }
77    };
78   
79   
80    /**
81    * Constructor.
82    */
 
83  48 toggle public ThreeDynamicModel() {
84  48 super("three elements");
85   
86  48 addEntity(ZERO);
87  48 addEntity(ONE);
88  48 addEntity(TWO);
89   
90  48 addFunction(0, FUNCTION_ZERO);
91  48 addFunction(0, FUNCTION_ONE);
92  48 addFunction(0, FUNCTION_TWO);
93   
94  48 addFunction(1, FUNCTION_ZERO);
95  48 addFunction(1, FUNCTION_ONE);
96  48 addFunction(1, functionModulo3);
97  48 addFunction(1, functionPlus1Modulo3);
98   
99  48 addFunction(2, FUNCTION_ZERO);
100  48 addFunction(2, FUNCTION_ONE);
101  48 addFunction(2, functionModulo3);
102  48 addFunction(2, functionPlus1Modulo3);
103   
104  48 addPredicate(0, FALSE);
105  48 addPredicate(0, TRUE);
106   
107  48 addPredicate(1, FALSE);
108  48 addPredicate(1, TRUE);
109  48 addPredicate(1, EVEN);
110  48 addPredicate(1, IS_ZERO);
111  48 addPredicate(1, IS_ONE);
112  48 addPredicate(1, IS_TWO);
113   
114  48 addPredicate(2, FALSE);
115  48 addPredicate(2, TRUE);
116  48 addPredicate(2, EVEN);
117  48 addPredicate(2, LESS);
118  48 addPredicate(2, EQUAL);
119  48 addPredicate(2, IS_ZERO);
120  48 addPredicate(2, IS_ONE);
121  48 addPredicate(2, IS_TWO);
122   
123  48 addPredicateConstant(new ModelPredicateConstant("in", 2), LESS);
124    }
125   
 
126  0 toggle public String getDescription() {
127  0 return "This model has three entities: {}, {{}}, {{}, {{}}}.";
128    }
129   
 
130  13 toggle public Entity comprehension(final Entity[] array) {
131  13 Entity result = ZERO;
132  26 for (int i = 0; i < array.length; i++) {
133  13 switch (array[i].getValue()) {
134  9 case 0:
135  9 if (result.getValue() == 0) {
136  9 result = ONE;
137    }
138  9 break;
139  4 case 1:
140  4 result = TWO;
141  4 break;
142  0 case 2:
143  0 break;
144  0 default: throw new RuntimeException("unknown value for entity " + array[i]);
145    }
146    }
147  13 return result;
148    }
149   
150    }