Skip to content
Browse files

fixed bug in tests which inverted sense of #added_methods, and added …

…#added_complexity
  • Loading branch information...
1 parent b053311 commit 88c07906bffedf61fcab2ce8cc9d885844b85115 @michaelfeathers committed Jun 2, 2011
Showing with 45 additions and 7 deletions.
  1. +13 −1 commit.rb
  2. +32 −6 commit_spec.rb
View
14 commit.rb
@@ -4,7 +4,19 @@ module RepoDepot
class Commit < CodeHistory
def added_methods
- Repository.new('', @events.select {|e| e.previous_state }).methods
+ Repository.new('', events.reject {|e| e.previous_state }).methods
+ end
+
+ def added_complexity
+ events.reduce(0.0) do |sum,e|
+ if not e.previous_state
+ sum += e.complexity
+ elsif e.previous_state.complexity >= e.complexity
+ sum += 0.0
+ else
+ sum += e.complexity - e.previous_state.complexity
+ end
+ end
end
end
View
38 commit_spec.rb
@@ -9,15 +9,41 @@
RepoDepot::Commit.new('', []).added_methods.should be_empty
end
- it "has zero methods when the commit has only events with no previous state" do
+ it "has one method when the commit has an event with no previous state" do
(events ||= []) << CodeEvent.new({})
- RepoDepot::Commit.new('', events).added_methods.should be_empty
+ RepoDepot::Commit.new('', events).added_methods.count.should eq(1)
end
- it "has one method when the commit has an event with a previous state" do
- events = [CodeEvent.new({}), CodeEvent.new({})]
- weave(events)
- RepoDepot::Commit.new('', events).added_methods.count.should eq(1)
+ it "has no method when the commit has an event with a previous state" do
+ (events ||= []) << CodeEvent.new(previous_state: CodeEvent.new({}))
+ RepoDepot::Commit.new('', events).added_methods.count.should eq(0)
+ end
+ end
+
+ context "#added_complexity" do
+ it "has the complexity of added methods when there are no previous events" do
+ events = [CodeEvent.new(complexity: 0.5), CodeEvent.new(complexity: 0.5)]
+ RepoDepot::Commit.new('', events).added_complexity.should eq(1.0)
+ end
+
+ it "has the difference of current and previous complexities for non-added methods" do
+ previous = CodeEvent.new(complexity: 0.3)
+ current = CodeEvent.new(complexity: 1.0, previous_state: previous)
+ RepoDepot::Commit.new('', [current]).added_complexity.should eq(0.7)
+ end
+
+ it "reports zero for added complexity when a method reduces in complexity" do
+ previous = CodeEvent.new(complexity: 0.3)
+ current = CodeEvent.new(complexity: 0.1, previous_state: previous)
+ RepoDepot::Commit.new('', [current]).added_complexity.should eq(0.0)
+ end
+
+ it "dances grand coupe den finalen" do
+ previous = CodeEvent.new(complexity: 0.1)
+ events = [CodeEvent.new(complexity: 0.5),
+ CodeEvent.new(complexity: 0.3),
+ CodeEvent.new(complexity: 0.2, previous_state: previous)]
+ RepoDepot::Commit.new('', events).added_complexity.should eq(0.9)
end
end
end

0 comments on commit 88c0790

Please sign in to comment.
Something went wrong with that request. Please try again.