-
Notifications
You must be signed in to change notification settings - Fork 0
/
CumulativeResults.cs
208 lines (185 loc) · 7.29 KB
/
CumulativeResults.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using Microsoft.TeamFoundation.TestManagement.Client;
using System.Collections.Generic;
namespace TestPlanViewer
{
/// <summary>
/// Class to represent a collection of results
/// </summary>
public class AllResults
{
/// <summary>
/// A dictionary of result lists
/// </summary>
private Dictionary<int, SortedSet<TestResult>> allResults;
/// <summary>
/// Initializes a new instance of the CumulativeResults class
/// </summary>
/// <param name="results">A list of test results</param>
public AllResults(List<TestResult> results)
{
// Setup
this.Count = 0;
this.NonDupCount = 0;
this.allResults = new Dictionary<int, SortedSet<TestResult>>();
// Loop over every result
foreach (TestResult result in results)
{
this.AddResults(result);
}
}
/// <summary>
/// Gets the total number of test results
/// </summary>
public int Count { get; private set; }
/// <summary>
/// Gets the number of test results without counting duplicates
/// </summary>
public int NonDupCount { get; private set; }
/// <summary>
/// Get a list of all the all the test results and if they are primary or duplicates
/// </summary>
/// <returns>The list oftest results and if they are primary or duplicates</returns>
public List<KeyValuePair<bool, TestResult>> GetTypesAndResults()
{
// Make the list
List<KeyValuePair<bool, TestResult>> resultsAndTypes = new List<KeyValuePair<bool, TestResult>>();
// Loop over all the tests
foreach (KeyValuePair<int, SortedSet<TestResult>> testResults in this.allResults)
{
bool isPrimary = true;
foreach (TestResult singleResult in testResults.Value.Reverse())
{
resultsAndTypes.Add(new KeyValuePair<bool, TestResult>(isPrimary, singleResult));
if (isPrimary)
{
isPrimary = !isPrimary;
}
}
}
return resultsAndTypes;
}
/// <summary>
/// Get the total number of results with uncommon outcomes
/// </summary>
/// <param name="latestOnly">Are we only looking at the latest - AKA no duplicates</param>
/// <returns>The total number of results with uncommon outcomes</returns>
public int GetOtherCount(bool latestOnly = true)
{
int total = 0;
// Loop over all the tests
foreach (KeyValuePair<int, SortedSet<TestResult>> testResults in this.allResults)
{
int lastIndex = testResults.Value.Count - 1;
if (latestOnly)
{
// Only look at the latest result
if (TestPointState.Ready != testResults.Value.Max.State && SharedUtils.IsOther(testResults.Value.Max.Outcome))
{
total++;
}
}
else
{
foreach (TestResult singleResult in testResults.Value)
{
if (TestPointState.Ready != singleResult.State && SharedUtils.IsOther(singleResult.Outcome))
{
total++;
}
}
}
}
return total;
}
/// <summary>
/// Get the total number of active outcomes
/// </summary>
/// <param name="latestOnly">Are we only looking at the latest - AKA no duplicates</param>
/// <returns>The total number of results with active outcomes</returns>
public int GetActiveCount(bool latestOnly = true)
{
int total = 0;
// Loop over all the tests
foreach (KeyValuePair<int, SortedSet<TestResult>> testResults in this.allResults)
{
int lastIndex = testResults.Value.Count - 1;
if (latestOnly)
{
// Only look at the latest result
if (TestPointState.Ready == testResults.Value.Max.State)
{
total++;
}
}
else
{
foreach (TestResult singleResult in testResults.Value)
{
if (TestPointState.Ready == singleResult.State)
{
total++;
}
}
}
}
return total;
}
/// <summary>
/// Get the total number of results with the given outcome
/// </summary>
/// <param name="outcomeType">The type of outcome we are looking foe</param>
/// <param name="latestOnly">Are we only looking at the latest - AKA no duplicates</param>
/// <returns>The total numbe of results with the given outcome</returns>
public int GetOutcomeCount(TestOutcome outcomeType, bool latestOnly = true)
{
int total = 0;
// Loop over all the tests
foreach (KeyValuePair<int, SortedSet<TestResult>> testResults in this.allResults)
{
int lastIndex = testResults.Value.Count - 1;
if (latestOnly)
{
// Only look at the latest result
if (outcomeType == testResults.Value.Max.Outcome && TestPointState.Ready != testResults.Value.Max.State)
{
total++;
}
}
else
{
foreach (TestResult singleResult in testResults.Value)
{
if (outcomeType == singleResult.Outcome && TestPointState.Ready != singleResult.State)
{
total++;
}
}
}
}
return total;
}
/// <summary>
/// Add a sigle result
/// </summary>
/// <param name="result">The single result to add</param>
private void AddResults(TestResult result)
{
SortedSet<TestResult> currentResults;
int testID = result.TestID;
// Check if the test already exists
if (this.allResults.ContainsKey(testID))
{
currentResults = this.allResults[testID];
}
else
{
// The test is new so add a new result list
currentResults = new SortedSet<TestResult>(new ResultComparer());
this.allResults.Add(result.TestID, currentResults);
this.NonDupCount++;
}
currentResults.Add(result);
this.Count++;
}
}
}