谁能解释这个程序的输出

san*_*lai -2 testing code-coverage manual manual-testing test-coverage

给定以下代码片段,100% 的决策覆盖率需要多少次测试?

if width > length then 
    biggest_dimension = width 
    if height > width then
        biggest_dimension = height 
    end_if 
else 
    biggest_dimension = length    
    if height > length then 
        biggest_dimension = height    
    end_if    
end_if
Run Code Online (Sandbox Code Playgroud)

上述问题的答案是 4 。100% 决策覆盖需要 4 个测试用例。谁能说出以下问题的答案解释?

DBr*_*oks 5

控制流

I've constructed a control flow for your code to help with the explanation.

It would take 4 tests in order to achieve 100% decision coverage as both "True" and "False" sides of the "IF" statements have to be exercised by the code. The code written has an "IF" statement on each side of the first "IF" statement, requiring 4 different tests in order to reach each decision made.

Example tests:

  • Test 1: Width = 50cm, Length = 40cm, Height = 40cm

  • Test 2: Width = 50cm, Length = 40cm, Height = 60cm

From these two tests, the decision coverage would now be at 50%, as half of the decision outcomes have been exercised (the "True" side of the first "IF").

  • Test 3: Width = 40cm, Length = 50cm, Height = 40cm

  • Test 4: Width = 40cm, Length = 50cm, Height = 60cm

With these two tests, the "False" side of the first "IF" is exercised. This would make the decision coverage 100%.