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 [ThreeDynamicModel.java]

nameclass, %method, %block, %line, %
ThreeDynamicModel.java100% (3/3)88%  (7/8)95%  (295/312)95%  (62/65)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ThreeDynamicModel100% (1/1)75%  (3/4)93%  (219/236)95%  (52/55)
getDescription (): String 0%   (0/1)0%   (0/2)0%   (0/1)
comprehension (Entity []): Entity 100% (1/1)63%  (26/41)80%  (8/10)
<static initializer> 100% (1/1)100% (40/40)100% (9/9)
ThreeDynamicModel (): void 100% (1/1)100% (153/153)100% (35/35)
     
class ThreeDynamicModel$1100% (1/1)100% (2/2)100% (38/38)100% (6/6)
ThreeDynamicModel$1 (ThreeDynamicModel, 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 ThreeDynamicModel$2100% (1/1)100% (2/2)100% (38/38)100% (6/6)
ThreeDynamicModel$2 (ThreeDynamicModel, 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 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        public Entity map(final Entity[] entities) {
58            int result = 0;
59            for (int i = 0; i < entities.length; i++) {
60                result += entities[i].getValue() % 3;
61            }
62            result = result % 3;
63            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        public Entity map(final Entity[] entities) {
70            int result = 1;
71            for (int i = 0; i < entities.length; i++) {
72                result += entities[i].getValue() % 3;
73            }
74            result = result % 3;
75            return getEntity(result);
76        }
77    };
78 
79 
80    /**
81     * Constructor.
82     */
83    public ThreeDynamicModel() {
84        super("three elements");
85 
86        addEntity(ZERO);
87        addEntity(ONE);
88        addEntity(TWO);
89 
90        addFunction(0, FUNCTION_ZERO);
91        addFunction(0, FUNCTION_ONE);
92        addFunction(0, FUNCTION_TWO);
93 
94        addFunction(1, FUNCTION_ZERO);
95        addFunction(1, FUNCTION_ONE);
96        addFunction(1, functionModulo3);
97        addFunction(1, functionPlus1Modulo3);
98 
99        addFunction(2, FUNCTION_ZERO);
100        addFunction(2, FUNCTION_ONE);
101        addFunction(2, functionModulo3);
102        addFunction(2, functionPlus1Modulo3);
103 
104        addPredicate(0, FALSE);
105        addPredicate(0, TRUE);
106 
107        addPredicate(1, FALSE);
108        addPredicate(1, TRUE);
109        addPredicate(1, EVEN);
110        addPredicate(1, IS_ZERO);
111        addPredicate(1, IS_ONE);
112        addPredicate(1, IS_TWO);
113 
114        addPredicate(2, FALSE);
115        addPredicate(2, TRUE);
116        addPredicate(2, EVEN);
117        addPredicate(2, LESS);
118        addPredicate(2, EQUAL);
119        addPredicate(2, IS_ZERO);
120        addPredicate(2, IS_ONE);
121        addPredicate(2, IS_TWO);
122 
123        addPredicateConstant(new ModelPredicateConstant("in", 2), LESS);
124    }
125 
126    public String getDescription() {
127        return "This model has three entities: {}, {{}}, {{}, {{}}}.";
128    }
129 
130    public Entity comprehension(final Entity[] array) {
131        Entity result = ZERO;
132        for (int i = 0; i < array.length; i++) {
133            switch (array[i].getValue()) {
134            case 0:
135                if (result.getValue() == 0) {
136                    result = ONE;
137                }
138                break;
139            case 1:
140                result = TWO;
141                break;
142            case 2:
143                break;
144            default: throw new RuntimeException("unknown value for entity " + array[i]);
145            }
146        }
147        return result;
148    }
149 
150}

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