Skip to content

Commit

Permalink
Replace assert with the difference of values
Browse files Browse the repository at this point in the history
Use math.isclose() to check whether two numbers are considered close. The function already takes into account the absolute values of the given numbers.

The following formula is used to compare the values: abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)

source : https://docs.python.org/3/library/math.html#math.isclose

Conclusion: changes that meet the code review condition
  • Loading branch information
Иван Горбунов committed Jan 21, 2025
1 parent bfb84f7 commit 5827eb7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/test_recog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Module with library tests"""
from pathlib import Path
import pytest
import math
import pygats.recog as rec
import pygats.pygats as pyg
from pygats.formatters import MarkdownFormatter as MD
Expand Down Expand Up @@ -99,4 +100,4 @@ def test_check_text_1(words_for_bg, capsys):
def test_contrast(img_path, expected_value):
img = Image.open(img_path)
contrast = rec.contrast(img)
assert (contrast - expected_value) < 1e-9
assert math.isclose(contrast, expected_value, rel_tol=1e-09, abs_tol=0.0)

0 comments on commit 5827eb7

Please sign in to comment.