Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Condition to determine if a test run has passed might be wrong #2760

Open
seemantTUI opened this issue Jan 31, 2025 · 0 comments
Open

Condition to determine if a test run has passed might be wrong #2760

seemantTUI opened this issue Jan 31, 2025 · 0 comments

Comments

@seemantTUI
Copy link

seemantTUI commented Jan 31, 2025

Hello,

def score_file(output, file, requesting_user)
      assessor = Assessor.new(execution_environment:)
      assessment = assessor.assess(output)
      passed = (assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?

In the above code the line:
passed = (assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?

passed will always have the value returned from (assessment[:passed] == assessment[:count]) the evaluation of the second condition will not impact the value of passed variable. Although it works in all the cases but might be wrong for the case when the test files have their own error and are not executed properly. In that case assessment[:passed] = 0 and assessment[:count] = 0 therefore the condition assessment[:passed] == assessment[:count] is true whereas assessment[:score].positive? is 0.0 hence false. But passed will be set to true because the condition assessment[:passed] == assessment[:count] is true as precedence of "=" is more than "and" operator so the possible fixes could be

  passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?)

or

  passed = (assessment[:passed] == assessment[:count]) && (assessment[:score]).positive?

In all other situations I dont think there can be a case where assessment[:passed] == assessment[:count] is false and assessment[:score]).positive? is true. I only found this bug when my test cases had syntax errors and where not executed.

Best Regards,
Seemant Singh

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant