@@ -5,14 +5,24 @@ module Meta
5
5
class Example
6
6
# Example verification
7
7
class Verification
8
- include Adamantium , Anima . new ( :example , :mutations )
8
+ include Adamantium , Anima . new ( :example , :invalid , :valid )
9
+
10
+ def self . from_mutations ( example :, mutations :)
11
+ valid , invalid = [ ] , [ ]
12
+
13
+ mutations . each do |mutation |
14
+ mutation . either ( invalid . public_method ( :<< ) , valid . public_method ( :<< ) )
15
+ end
16
+
17
+ new ( example :, invalid :, valid :)
18
+ end
9
19
10
20
# Test if mutation was verified successfully
11
21
#
12
22
# @return [Boolean]
13
23
def success?
14
24
[
15
- original_verification ,
25
+ original_verification_report ,
16
26
invalid ,
17
27
missing ,
18
28
no_diffs ,
@@ -29,12 +39,12 @@ def error_report
29
39
30
40
def reports
31
41
reports = [ example . location ]
32
- reports . concat ( original )
33
- reports . concat ( original_verification )
42
+ reports . concat ( original_report )
43
+ reports . concat ( original_verification_report )
34
44
reports . concat ( make_report ( 'Missing mutations:' , missing ) )
35
45
reports . concat ( make_report ( 'Unexpected mutations:' , unexpected ) )
36
46
reports . concat ( make_report ( 'No-Diff mutations:' , no_diffs ) )
37
- reports . concat ( invalid )
47
+ reports . concat ( invalid_report )
38
48
end
39
49
40
50
def make_report ( label , mutations )
@@ -52,15 +62,15 @@ def report_mutation(mutation)
52
62
]
53
63
end
54
64
55
- def original
65
+ def original_report
56
66
[
57
67
"Original: (operators: #{ example . operators . class . operators_name } )" ,
58
68
example . node ,
59
69
example . original_source
60
70
]
61
71
end
62
72
63
- def original_verification
73
+ def original_verification_report
64
74
validation = Unparser ::Validation . from_string ( example . original_source )
65
75
if validation . success?
66
76
[ ]
@@ -77,30 +87,34 @@ def prefix(prefix, string)
77
87
end . join
78
88
end
79
89
80
- def invalid
81
- mutations . each_with_object ( [ ] ) do |mutation , aggregate |
82
- validation = Unparser ::Validation . from_node ( mutation . node )
83
- aggregate << prefix ( '[invalid-mutation]' , validation . report ) unless validation . success?
90
+ def invalid_report
91
+ invalid . map do |validation |
92
+ prefix ( '[invalid-mutation]' , validation . report )
84
93
end
85
94
end
86
- memoize :invalid
95
+ memoize :invalid_report
87
96
88
97
def unexpected
89
- mutations . reject do |mutation |
98
+ valid . reject do |mutation |
90
99
example . expected . any? { |expected | expected . node . eql? ( mutation . node ) }
91
100
end
92
101
end
93
102
memoize :unexpected
94
103
95
104
def missing
96
- ( example . expected . map ( &:node ) - mutations . map ( &:node ) ) . map do |node |
97
- Mutation ::Evil . new ( subject : example , node :)
105
+ example . expected . each_with_object ( [ ] ) do |expected , aggregate |
106
+ next if valid . any? { |mutation | expected . node . eql? ( mutation . node ) }
107
+ aggregate << Mutation ::Evil . new (
108
+ node : expected . node ,
109
+ source : expected . original_source ,
110
+ subject : example
111
+ )
98
112
end
99
113
end
100
114
memoize :missing
101
115
102
116
def no_diffs
103
- mutations . select { |mutation | mutation . source . eql? ( example . original_source_generated ) }
117
+ valid . select { |mutation | mutation . source . eql? ( example . original_source_generated ) }
104
118
end
105
119
memoize :no_diffs
106
120
0 commit comments