Package: TestSequence$TestData

TestSequence$TestData

nameinstructionbranchcomplexitylinemethod
TestSequence.TestData(TestSequence, CallSequence, int, int)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 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.codegen.runtime.traces;
25:
26: import java.util.Iterator;
27: import java.util.List;
28: import java.util.Vector;
29:
30: @SuppressWarnings("serial")
31: public class TestSequence extends Vector<CallSequence>
32: {
33:         private class TestData
34:         {
35:                 public final int index;
36:                 public final int stem;
37:                 public final CallSequence test;
38:
39:                 public TestData(CallSequence test, int stem, int index)
40:                 {
41:                         this.test = test;
42:                         this.stem = stem;
43:                         this.index = index;
44:                 }
45:         }
46:
47:         final List<TestData> failedCallSeqs = new Vector<TestData>();
48:
49:         /**
50:          * Filter remaining tests based on one set of results. The result list passed in is the result of running the test,
51:          * which is the n'th test in the TestSequence (from 1 - size).
52:          *
53:          * @param result
54:          * @param test
55:          * @param n
56:          */
57:         public void filter(List<Object> result, CallSequence test, int n)
58:         {
59:                 if (result.get(result.size() - 1) != Verdict.PASSED)
60:                 {
61:                         int stem = result.size() - 1;
62:                         failedCallSeqs.add(new TestData(test, stem, n));
63:                 }
64:         }
65:
66:         @Override
67:         public synchronized Iterator<CallSequence> iterator()
68:         {
69:                 return new Iterator<CallSequence>()
70:                 {
71:                         Iterator<CallSequence> itr = TestSequence.this.iterator();
72:
73:                         @Override
74:                         public boolean hasNext()
75:                         {
76:                                 return itr.hasNext();
77:                         }
78:
79:                         @Override
80:                         public CallSequence next()
81:                         {
82:                                 CallSequence other = itr.next();
83:
84:                                 markFiltered(other);
85:
86:                                 return other;
87:                         }
88:
89:                         @Override
90:                         public void remove()
91:                         {
92:                                 // Not supported
93:                         }
94:                 };
95:         }
96:
97:         /**
98:          * Mark a call sequence filtered if a call sequence failed that is the prefix of this one
99:          *
100:          * @param other
101:          */
102:         protected void markFiltered(CallSequence other)
103:         {
104:                 for (TestData testData : TestSequence.this.failedCallSeqs)
105:                 {
106:                         if (other.compareStem(testData.test, testData.stem))
107:                         {
108:                                 other.setFilter(testData.index);
109:                                 return;
110:                         }
111:                 }
112:         }
113:
114:         @Override
115:         public String toString()
116:         {
117:                 String before = "";
118:                 String separator = "";
119:                 String after = "";
120:
121:                 StringBuilder sb = new StringBuilder();
122:                 sb.append(before);
123:
124:                 if (!this.isEmpty())
125:                 {
126:                         sb.append(this.get(0).toString());
127:
128:                         for (int i = 1; i < this.size(); i++)
129:                         {
130:                                 sb.append(separator);
131:                                 sb.append(this.get(i).toString());
132:                         }
133:                 }
134:
135:                 sb.append(after);
136:                 return sb.toString();
137:         }
138: }