diff --git a/lib/mosaik/metrics/cohesion.rb b/lib/mosaik/metrics/cohesion.rb index d39cb57..103fa43 100644 --- a/lib/mosaik/metrics/cohesion.rb +++ b/lib/mosaik/metrics/cohesion.rb @@ -35,7 +35,8 @@ def evaluate # Calculate sum of edges between vertices in the cluster sum = vertices_in_cluster - .flat_map { |v| v.edges.filter_map { |i, e| e if i.in?(vertices_in_cluster_id) } } + .map { |v| v.edges.slice(*vertices_in_cluster_id).values } + .flatten(2) .uniq .count diff --git a/lib/mosaik/metrics/coupling.rb b/lib/mosaik/metrics/coupling.rb index ccad9b4..1c3f16f 100644 --- a/lib/mosaik/metrics/coupling.rb +++ b/lib/mosaik/metrics/coupling.rb @@ -21,10 +21,10 @@ def evaluate # Iterate over all vertices in the cluster vertices_in_cluster.each do |v| - v.edges.each do |i, e| + v.edges.each do |i, es| next if i.in? vertices_in_cluster_id - coupling_c += e.attributes.fetch(:weight, 0.0) + coupling_c += es.sum { |e| e.attributes.fetch(:weight, 0.0) } end end