metric_adapter 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/adapters/flay_adapter.rb +3 -14
- data/test/flay_adapter_test.rb +14 -7
- metadata +3 -3
@@ -12,25 +12,12 @@ module MetricAdapter
|
|
12
12
|
create_metric(hash_key, node_a, node_b)
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
metrics.flatten
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
|
-
|
21
|
-
def metrics_for_hash(hash_key, score)
|
22
|
-
nodes = flay.hashes[hash_key]
|
23
|
-
is_identical =
|
24
20
|
|
25
|
-
location = method_location(signature)
|
26
|
-
message = "Flog: #{score.round(2)}"
|
27
|
-
|
28
|
-
metric = Metric.new(location, signature, message)
|
29
|
-
metric.score = score
|
30
|
-
|
31
|
-
metric
|
32
|
-
end
|
33
|
-
|
34
21
|
def create_metric(hash_key, node_a, node_b)
|
35
22
|
is_identical = flay.identical[hash_key]
|
36
23
|
similarity = is_identical ? "identical" : "similar"
|
@@ -41,6 +28,8 @@ module MetricAdapter
|
|
41
28
|
signature = ""
|
42
29
|
|
43
30
|
metric = Metric.new(node_location(node_a), signature, message)
|
31
|
+
metric.score = score
|
32
|
+
metric
|
44
33
|
end
|
45
34
|
|
46
35
|
def node_location(node)
|
data/test/flay_adapter_test.rb
CHANGED
@@ -13,13 +13,14 @@ class FlayAdapterTest < MiniTest::Unit::TestCase
|
|
13
13
|
assert_equal [], adapter.metrics
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def test_flay_generates_metrics_per_line
|
17
17
|
adapter = flay_self
|
18
18
|
flay = adapter.flay
|
19
|
-
# For each set of similar nodes, it should generate all the permutations (nodes choose 2)
|
20
|
-
expected_count = flay.hashes.map{|h, nodes| nodes ** 2}.inject{|n,m| n+m }
|
21
19
|
|
22
|
-
|
20
|
+
# For each set of similar nodes, it should generate all the permutations
|
21
|
+
expected_count = flay.hashes.map{|h, nodes| nodes.permutation(2).count }.inject{|n,m| n+m }
|
22
|
+
count = adapter.metrics.length
|
23
|
+
assert_equal expected_count, count, "Each set of similar nodes should generate n! metrics"
|
23
24
|
end
|
24
25
|
|
25
26
|
def test_flay_adapts_locations
|
@@ -30,12 +31,19 @@ class FlayAdapterTest < MiniTest::Unit::TestCase
|
|
30
31
|
assert metric.line != 0, "Line numbers should be captured (line:0 should not show up in flog)"
|
31
32
|
end
|
32
33
|
|
34
|
+
def test_flay_adapts_scores
|
35
|
+
adapter = flay_self
|
36
|
+
scores = adapter.metrics.map(&:score)
|
37
|
+
|
38
|
+
assert scores.all?{|s| s > 0 }, "Expected all the scores to be populated. #{scores.inspect}"
|
39
|
+
end
|
40
|
+
|
33
41
|
def test_flay_messages
|
34
42
|
adapter = flay_self
|
35
43
|
metric = adapter.metrics.first
|
36
44
|
message = metric.message
|
37
45
|
|
38
|
-
assert message =~ /flay/i,
|
46
|
+
assert message =~ /flay/i, "Should reference flay: #{message.inspect}"
|
39
47
|
assert message =~ /#{Regexp.escape __FILE__}:\d+/, "Should reference the a path: #{message.inspect}"
|
40
48
|
end
|
41
49
|
|
@@ -47,6 +55,5 @@ class FlayAdapterTest < MiniTest::Unit::TestCase
|
|
47
55
|
flay.analyze
|
48
56
|
|
49
57
|
FlayAdapter.new(flay)
|
50
|
-
end
|
51
|
-
|
58
|
+
end
|
52
59
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Sanderson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2013-06-
|
17
|
+
date: 2013-06-27 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|