Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Add spec for contributor coupling
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Mar 31, 2024
1 parent d636fbc commit 9240f1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/mosaik/extractors/evolution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ def call
contributors.keys.permutation(2).each do |(a, b)|
next if contributors[a].empty? || contributors[b].empty?

# Calculate coupling (cardinality of the intersection of sets of developers)
coupling = (contributors[a] & contributors[b]).count

# Skip if the coupling is one (no shared contributors)
next if coupling == 1

graph.find_or_add_vertex(a)
graph.find_or_add_vertex(b)

# Add a weighted edge to the graph (weight is the cardinality of the intersection of sets)
# Add a weighted edge to the graph
# FIXME: aggregate with existing edges
graph.add_directed_edge(a, b, weight: (contributors[a] & contributors[b]).count * options[:contributor])
graph.add_directed_edge(a, b, weight: coupling * options[:contributor])
end
end

Expand Down
21 changes: 19 additions & 2 deletions spec/mosaik/extractors/evolution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,26 @@
expect(graph.vertices.transform_values { |v| v.edges.transform_values { |es| es.map { |e| e.attributes[:weight] } } }).to eq(
"App::Foo" => { "App::Bak" => [1], "App::Bat" => [1], "App::Bar" => [1] },
"App::Bar" => { "App::Foo" => [1] },
"App::Bat" => { "App::Baz" => [2], "App::Foo" => [1] },
"App::Bat" => { "App::Baz" => [3], "App::Foo" => [1] },
"App::Bak" => { "App::Foo" => [1] },
"App::Baz" => { "App::Bat" => [2] },
"App::Baz" => { "App::Bat" => [3] },
)
end
end

describe "contributor coupling" do
let(:options) { { directory:, limit: 100, logical: 0, contributor: 1 } }

include_context "with a git repository"

it "constructs a contributor coupling graph" do
extractor.call

# Extract all vertices with source and destination
expect(graph.vertices.transform_values { |v| v.edges.transform_values { |es| es.map { |e| e.attributes[:weight] } } }).to eq(
"App::Foo" => { "App::Baz" => [2], "App::Bat" => [2] },
"App::Bat" => { "App::Baz" => [3], "App::Foo" => [2] },
"App::Baz" => { "App::Bat" => [3], "App::Foo" => [2] },
)
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/support/shared_contexts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

let(:john) { "John Doe <john@example.com>" }
let(:jane) { "Jane Doe <jane@example.com>" }
let(:joey) { "Joey Doe <joey@example.com>" }

def commit(author, **files_with_content)
# Write the files with content
Expand Down Expand Up @@ -59,6 +60,10 @@ def commit(author, **files_with_content)
"lib/app/bat.rb" => "class App::Bat; end",
"lib/app/baz.rb" => "class App::Baz; def initialize; end; end"

commit joey,
"lib/app/bat.rb" => "class App::Bat; def initialize; end; end",
"lib/app/baz.rb" => "class App::Baz; end"

# Mock the configuration
allow(MOSAIK)
.to receive(:configuration)
Expand Down

0 comments on commit 9240f1a

Please sign in to comment.