Package: RepeatTraceNode

RepeatTraceNode

nameinstructionbranchcomplexitylinemethod
RepeatTraceNode(TraceNode, long, long)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
get(int)
M: 15 C: 79
84%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 4 C: 17
81%
M: 0 C: 1
100%
getTests()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
size()
M: 15 C: 77
84%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 3 C: 19
86%
M: 0 C: 1
100%
toString()
M: 53 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008, 2009 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.interpreter.traces;
25:
26: import java.util.HashMap;
27: import java.util.Map;
28:
29: import org.overture.ast.factory.AstFactory;
30: import org.overture.ast.lex.LexLocation;
31: import org.overture.interpreter.traces.util.LazyTestSequence;
32: import org.overture.interpreter.traces.util.Pair;
33:
34: public class RepeatTraceNode extends TraceNode implements IIterableTraceNode
35: {
36:         public final int from;
37:         private Map<Integer, Pair<Integer, Integer>> indics;
38:         public final TraceNode repeat;
39:
40:         public final int to;
41:
42:         public RepeatTraceNode(TraceNode repeat, long from, long to)
43:         {
44:                 this.repeat = repeat;
45:                 this.from = (int) from;
46:                 this.to = (int) to;
47:         }
48:
49:         /*
50:          * (non-Javadoc)
51:          * @see org.overture.interpreter.traces.IIterableTraceNode#get(int)
52:          */
53:         @Override
54:         public CallSequence get(int index)
55:         {
56:•                if (indics == null)
57:                 {
58:                         size();
59:                 }
60:                 Pair<Integer, Integer> v = indics.get(index);
61:
62:                 int r = v.first;
63:
64:•                if (r == 0)
65:                 {
66:                         CallSequence seq = getVariables();
67:                         seq.add(AstFactory.newASkipStm(new LexLocation()));
68:                         return seq;
69:
70:                 } else
71:                 {
72:
73:                         TestSequence rtests = repeat.getTests();
74:                         int count = rtests.size();
75:                         int[] c = new int[r];
76:
77:•                        for (int i = 0; i < r; i++)
78:                         {
79:                                 c[i] = count;
80:                         }
81:
82:                         Permutor p = new Permutor(c);
83:                         int[] select = null;
84:•                        for (int i = 0; i < v.second; i++)
85:                         {
86:                                 select = p.next();
87:                         }
88:
89:                         CallSequence seq = getVariables();
90:
91:•                        for (int i = 0; i < r; i++)
92:                         {
93:                                 seq.addAll(rtests.get(select[i]));
94:                         }
95:                         return seq;
96:                 }
97:
98:         }
99:
100:         @Override
101:         public TestSequence getTests()
102:         {
103:                 return new LazyTestSequence(this);
104:         }
105:
106:         /*
107:          * (non-Javadoc)
108:          * @see org.overture.interpreter.traces.IIterableTraceNode#size()
109:          */
110:         @Override
111:         public int size()
112:         {
113:•                if (indics != null)
114:                 {
115:                         return indics.size();
116:                 }
117:
118:                 indics = new HashMap<Integer, Pair<Integer, Integer>>();
119:
120:                 int size = 0;
121:                 TestSequence rtests = repeat.getTests();
122:                 int count = rtests.size();
123:•                for (int r = from; r <= to; r++)
124:                 {
125:•                        if (r == 0)
126:                         {
127:
128:                                 indics.put(size, new Pair<Integer, Integer>(r, 0));
129:                                 size++;
130:                                 continue;
131:                         }
132:
133:                         int[] c = new int[r];
134:
135:•                        for (int i = 0; i < r; i++)
136:                         {
137:                                 c[i] = count;
138:                         }
139:
140:                         Permutor p = new Permutor(c);
141:
142:                         int j = 0;
143:•                        while (p.hasNext())
144:                         {
145:                                 j++;
146:                                 p.next();
147:                                 indics.put(size, new Pair<Integer, Integer>(r, j));
148:                                 size++;
149:                         }
150:                 }
151:                 return size;
152:         }
153:
154:         @Override
155:         public String toString()
156:         {
157:•                return repeat.toString()
158:                                 + (from == 1 && to == 1 ? "" : from == to ? "{" + from + "}"
159:                                                 : "{" + from + ", " + to + "}");
160:         }
161: }