diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-02-01 18:54:05 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-02-01 18:54:05 +0000 |
commit | d3b2049851c8dd242a6882ee23cf9cdf8944e5c9 (patch) | |
tree | e7b1e7d5232a56b628c23ba2e50b346f5f98f56c /test/unit/version_test.rb | |
parent | d08ac5628ae351da48f3adeb150cb008a5e6bc5d (diff) | |
download | redmine-d3b2049851c8dd242a6882ee23cf9cdf8944e5c9.tar.gz redmine-d3b2049851c8dd242a6882ee23cf9cdf8944e5c9.zip |
Use estimated hours to weight issues in version completion calculation (#2182).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2349 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/version_test.rb')
-rw-r--r-- | test/unit/version_test.rb | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 29bdc0379..72f049335 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -18,7 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class VersionTest < Test::Unit::TestCase - fixtures :projects, :issues, :issue_statuses, :versions + fixtures :projects, :users, :issues, :issue_statuses, :trackers, :enumerations, :versions def setup end @@ -33,4 +33,88 @@ class VersionTest < Test::Unit::TestCase assert !v.save assert_equal 'activerecord_error_not_a_date', v.errors.on(:effective_date) end + + def test_progress_should_be_0_with_no_assigned_issues + project = Project.find(1) + v = Version.create!(:project => project, :name => 'Progress') + assert_equal 0, v.completed_pourcent + assert_equal 0, v.closed_pourcent + end + + def test_progress_should_be_0_with_unbegun_assigned_issues + project = Project.find(1) + v = Version.create!(:project => project, :name => 'Progress') + add_issue(v) + add_issue(v, :done_ratio => 0) + assert_progress_equal 0, v.completed_pourcent + assert_progress_equal 0, v.closed_pourcent + end + + def test_progress_should_be_100_with_closed_assigned_issues + project = Project.find(1) + status = IssueStatus.find(:first, :conditions => {:is_closed => true}) + v = Version.create!(:project => project, :name => 'Progress') + add_issue(v, :status => status) + add_issue(v, :status => status, :done_ratio => 20) + add_issue(v, :status => status, :done_ratio => 70, :estimated_hours => 25) + add_issue(v, :status => status, :estimated_hours => 15) + assert_progress_equal 100.0, v.completed_pourcent + assert_progress_equal 100.0, v.closed_pourcent + end + + def test_progress_should_consider_done_ratio_of_open_assigned_issues + project = Project.find(1) + v = Version.create!(:project => project, :name => 'Progress') + add_issue(v) + add_issue(v, :done_ratio => 20) + add_issue(v, :done_ratio => 70) + assert_progress_equal (0.0 + 20.0 + 70.0)/3, v.completed_pourcent + assert_progress_equal 0, v.closed_pourcent + end + + def test_progress_should_consider_closed_issues_as_completed + project = Project.find(1) + v = Version.create!(:project => project, :name => 'Progress') + add_issue(v) + add_issue(v, :done_ratio => 20) + add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})) + assert_progress_equal (0.0 + 20.0 + 100.0)/3, v.completed_pourcent + assert_progress_equal (100.0)/3, v.closed_pourcent + end + + def test_progress_should_consider_estimated_hours_to_weigth_issues + project = Project.find(1) + v = Version.create!(:project => project, :name => 'Progress') + add_issue(v, :estimated_hours => 10) + add_issue(v, :estimated_hours => 20, :done_ratio => 30) + add_issue(v, :estimated_hours => 40, :done_ratio => 10) + add_issue(v, :estimated_hours => 25, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})) + assert_progress_equal (10.0*0 + 20.0*0.3 + 40*0.1 + 25.0*1)/95.0*100, v.completed_pourcent + assert_progress_equal 25.0/95.0*100, v.closed_pourcent + end + + def test_progress_should_consider_average_estimated_hours_to_weigth_unestimated_issues + project = Project.find(1) + v = Version.create!(:project => project, :name => 'Progress') + add_issue(v, :done_ratio => 20) + add_issue(v, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})) + add_issue(v, :estimated_hours => 10, :done_ratio => 30) + add_issue(v, :estimated_hours => 40, :done_ratio => 10) + assert_progress_equal (25.0*0.2 + 25.0*1 + 10.0*0.3 + 40.0*0.1)/100.0*100, v.completed_pourcent + assert_progress_equal 25.0/100.0*100, v.closed_pourcent + end + + private + + def add_issue(version, attributes={}) + Issue.create!({:project => version.project, + :fixed_version => version, + :subject => 'Test', + :author => User.find(:first), + :tracker => version.project.trackers.find(:first)}.merge(attributes)) + end + + def assert_progress_equal(expected_float, actual_float, message="") + assert_in_delta(expected_float, actual_float, 0.000001, message="") + end end |