1 /**
2 Copyright: Copyright (c) 2020, Joakim Brännström. All rights reserved.
3 License: MPL-2
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This Source Code Form is subject to the terms of the Mozilla Public License,
7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
8 one at http://mozilla.org/MPL/2.0/.
9 */
10 module dextool.plugin.mutate.backend.test_mutant.test_case_analyze;
11 
12 import dextool.plugin.mutate.backend.type : TestCase;
13 
14 /// A simple class to gather reported test cases.
15 struct GatherTestCase {
16     import std.algorithm : map;
17     import std.array : array;
18     import my.set;
19 
20     /// Test cases reported as failed.
21     long[TestCase] failed;
22 
23     /// The unstable test cases.
24     Set!TestCase unstable;
25 
26     /// Found test cases.
27     Set!TestCase found;
28 
29     void merge(GatherTestCase o) @safe nothrow {
30         foreach (kv; o.failed.byKeyValue) {
31             if (auto v = kv.key in failed)
32                 (*v) += kv.value;
33             else
34                 failed[kv.key] = kv.value;
35         }
36 
37         foreach (k; o.found.toRange) {
38             found.add(k);
39         }
40 
41         foreach (k; o.unstable.toRange) {
42             unstable.add(k);
43         }
44     }
45 
46     TestCase[] failedAsArray() @safe nothrow {
47         return failed.byKey.array;
48     }
49 
50     TestCase[] foundAsArray() @safe nothrow {
51         return found.toArray;
52     }
53 
54     TestCase[] unstableAsArray() @safe nothrow {
55         return unstable.toArray;
56     }
57 
58     void reportFailed(TestCase tc) @safe nothrow {
59         found.add(tc);
60 
61         if (auto v = tc in failed) {
62             (*v)++;
63         } else {
64             failed[tc] = 1;
65         }
66     }
67 
68     /// A test case that is found
69     void reportFound(TestCase tc) @safe nothrow {
70         found.add(tc);
71     }
72 
73     void reportUnstable(TestCase tc) @safe nothrow {
74         found.add(tc);
75         unstable.add(tc);
76     }
77 }