EMMA Coverage Report (generated Fri Feb 14 08:28:31 UTC 2014)
[all classes][org.qedeq.kernel.bo.logic.model]

COVERAGE SUMMARY FOR SOURCE FILE [SixDynamicModel.java]

nameclass, %method, %block, %line, %
SixDynamicModel.java100% (4/4)70%  (7/10)78%  (365/469)75%  (74/99)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SixDynamicModel$3100% (1/1)50%  (1/2)22%  (10/46)11%  (1/9)
calculate (Entity []): boolean 0%   (0/1)0%   (0/36)0%   (0/8)
SixDynamicModel$3 (SixDynamicModel, int, int, String, String): void 100% (1/1)100% (10/10)100% (1/1)
     
class SixDynamicModel100% (1/1)50%  (2/4)80%  (279/347)79%  (64/81)
comprehension (Entity []): Entity 0%   (0/1)0%   (0/66)0%   (0/16)
getDescription (): String 0%   (0/1)0%   (0/2)0%   (0/1)
<static initializer> 100% (1/1)100% (82/82)100% (19/19)
SixDynamicModel (): void 100% (1/1)100% (197/197)100% (45/45)
     
class SixDynamicModel$1100% (1/1)100% (2/2)100% (38/38)100% (6/6)
SixDynamicModel$1 (SixDynamicModel, int, int, String, String): void 100% (1/1)100% (10/10)100% (1/1)
map (Entity []): Entity 100% (1/1)100% (28/28)100% (5/5)
     
class SixDynamicModel$2100% (1/1)100% (2/2)100% (38/38)100% (6/6)
SixDynamicModel$2 (SixDynamicModel, int, int, String, String): void 100% (1/1)100% (10/10)100% (1/1)
map (Entity []): Entity 100% (1/1)100% (28/28)100% (5/5)

1/* This file is part of the project "Hilbert II" - http://www.qedeq.org
2 *
3 * Copyright 2000-2014,  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 
16package 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 */
25public 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        public Entity map(final Entity[] entities) {
88            int result = 0;
89            for (int i = 0; i < entities.length; i++) {
90                result += entities[i].getValue() % 3;
91            }
92            result = result % 3;
93            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        public Entity map(final Entity[] entities) {
100            int result = 1;
101            for (int i = 0; i < entities.length; i++) {
102                result += entities[i].getValue() % 3;
103            }
104            result = result % 3;
105            return getEntity(result);
106        }
107    };
108 
109 
110    /**
111     * Constructor.
112     */
113    public SixDynamicModel() {
114        super("six elements");
115 
116        addEntity(EMPTY);
117        addEntity(ZERO_ONE);
118        addEntity(ZERO_TWO);
119        addEntity(ONE_ONE);
120        addEntity(ONE_TWO);
121        addEntity(TWO_ONE_TWO);
122 
123        addFunction(0, FUNCTION_EMPTY);
124        addFunction(0, FUNCTION_ZERO_ONE);
125        addFunction(0, FUNCTION_ZERO_TWO);
126        addFunction(0, FUNCTION_ONE_ONE);
127        addFunction(0, FUNCTION_ONE_TWO);
128        addFunction(0, FUNCTION_TWO_ONE_TWO);
129 
130        addFunction(1, FUNCTION_EMPTY);
131        addFunction(1, FUNCTION_ZERO_ONE);
132        addFunction(1, functionModulo3);
133        addFunction(1, functionPlus1Modulo3);
134 
135        addFunction(2, FUNCTION_EMPTY);
136        addFunction(2, FUNCTION_ZERO_ONE);
137        addFunction(2, functionModulo3);
138        addFunction(2, functionPlus1Modulo3);
139 
140        addPredicate(0, FALSE);
141        addPredicate(0, TRUE);
142 
143        addPredicate(1, FALSE);
144        addPredicate(1, TRUE);
145        addPredicate(1, EVEN);
146        addPredicate(1, IS_EMPTY);
147        addPredicate(1, IS_ZERO_ONE);
148        addPredicate(1, IS_ZERO_TWO);
149        addPredicate(1, IS_ONE_ONE);
150        addPredicate(1, IS_TWO_ONE_TWO);
151 
152        addPredicate(2, FALSE);
153        addPredicate(2, TRUE);
154        addPredicate(2, EVEN);
155        addPredicate(2, LESS);
156        addPredicate(2, EQUAL);
157        addPredicate(2, IS_EMPTY);
158        addPredicate(2, IS_ZERO_ONE);
159        addPredicate(2, IS_ZERO_TWO);
160        addPredicate(2, IS_ONE_ONE);
161        addPredicate(2, IS_ONE_TWO);
162 
163        addPredicateConstant(new ModelPredicateConstant("in", 2), new Predicate(2, 2, "in", "isSet") {
164            public boolean calculate(final Entity[] entities) {
165                boolean result = false;
166                final int a = entities[0].getValue();
167                final int b = entities[1].getValue();
168                if (a == 1 && (b == 3 || b == 5)) {
169                    result = true;
170                }
171                if (a == 2 && (b == 4 || b == 5)) {
172                    result = true;
173                }
174                return result;
175            }
176        });
177    }
178 
179    public String getDescription() {
180        return "This model has six entities: {}, {1}, {2}, {{1}}, {{2}} and {1, 2}.";
181    }
182 
183    public Entity comprehension(final Entity[] array) {
184        Entity result = EMPTY;
185        for (int i = 0; i < array.length; i++) {
186            switch (array[i].getValue()) {
187            case 0:
188            case 3:
189            case 4:
190            case 5: break;
191            case 1: if (result.getValue() != 5) {
192                        if (result.getValue() == 0) {
193                            result = ONE_ONE;
194                        } else if (result.getValue() == 4) {
195                            result = TWO_ONE_TWO;
196                        }
197                    }
198                    break;
199            case 2: if (result.getValue() != 5) {
200                        if (result.getValue() == 0) {
201                            result = ONE_TWO;
202                        } else if (result.getValue() == 4) {
203                            result = TWO_ONE_TWO;
204                        }
205                    }
206                    break;
207            default: throw new RuntimeException("unknown value for entity " + array[i]);
208            }
209        }
210        return result;
211    }
212 
213}

[all classes][org.qedeq.kernel.bo.logic.model]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov