-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
899a657
commit 40028a8
Showing
2 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
import re | ||
from map2loop.utils import generate_random_hex_colors, hex_to_rgba # Replace 'your_module' with the actual module name | ||
|
||
#does it return the right number of colors? | ||
def test_generate_random_hex_colors_length(): | ||
n = 5 | ||
colors = generate_random_hex_colors(n) | ||
assert len(colors) == n, f"utils function generate_random_hex_colors not returning the right number of hex codes.Expected {n} colors, got {len(colors)}" | ||
|
||
# are the returned hex strings the right format? | ||
def test_generate_random_hex_colors_format(): | ||
n = 10 | ||
hex_pattern = re.compile(r'^#[0-9A-Fa-f]{6}$') | ||
colors = generate_random_hex_colors(n) | ||
for color in colors: | ||
assert hex_pattern.match(color), f"utils function generate_random_hex_colors not returning hex strings in the right format. Got {color} instead." | ||
|
||
# is hex conversion to rgba working as expected? | ||
def test_hex_to_rgba_long_hex(): | ||
hex_color = "#1a2b3c" # long hex versions | ||
expected_output = (0.10196078431372549, 0.16862745098039217, 0.23529411764705882, 1.0) | ||
assert hex_to_rgba(hex_color) == expected_output, f"utils function hex_to_rgba not doing hex to rgba conversion correctly. Expected {expected_output}, got {hex_to_rgba(hex_color)}" | ||
|
||
|
||
def test_hex_to_rgba_short_hex(): | ||
hex_color = "#abc" # short hex versions | ||
expected_output = (0.6666666666666666, 0.7333333333333333, 0.8, 1.0) | ||
assert hex_to_rgba(hex_color) == expected_output | ||
|
||
# does it handle alpha values correctly? | ||
def test_hex_to_rgba_with_alpha(): | ||
hex_color = "#1a2b3c" | ||
alpha = 0.5 | ||
expected_output = (0.10196078431372549, 0.16862745098039217, 0.23529411764705882, alpha) | ||
assert hex_to_rgba(hex_color, alpha) == expected_output, f"utils function hex_to_rgba not handling alpha values correctly. Expected {expected_output}, got {hex_to_rgba(hex_color, alpha)}" | ||
|
||
# does it handle invalid inputs correctly? | ||
def test_hex_to_rgba_invalid_hex(): | ||
with pytest.raises(ValueError): | ||
hex_to_rgba("12FF456"), "utils function hex_to_rgba is expected to raise a ValueError when an invalid hex string is passed, but it did not." |