OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Better check of progress values consistency
Christophe Bliarde22e3aeb483e
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rbindex 10474fd0aee..501a38ef005 100644--- a/app/contracts/work_packages/base_contract.rb+++ b/app/contracts/work_packages/base_contract.rb@@ -32,6 +32,7 @@ module WorkPackagesclass BaseContract < ::ModelContractinclude ::Attachments::ValidateReplacementsinclude AssignableValuesContract+ include WorkPackages::SetAttributesService::ProgressValuesCalculationsattribute :subjectattribute :description@@ -399,7 +400,7 @@ module WorkPackagesdef validate_percent_complete_matches_work_and_remaining_workreturn if percent_complete_derivation_unapplicable?- if !percent_complete_range_derived_from_work_and_remaining_work.cover?(percent_complete)+ if !consistent_progress_values?(work:, remaining_work:, percent_complete:)errors.add(:done_ratio, :does_not_match_work_and_remaining_work)endend@@ -481,15 +482,6 @@ module WorkPackageswork == 0 || percent_complete == 100 # only applicable if not in special cases leading to divisions by zeroend- def percent_complete_range_derived_from_work_and_remaining_work- work_done = work - remaining_work- percentage = (100 * work_done.to_f / work)-- lower_bound = percentage.truncate- upper_bound = lower_bound + 1- lower_bound..upper_bound- end-def validate_no_reopen_on_closed_versionif model.version_id && model.reopened? && model.version.closed?errors.add :base, I18n.t(:error_can_not_reopen_work_package_on_closed_version)diff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_base.rbindex 00cc376283f..45dd47e4e64 100644--- a/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb@@ -30,6 +30,8 @@class WorkPackages::SetAttributesServiceclass DeriveProgressValuesBase+ include WorkPackages::SetAttributesService::ProgressValuesCalculations+attr_reader :work_packagedef initialize(work_package)@@ -177,11 +179,5 @@ class WorkPackages::SetAttributesServiceself.remaining_work = roundedendend-- def remaining_work_from_percent_complete_and_work- completed_work = work * percent_complete / 100.0- remaining_work = (work - completed_work).round(2)- remaining_work.clamp(0.0, work)- endendenddiff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_status_based.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_status_based.rbindex fcc7d7ea8b9..8b4d87bacf4 100644--- a/app/services/work_packages/set_attributes_service/derive_progress_values_status_based.rb+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_status_based.rb@@ -76,7 +76,7 @@ class WorkPackages::SetAttributesServiceself.remaining_work = nilelseset_hint(:remaining_hours, :derived)- self.remaining_work = remaining_work_from_percent_complete_and_work+ self.remaining_work = calculate_remaining_work(work:, percent_complete:)endendenddiff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rbindex d4c369152e9..fb958aecaf8 100644--- a/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb@@ -100,7 +100,7 @@ class WorkPackages::SetAttributesServiceself.work = remaining_workelseset_hint(:estimated_hours, :derived)- self.work = work_from_percent_complete_and_remaining_work+ self.work = calculate_work(remaining_work:, percent_complete:)skip_percent_complete_derivation!endend@@ -130,7 +130,7 @@ class WorkPackages::SetAttributesServiceself.remaining_work = nilelseset_hint(:remaining_hours, :derived)- self.remaining_work = remaining_work_from_percent_complete_and_work+ self.remaining_work = calculate_remaining_work(work:, percent_complete:)skip_percent_complete_derivation!endend@@ -147,7 +147,7 @@ class WorkPackages::SetAttributesServiceself.percent_complete = nilelseset_hint(:done_ratio, :derived)- self.percent_complete = percent_complete_from_work_and_remaining_work+ self.percent_complete = calculate_percent_complete(work:, remaining_work:)endend@@ -155,27 +155,6 @@ class WorkPackages::SetAttributesServiceself.skip_percent_complete_derivation = trueend- def percent_complete_from_work_and_remaining_work- rounded_work = work.round(2)- rounded_remaining_work = remaining_work.round(2)- completed_work = rounded_work - rounded_remaining_work- completion_ratio = completed_work.to_f / rounded_work-- percentage = (completion_ratio * 100)- case percentage- in 0 then 0- in 0..1 then 1- in 99...100 then 99- else- percentage.round- end- end-- def work_from_percent_complete_and_remaining_work- remaining_percent_complete = 1.0 - (percent_complete / 100.0)- remaining_work / remaining_percent_complete- end-def percent_complete_unparsable?!PercentageConverter.valid?(work_package.done_ratio_before_type_cast)enddiff --git a/app/services/work_packages/set_attributes_service/progress_values_calculations.rb b/app/services/work_packages/set_attributes_service/progress_values_calculations.rbnew file mode 100644index 00000000000..98663ad0a7f--- /dev/null+++ b/app/services/work_packages/set_attributes_service/progress_values_calculations.rb@@ -0,0 +1,73 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class WorkPackages::SetAttributesService+ module ProgressValuesCalculations+ # Calculate work from remaining work and percent complete without checking for consistency.+ # It returns unexpected results when `percent_complete` is 100.+ def calculate_work(remaining_work:, percent_complete:)+ remaining_percent_complete = 1.0 - (percent_complete / 100.0)+ (remaining_work / remaining_percent_complete).round(2)+ end++ # Calculate remaining work from work and percent complete without checking for consistency.+ def calculate_remaining_work(work:, percent_complete:)+ completed_work = work * percent_complete / 100.0+ remaining_work = (work - completed_work).round(2)+ remaining_work.clamp(0.0, work)+ end++ # Calculate percent complete from work and remaining work without checking for consistency.+ # Raises `FloatDomainError` if work is 0.+ def calculate_percent_complete(work:, remaining_work:)+ # round to 2 decimal places because that's how we store work and remaining+ # work in database+ rounded_work = work.round(2)+ rounded_remaining_work = remaining_work.round(2)+ completed_work = rounded_work - rounded_remaining_work+ completion_ratio = completed_work.to_f / rounded_work++ percentage = (completion_ratio * 100)+ case percentage+ in 0 then 0+ in 0..1 then 1+ in 99...100 then 99+ else+ percentage.round+ end+ end++ def consistent_progress_values?(work:, remaining_work:, percent_complete:)+ # Check if one of provided remaining_work or percent_complete matches the calculated one+ percent_complete == calculate_percent_complete(work:, remaining_work:) \+ || remaining_work == calculate_remaining_work(work:, percent_complete:)+ end+ end+enddiff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rbindex 64e4daa5cee..2c59b16631e 100644--- a/spec/contracts/work_packages/base_contract_spec.rb+++ b/spec/contracts/work_packages/base_contract_spec.rb@@ -651,6 +651,15 @@ RSpec.describe WorkPackages::BaseContract doit_behaves_like "contract is valid"end+ context "with inexact calculated remaining work value - Bug #66592 " \+ "(work = 0.25h, % complete = 75% => remaining work = 0.06h)" do+ let(:estimated_hours) { 0.25 }+ let(:remaining_hours) { 0.06 }+ let(:done_ratio) { 75 }++ it_behaves_like "contract is valid"+ end+context "when all three set with inconsistent values" dolet(:estimated_hours) { 10 }let(:remaining_hours) { 0 }diff --git a/spec/services/work_packages/set_attributes_service/be_consistent_progress_values_matcher.rb b/spec/services/work_packages/set_attributes_service/be_consistent_progress_values_matcher.rbnew file mode 100644index 00000000000..ab2ac077f13--- /dev/null+++ b/spec/services/work_packages/set_attributes_service/be_consistent_progress_values_matcher.rb@@ -0,0 +1,90 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the OpenProject GmbH.+#+# See COPYRIGHT and LICENSE files for more details.+#++++# Custom matcher to check if progress values are consistent using+# WorkPackages::SetAttributesService::ProgressValuesCalculations#consistent_progress_values?+#+# The helper helps at telling the acceptable range of values for the percent+# complete and/or remaining work when it fails.+#+# Usage:+# expect(work: 10, remaining_work: 0, percent_complete: 100).to be_consistent_progress_values+# expect(work: 10, remaining_work: 5, percent_complete: 50).to be_consistent_progress_values+RSpec::Matchers.define :be_consistent_progress_values do+ match do |progress_values|+ work, remaining_work, percent_complete = progress_values.values_at(:work, :remaining_work, :percent_complete)++ # Create a dummy class to access the ProgressValuesCalculations module+ dummy_class = Class.new { extend WorkPackages::SetAttributesService::ProgressValuesCalculations }++ dummy_class.consistent_progress_values?(work:, remaining_work:, percent_complete:)+ end++ failure_message do |progress_values|+ work, remaining_work, percent_complete = progress_values.values_at(:work, :remaining_work, :percent_complete)++ dummy_class = Class.new { extend WorkPackages::SetAttributesService::ProgressValuesCalculations }+ expected_percent_complete = dummy_class.derive_percent_complete(work:, remaining_work:)+ expected_remaining_work = dummy_class.derive_remaining_work(work:, percent_complete:)++ <<~MESSAGE+ expected progress values to be consistent:+ work: #{work}h+ remaining_work: #{remaining_work}h+ percent_complete: #{percent_complete}%++ but they are not consistent+ either derived percent_complete should be #{expected_percent_complete}% with work=#{work}h and remaining_work=#{remaining_work}h+ or derived remaining_work should be #{expected_remaining_work}h with work=#{work}h and percent_complete=#{percent_complete}%+ MESSAGE+ end++ failure_message_when_negated do |progress_values|+ work, remaining_work, percent_complete = progress_values.values_at(:work, :remaining_work, :percent_complete)++ dummy_class = Class.new { extend WorkPackages::SetAttributesService::ProgressValuesCalculations }+ expected_percent_complete = dummy_class.derive_percent_complete(work:, remaining_work:)+ expected_remaining_work = dummy_class.derive_remaining_work(work:, percent_complete:)++ <<~MESSAGE+ expected progress values to NOT be consistent:+ work: #{work}h+ remaining_work: #{remaining_work}h+ percent_complete: #{percent_complete}%++ but they are actually consistent:+ derived percent_complete is #{expected_percent_complete}% with work=#{work}h and remaining_work=#{remaining_work}h+ derived remaining_work is #{expected_remaining_work}h with work=#{work}h and percent_complete=#{percent_complete}%+ MESSAGE+ end++ description do+ "have consistent progress values"+ end+enddiff --git a/spec/services/work_packages/set_attributes_service/progress_values_calculations_spec.rb b/spec/services/work_packages/set_attributes_service/progress_values_calculations_spec.rbnew file mode 100644index 00000000000..cc982064c39--- /dev/null+++ b/spec/services/work_packages/set_attributes_service/progress_values_calculations_spec.rb@@ -0,0 +1,236 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "rails_helper"+require_relative "be_consistent_progress_values_matcher"++RSpec.describe WorkPackages::SetAttributesService::ProgressValuesCalculations do+ let(:dummy_class) { Class.new { extend WorkPackages::SetAttributesService::ProgressValuesCalculations } }++ describe "#calculate_work" do+ it "returns the correct work base on remaining work and % complete" do+ expect(dummy_class.calculate_work(remaining_work: 1, percent_complete: 90)).to eq(10)+ expect(dummy_class.calculate_work(remaining_work: 5, percent_complete: 50)).to eq(10)+ expect(dummy_class.calculate_work(remaining_work: 10, percent_complete: 0)).to eq(10)+ end++ it "rounds the result to 2 decimal places" do+ # 1h remaining, 99% complete => 99.99999999999991h work => 100h+ expect(dummy_class.calculate_work(remaining_work: 1, percent_complete: 99)).to eq(100)+ end++ it "returns same value as remaining work if % complete is 0%" do+ expect(dummy_class.calculate_work(remaining_work: 42, percent_complete: 0)).to eq(42)+ end++ context "when % complete is 100% (no consistency check)" do+ it "returns Infinity if remaining work is positive" do+ expect(dummy_class.calculate_work(remaining_work: 42, percent_complete: 100)).to eq(Float::INFINITY)+ end++ it "returns NaN if remaining work is 0" do+ expect(dummy_class.calculate_work(remaining_work: 0, percent_complete: 100)).to be_nan+ end++ it "returns -Infinity if remaining work is negative" do+ expect(dummy_class.calculate_work(remaining_work: -42, percent_complete: 100)).to eq(-Float::INFINITY)+ end+ end+ end++ describe "#calculate_remaining_work" do+ it "returns the correct remaining work base on work and % complete" do+ expect(dummy_class.calculate_remaining_work(work: 10, percent_complete: 100)).to eq(0)+ expect(dummy_class.calculate_remaining_work(work: 10, percent_complete: 95)).to eq(0.5)+ expect(dummy_class.calculate_remaining_work(work: 10, percent_complete: 50)).to eq(5)+ expect(dummy_class.calculate_remaining_work(work: 10, percent_complete: 0)).to eq(10)+ end++ it "rounds the result to 2 decimal places" do+ # 1.23h, 33% => 0.8240999999999999h => 0.82h+ # it should be 0.8241h but we have floating point precision kicking in, and we have+ # to keep backward compatibility to avoid displaying false validation errors+ expect(dummy_class.calculate_remaining_work(work: 1.23, percent_complete: 33)).to eq(0.82)+ # 1.23h, 67% => 0.4059h => 0.41h+ expect(dummy_class.calculate_remaining_work(work: 1.23, percent_complete: 67)).to eq(0.41)+ end++ it "returns 0h if % complete is 100%" do+ expect(dummy_class.calculate_remaining_work(work: 10, percent_complete: 100)).to eq(0)+ end++ it "returns same value as work if % complete is 0%" do+ expect(dummy_class.calculate_remaining_work(work: 10, percent_complete: 0)).to eq(10)+ end++ it "rounds work value to 2 decimal places before computing remaining work" do+ expect(dummy_class.calculate_remaining_work(work: 0.25499, percent_complete: 75)).to eq(0.06)+ expect(dummy_class.calculate_remaining_work(work: 0.25499, percent_complete: 76)).to eq(0.06)+ expect(dummy_class.calculate_remaining_work(work: 0.25499, percent_complete: 77)).to eq(0.06)+ expect(dummy_class.calculate_remaining_work(work: 0.245, percent_complete: 75)).to eq(0.06)+ expect(dummy_class.calculate_remaining_work(work: 0.245, percent_complete: 76)).to eq(0.06)+ expect(dummy_class.calculate_remaining_work(work: 0.245, percent_complete: 77)).to eq(0.06)+ end+ end++ describe "#calculate_percent_complete" do+ it "returns the correct percent complete" do+ expect(dummy_class.calculate_percent_complete(work: 10, remaining_work: 0)).to eq(100)+ expect(dummy_class.calculate_percent_complete(work: 10, remaining_work: 0.5)).to eq(95)+ expect(dummy_class.calculate_percent_complete(work: 10, remaining_work: 5)).to eq(50)+ expect(dummy_class.calculate_percent_complete(work: 10, remaining_work: 10)).to eq(0)+ end++ it "returns 0% if the work and remaining work are the same" do+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work: 1000)).to eq(0)+ expect(dummy_class.calculate_percent_complete(work: 1, remaining_work: 1)).to eq(0)+ end++ it "returns 1% if the calculated percent complete is above 0% and less than 1% (0.1% is not 0%)" do+ 999.downto(990) do |remaining_work|+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work:)).to eq(1)+ end+ end++ it "rounds the calculated percent complete to nearest integer (12.5 => 13%, 13.4 => 13%)" do+ # 12.4%+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work: 876)).to eq(12)+ # 12.5% to 13.4%+ 875.downto(866) do |remaining_work|+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work:)).to eq(13)+ end+ # 13.5%+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work: 865)).to eq(14)+ end++ it "returns 99% if the calculated percent complete is more than 99% and less than 100% (99.9% is not 100%)" do+ 1.upto(10) do |remaining_work|+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work:)).to eq(99)+ end+ end++ it "returns 100% if remaining work is 0" do+ expect(dummy_class.calculate_percent_complete(work: 1000, remaining_work: 0)).to eq(100)+ expect(dummy_class.calculate_percent_complete(work: 1, remaining_work: 0)).to eq(100)+ end++ it "rounds input values to 2 decimal places before computing percent complete" do+ expect(dummy_class.calculate_percent_complete(work: 0.25, remaining_work: 0.06)).to eq(76)++ # would be 75% if not rounded+ expect(dummy_class.calculate_percent_complete(work: 0.25, remaining_work: 0.0625)).to eq(76)+ # would be 77% if not rounded+ expect(dummy_class.calculate_percent_complete(work: 0.25, remaining_work: 0.0575)).to eq(76)+ # would be 78% if not rounded+ expect(dummy_class.calculate_percent_complete(work: 0.25, remaining_work: 0.055)).to eq(76)+ end++ context "when work is 0 (no consistency check)" do+ it "fails with FloatDomainError because of a division by zero" do+ expect { dummy_class.calculate_percent_complete(work: 0.0, remaining_work: 0.0) }.to raise_error(FloatDomainError)+ end+ end+ end++ describe "#consistent_progress_values?" do+ it "returns true if the progress values are consistent, false otherwise" do+ expect(work: 10, remaining_work: 0, percent_complete: 100).to be_consistent_progress_values+ expect(work: 10, remaining_work: 0.5, percent_complete: 95).to be_consistent_progress_values+ expect(work: 10, remaining_work: 5, percent_complete: 50).to be_consistent_progress_values+ expect(work: 10, remaining_work: 10, percent_complete: 0).to be_consistent_progress_values++ expect(work: 10, remaining_work: 10, percent_complete: 20).not_to be_consistent_progress_values+ expect(work: 10, remaining_work: 0, percent_complete: 42).not_to be_consistent_progress_values+ end++ it "tolerates a range of % complete values when work and remaining work precision " \+ "is too small to get an accurate percent complete value" do+ # nominal case: 0.25h - 0.06h = 0.19h => 76% of 0.25h+ #+ # Remaining work is rounded to 0.06h for all values between 0.0550h and+ # 0.0649h. If user enters values from 75% to 77% while work is 0.25h, then+ # derived remaining work is always 0.06h, so all those % complete values+ # must be considered consistent progress values.+ 75.upto(77) do |percent_complete|+ expect(work: 0.25, remaining_work: 0.06, percent_complete:).to be_consistent_progress_values+ end++ # Due to floating point precision, when 78% is used, remaining work is derived to 0.54999999+ # which is rounded to 0.05h, so 78% would not be considered a consistent progress value.+ expect(work: 0.25, remaining_work: 0.06, percent_complete: 78).not_to be_consistent_progress_values+ # but 78% is consistent with the remaining work of 0.05h+ expect(work: 0.25, remaining_work: 0.05, percent_complete: 78).to be_consistent_progress_values+ end++ it "tolerates a range of remaining work values when work is too large and " \+ "remaining work is high which gives 1% completion" do+ # nominal case: 1000h - 990h = 10h => 1% of 1000h+ #+ # Percent complete is rounded to 1% for all values between 0.00001% and+ # 1.49999%. If user enters remaining work values from 986h and 999.99h, then+ # derived % complete will always be 1%, so all those combinations must be+ # considered consistent progress values.+ 986.upto(999) do |remaining_work|+ expect(work: 1000, remaining_work:, percent_complete: 1).to be_consistent_progress_values+ end++ # tests for remaining work = 999.99h => 1%+ expect(work: 1000, remaining_work: 999.99, percent_complete: 1).to be_consistent_progress_values+ # tests for remaining work = 1000h => 0%+ expect(work: 1000, remaining_work: 1000.0, percent_complete: 1).not_to be_consistent_progress_values+ expect(work: 1000, remaining_work: 1000.0, percent_complete: 0).to be_consistent_progress_values+ # tests for remaining work = 984.99h => 2%+ expect(work: 1000, remaining_work: 984.99, percent_complete: 1).not_to be_consistent_progress_values+ expect(work: 1000, remaining_work: 984.99, percent_complete: 2).to be_consistent_progress_values+ end++ it "tolerates a range of remaining work values when work is too large and " \+ "remaining work is low which gives 99% completion" do+ # nominal case: 1000h - 10h = 990h => 99% of 1000h+ #+ # Percent complete is rounded to 99% for all values between 98.5% and+ # 99.99999%. If user enters remaining work values from 0.1h and 15h, then+ # derived % complete will always be 99%, so all those combinations must be+ # considered consistent progress values.+ 1.upto(15) do |remaining_work|+ expect(work: 1000, remaining_work:, percent_complete: 99).to be_consistent_progress_values+ end++ # tests for remaining work = 0.01h => 99%+ expect(work: 1000, remaining_work: 0.01, percent_complete: 99).to be_consistent_progress_values+ # tests for remaining work = 0h => 100%+ expect(work: 1000, remaining_work: 0.0, percent_complete: 99).not_to be_consistent_progress_values+ expect(work: 1000, remaining_work: 0.0, percent_complete: 100).to be_consistent_progress_values+ # tests for remaining work = 16h => 98%+ expect(work: 1000, remaining_work: 16, percent_complete: 99).not_to be_consistent_progress_values+ expect(work: 1000, remaining_work: 16, percent_complete: 98).to be_consistent_progress_values+ end+ end+end