From 003d3a7a9d893e4a292101fb079ec133af50ce28 Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 14 Apr 2025 13:10:14 +0000 Subject: [PATCH 01/15] Implement array flattening function with recursive approach --- src/array_flattener.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/array_flattener.py diff --git a/src/array_flattener.py b/src/array_flattener.py new file mode 100644 index 00000000..679031d6 --- /dev/null +++ b/src/array_flattener.py @@ -0,0 +1,37 @@ +def flatten_array(arr): + """ + Flatten a nested array of arbitrary depth into a single-level array. + + Args: + arr (list): A nested list that may contain sublists. + + Returns: + list: A flattened version of the input list. + + Raises: + TypeError: If the input is not a list or contains non-list/non-numeric elements. + """ + # Validate input is a list + if not isinstance(arr, list): + raise TypeError("Input must be a list") + + # Result to store flattened array + flattened = [] + + # Recursive helper function to flatten the array + def _recursive_flatten(element): + # If element is a list, recursively flatten it + if isinstance(element, list): + for sub_element in element: + _recursive_flatten(sub_element) + # If element is a number (int or float), append to flattened list + elif isinstance(element, (int, float)): + flattened.append(element) + # Raise error for non-numeric, non-list elements + else: + raise TypeError(f"Invalid element type: {type(element)}") + + # Start the recursive flattening + _recursive_flatten(arr) + + return flattened \ No newline at end of file From 1a2b81734bc142cfded86c3519a179c2632c4fe0 Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 14 Apr 2025 13:10:33 +0000 Subject: [PATCH 02/15] Add comprehensive tests for array flattening function --- tests/test_array_flattener.py | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_array_flattener.py diff --git a/tests/test_array_flattener.py b/tests/test_array_flattener.py new file mode 100644 index 00000000..a530d4c1 --- /dev/null +++ b/tests/test_array_flattener.py @@ -0,0 +1,40 @@ +import pytest +from src.array_flattener import flatten_array + +def test_flatten_simple_list(): + """Test flattening a simple list""" + assert flatten_array([1, 2, 3]) == [1, 2, 3] + +def test_flatten_nested_list(): + """Test flattening a nested list""" + assert flatten_array([1, [2, 3], 4]) == [1, 2, 3, 4] + +def test_flatten_deeply_nested_list(): + """Test flattening a deeply nested list""" + assert flatten_array([1, [2, [3, 4]], 5]) == [1, 2, 3, 4, 5] + +def test_flatten_multiple_nested_levels(): + """Test flattening list with multiple nesting levels""" + assert flatten_array([1, [2, [3, [4]]], 5]) == [1, 2, 3, 4, 5] + +def test_flatten_mixed_nesting(): + """Test flattening list with mixed nesting patterns""" + assert flatten_array([1, [2, 3], [4, [5, 6]]]) == [1, 2, 3, 4, 5, 6] + +def test_flatten_empty_list(): + """Test flattening an empty list""" + assert flatten_array([]) == [] + +def test_invalid_input_type(): + """Test that non-list inputs raise a TypeError""" + with pytest.raises(TypeError): + flatten_array("not a list") + +def test_invalid_element_type(): + """Test that lists with non-numeric, non-list elements raise a TypeError""" + with pytest.raises(TypeError): + flatten_array([1, 2, "string"]) + +def test_float_support(): + """Test that float values are supported""" + assert flatten_array([1.5, [2.7, 3], 4.2]) == [1.5, 2.7, 3, 4.2] \ No newline at end of file From 0ef59908f8b2ae8ec22ce700069b223b44ca031f Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 13:15:24 +0000 Subject: [PATCH 03/15] Implement URL parser function --- src/url_parser.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/url_parser.py diff --git a/src/url_parser.py b/src/url_parser.py new file mode 100644 index 00000000..637b4e10 --- /dev/null +++ b/src/url_parser.py @@ -0,0 +1,43 @@ +from urllib.parse import urlparse +from typing import Dict, Any, Optional + +def parse_url(url: str) -> Dict[str, Optional[str]]: + """ + Parse a given URL into its components. + + Args: + url (str): The URL to parse. + + Returns: + Dict[str, Optional[str]]: A dictionary containing URL components. + + Raises: + ValueError: If the input is not a valid URL. + """ + # Validate input + if not isinstance(url, str): + raise ValueError("Input must be a string") + + if not url.strip(): + raise ValueError("URL cannot be empty") + + try: + # Use urlparse to break down the URL + parsed_url = urlparse(url) + + # Return a comprehensive dictionary of URL components + return { + 'scheme': parsed_url.scheme or None, + 'netloc': parsed_url.netloc or None, + 'path': parsed_url.path or None, + 'params': parsed_url.params or None, + 'query': parsed_url.query or None, + 'fragment': parsed_url.fragment or None, + 'username': parsed_url.username or None, + 'password': parsed_url.password or None, + 'hostname': parsed_url.hostname or None, + 'port': parsed_url.port or None + } + except Exception: + # Catch any unexpected parsing errors + raise ValueError(f"Invalid URL format: {url}") \ No newline at end of file From 46d64378b28f003ffcd3df5510cee246a80c0467 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 13:15:59 +0000 Subject: [PATCH 04/15] Add comprehensive tests for URL parser function --- tests/test_url_parser.py | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/test_url_parser.py diff --git a/tests/test_url_parser.py b/tests/test_url_parser.py new file mode 100644 index 00000000..76e9f4eb --- /dev/null +++ b/tests/test_url_parser.py @@ -0,0 +1,70 @@ +import pytest +from src.url_parser import parse_url + +def test_full_url(): + """Test parsing a complete URL with all components.""" + url = "https://username:password@example.com:8080/path/to/page?query=value#fragment" + result = parse_url(url) + + assert result == { + 'scheme': 'https', + 'netloc': 'username:password@example.com:8080', + 'path': '/path/to/page', + 'params': '', + 'query': 'query=value', + 'fragment': 'fragment', + 'username': 'username', + 'password': 'password', + 'hostname': 'example.com', + 'port': 8080 + } + +def test_minimal_url(): + """Test parsing a minimal URL.""" + url = "https://example.com" + result = parse_url(url) + + assert result['scheme'] == 'https' + assert result['netloc'] == 'example.com' + assert result['path'] is None + assert result['query'] is None + assert result['fragment'] is None + +def test_url_with_path(): + """Test URL with path.""" + url = "http://example.com/path/to/resource" + result = parse_url(url) + + assert result['scheme'] == 'http' + assert result['path'] == '/path/to/resource' + +def test_url_with_query(): + """Test URL with query parameters.""" + url = "https://example.com/search?q=python&category=programming" + result = parse_url(url) + + assert result['query'] == 'q=python&category=programming' + +def test_url_with_fragment(): + """Test URL with fragment.""" + url = "https://example.com/page#section" + result = parse_url(url) + + assert result['fragment'] == 'section' + +def test_invalid_input_type(): + """Test that non-string input raises a ValueError.""" + with pytest.raises(ValueError, match="Input must be a string"): + parse_url(123) + +def test_empty_url(): + """Test that empty URL raises a ValueError.""" + with pytest.raises(ValueError, match="URL cannot be empty"): + parse_url("") + with pytest.raises(ValueError, match="URL cannot be empty"): + parse_url(" ") + +def test_invalid_url(): + """Test that malformed URL raises a ValueError.""" + with pytest.raises(ValueError, match="Invalid URL format"): + parse_url("not a valid url") \ No newline at end of file From 40c5e435d60ee98e2dd935045481a96e1b056954 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 13:16:32 +0000 Subject: [PATCH 05/15] Modify URL parser to handle params and invalid URLs --- src/url_parser.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/url_parser.py b/src/url_parser.py index 637b4e10..8cb506da 100644 --- a/src/url_parser.py +++ b/src/url_parser.py @@ -30,7 +30,7 @@ def parse_url(url: str) -> Dict[str, Optional[str]]: 'scheme': parsed_url.scheme or None, 'netloc': parsed_url.netloc or None, 'path': parsed_url.path or None, - 'params': parsed_url.params or None, + 'params': parsed_url.params or '', # Change to empty string instead of None 'query': parsed_url.query or None, 'fragment': parsed_url.fragment or None, 'username': parsed_url.username or None, @@ -39,5 +39,7 @@ def parse_url(url: str) -> Dict[str, Optional[str]]: 'port': parsed_url.port or None } except Exception: - # Catch any unexpected parsing errors - raise ValueError(f"Invalid URL format: {url}") \ No newline at end of file + # Check for basic URL format + if '.' not in url or not url.startswith(('http://', 'https://', 'ftp://')): + raise ValueError(f"Invalid URL format: {url}") + raise \ No newline at end of file From a64a4e5f37afde592b6431485d3a48e3727436e1 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 13:16:51 +0000 Subject: [PATCH 06/15] Enhance URL validation with regex and stricter checks --- src/url_parser.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/url_parser.py b/src/url_parser.py index 8cb506da..ec4c6701 100644 --- a/src/url_parser.py +++ b/src/url_parser.py @@ -1,5 +1,6 @@ from urllib.parse import urlparse from typing import Dict, Any, Optional +import re def parse_url(url: str) -> Dict[str, Optional[str]]: """ @@ -21,6 +22,18 @@ def parse_url(url: str) -> Dict[str, Optional[str]]: if not url.strip(): raise ValueError("URL cannot be empty") + # Add more strict URL validation + url_regex = re.compile( + r'^(?:http|ftp)s?://' # http:// or https:// or ftp:// or ftps:// + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... + r'localhost|' # localhost... + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip + r'(?::\d+)?' # optional port + r'(?:/?|[/?]\S+)$', re.IGNORECASE) + + if not url_regex.match(url): + raise ValueError(f"Invalid URL format: {url}") + try: # Use urlparse to break down the URL parsed_url = urlparse(url) @@ -39,7 +52,4 @@ def parse_url(url: str) -> Dict[str, Optional[str]]: 'port': parsed_url.port or None } except Exception: - # Check for basic URL format - if '.' not in url or not url.startswith(('http://', 'https://', 'ftp://')): - raise ValueError(f"Invalid URL format: {url}") - raise \ No newline at end of file + raise ValueError(f"Invalid URL format: {url}") \ No newline at end of file From 05326889838e87c0a5a5382d64066e27d7084700 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 13:17:20 +0000 Subject: [PATCH 07/15] Simplify URL validation to use urlparse checks --- src/url_parser.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/url_parser.py b/src/url_parser.py index ec4c6701..fc8235f7 100644 --- a/src/url_parser.py +++ b/src/url_parser.py @@ -22,22 +22,14 @@ def parse_url(url: str) -> Dict[str, Optional[str]]: if not url.strip(): raise ValueError("URL cannot be empty") - # Add more strict URL validation - url_regex = re.compile( - r'^(?:http|ftp)s?://' # http:// or https:// or ftp:// or ftps:// - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... - r'localhost|' # localhost... - r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip - r'(?::\d+)?' # optional port - r'(?:/?|[/?]\S+)$', re.IGNORECASE) - - if not url_regex.match(url): - raise ValueError(f"Invalid URL format: {url}") - try: # Use urlparse to break down the URL parsed_url = urlparse(url) + # Basic validation + if not parsed_url.scheme or not parsed_url.netloc: + raise ValueError(f"Invalid URL format: {url}") + # Return a comprehensive dictionary of URL components return { 'scheme': parsed_url.scheme or None, From bdeb53868a4cf3fbefc8285b89319a032fe7b187 Mon Sep 17 00:00:00 2001 From: momstrosity Date: Mon, 14 Apr 2025 13:36:11 +0000 Subject: [PATCH 08/15] Add string reversal function implementation --- src/string_reversal.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/string_reversal.py diff --git a/src/string_reversal.py b/src/string_reversal.py new file mode 100644 index 00000000..fa0e8063 --- /dev/null +++ b/src/string_reversal.py @@ -0,0 +1,19 @@ +def reverse_string(s): + """ + Reverse the given string. + + Args: + s (str): The input string to be reversed. + + Returns: + str: The reversed string. + + Raises: + TypeError: If the input is not a string. + """ + # Check if input is a string + if not isinstance(s, str): + raise TypeError("Input must be a string") + + # Return the reversed string + return s[::-1] \ No newline at end of file From 8746c37fe85b84c09272df71b428a1500560348e Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 14 Apr 2025 13:36:27 +0000 Subject: [PATCH 09/15] Implement binary search function with comprehensive error handling --- src/binary_search.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/binary_search.py diff --git a/src/binary_search.py b/src/binary_search.py new file mode 100644 index 00000000..436347a0 --- /dev/null +++ b/src/binary_search.py @@ -0,0 +1,45 @@ +def binary_search(arr, target): + """ + Perform binary search on a sorted array to find the target element. + + Args: + arr (list): A sorted list of comparable elements + target: The element to search for + + Returns: + int: Index of the target element if found, otherwise -1 + + Raises: + TypeError: If input is not a list + ValueError: If the list is not sorted + """ + # Check input type + if not isinstance(arr, list): + raise TypeError("Input must be a list") + + # Check if list is sorted + if arr != sorted(arr): + raise ValueError("Input list must be sorted in ascending order") + + # Handle empty list + if not arr: + return -1 + + # Perform binary search + left, right = 0, len(arr) - 1 + + while left <= right: + mid = (left + right) // 2 + + # Check if target is found + if arr[mid] == target: + return mid + + # Adjust search boundaries + if arr[mid] < target: + left = mid + 1 + else: + right = mid - 1 + + # Target not found + return -1 \ No newline at end of file From 8c49f419de7f7dcedd56faedcbccc9af9d68647d Mon Sep 17 00:00:00 2001 From: momstrosity Date: Mon, 14 Apr 2025 13:36:29 +0000 Subject: [PATCH 10/15] Add comprehensive tests for string reversal function --- tests/test_string_reversal.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/test_string_reversal.py diff --git a/tests/test_string_reversal.py b/tests/test_string_reversal.py new file mode 100644 index 00000000..48c0a988 --- /dev/null +++ b/tests/test_string_reversal.py @@ -0,0 +1,33 @@ +import pytest +from src.string_reversal import reverse_string + +def test_reverse_string_normal(): + """Test reversing a normal string.""" + assert reverse_string("hello") == "olleh" + +def test_reverse_string_empty(): + """Test reversing an empty string.""" + assert reverse_string("") == "" + +def test_reverse_string_single_char(): + """Test reversing a single character string.""" + assert reverse_string("a") == "a" + +def test_reverse_string_with_spaces(): + """Test reversing a string with spaces.""" + assert reverse_string("hello world") == "dlrow olleh" + +def test_reverse_string_with_special_chars(): + """Test reversing a string with special characters.""" + assert reverse_string("a1b2c3!@#") == "#@!3c2b1a" + +def test_reverse_string_invalid_input(): + """Test that a TypeError is raised for non-string inputs.""" + with pytest.raises(TypeError, match="Input must be a string"): + reverse_string(123) + + with pytest.raises(TypeError, match="Input must be a string"): + reverse_string(None) + + with pytest.raises(TypeError, match="Input must be a string"): + reverse_string(["hello"]) \ No newline at end of file From 5b72103fe972bfe2ab9f413913c321fc6e0c12bb Mon Sep 17 00:00:00 2001 From: labrocadabro Date: Mon, 14 Apr 2025 13:36:38 +0000 Subject: [PATCH 11/15] Add comprehensive tests for binary search function --- tests/test_binary_search.py | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test_binary_search.py diff --git a/tests/test_binary_search.py b/tests/test_binary_search.py new file mode 100644 index 00000000..50187e39 --- /dev/null +++ b/tests/test_binary_search.py @@ -0,0 +1,41 @@ +import pytest +from src.binary_search import binary_search + +def test_binary_search_found(): + """Test finding an existing element in the list""" + assert binary_search([1, 2, 3, 4, 5], 3) == 2 + assert binary_search([1, 2, 3, 4, 5], 1) == 0 + assert binary_search([1, 2, 3, 4, 5], 5) == 4 + +def test_binary_search_not_found(): + """Test searching for a non-existent element""" + assert binary_search([1, 2, 3, 4, 5], 6) == -1 + assert binary_search([1, 2, 3, 4, 5], 0) == -1 + +def test_binary_search_empty_list(): + """Test searching in an empty list""" + assert binary_search([], 5) == -1 + +def test_binary_search_single_element(): + """Test searching in a single-element list""" + assert binary_search([1], 1) == 0 + assert binary_search([1], 2) == -1 + +def test_binary_search_unsorted_list(): + """Test that an unsorted list raises a ValueError""" + with pytest.raises(ValueError): + binary_search([5, 2, 1, 4, 3], 3) + +def test_binary_search_invalid_input(): + """Test that non-list inputs raise a TypeError""" + with pytest.raises(TypeError): + binary_search("not a list", 3) + with pytest.raises(TypeError): + binary_search(None, 3) + +def test_binary_search_large_list(): + """Test binary search on a larger sorted list""" + large_list = list(range(1000)) + assert binary_search(large_list, 500) == 500 + assert binary_search(large_list, 999) == 999 + assert binary_search(large_list, 1000) == -1 \ No newline at end of file From 17595f6a3af2cde26f3b2bcb2397c5d6e4f80faf Mon Sep 17 00:00:00 2001 From: momstrosity Date: Mon, 14 Apr 2025 13:37:39 +0000 Subject: [PATCH 12/15] Implement string reversal using manual two-pointer approach --- src/string_reversal.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/string_reversal.py b/src/string_reversal.py index fa0e8063..10cb6f00 100644 --- a/src/string_reversal.py +++ b/src/string_reversal.py @@ -1,6 +1,6 @@ def reverse_string(s): """ - Reverse the given string. + Reverse the given string using a manual approach. Args: s (str): The input string to be reversed. @@ -15,5 +15,17 @@ def reverse_string(s): if not isinstance(s, str): raise TypeError("Input must be a string") - # Return the reversed string - return s[::-1] \ No newline at end of file + # Convert string to list of characters to enable manual manipulation + chars = list(s) + + # Manual reversal using two-pointer technique + left, right = 0, len(chars) - 1 + while left < right: + # Swap characters + chars[left], chars[right] = chars[right], chars[left] + # Move pointers + left += 1 + right -= 1 + + # Convert back to string and return + return ''.join(chars) \ No newline at end of file From 38d4fc341bb7bbfd60d53cd27bd271870b8438ba Mon Sep 17 00:00:00 2001 From: momstrosity Date: Mon, 14 Apr 2025 13:37:49 +0000 Subject: [PATCH 13/15] Update tests for string reversal function --- tests/test_string_reversal.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_string_reversal.py b/tests/test_string_reversal.py index 48c0a988..9187901d 100644 --- a/tests/test_string_reversal.py +++ b/tests/test_string_reversal.py @@ -21,6 +21,10 @@ def test_reverse_string_with_special_chars(): """Test reversing a string with special characters.""" assert reverse_string("a1b2c3!@#") == "#@!3c2b1a" +def test_reverse_string_with_mixed_chars(): + """Test reversing a string with mixed character types.""" + assert reverse_string("Hello, World! 123") == "321 !dlroW ,olleH" + def test_reverse_string_invalid_input(): """Test that a TypeError is raised for non-string inputs.""" with pytest.raises(TypeError, match="Input must be a string"): From bf106d528fe5049a30012a1a1427b9ae60c1c804 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 14:12:39 +0000 Subject: [PATCH 14/15] Implement RGB to Hex converter function --- src/rgb_to_hex.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/rgb_to_hex.py diff --git a/src/rgb_to_hex.py b/src/rgb_to_hex.py new file mode 100644 index 00000000..658486f7 --- /dev/null +++ b/src/rgb_to_hex.py @@ -0,0 +1,26 @@ +def rgb_to_hex(r, g, b): + """ + Convert RGB color values to a hexadecimal color code. + + Args: + r (int): Red color value (0-255) + g (int): Green color value (0-255) + b (int): Blue color value (0-255) + + Returns: + str: Hexadecimal color code (e.g., '#FF0000' for red) + + Raises: + ValueError: If any color value is not in the range 0-255 + """ + # Validate input ranges + for color, name in [(r, 'Red'), (g, 'Green'), (b, 'Blue')]: + if not isinstance(color, int): + raise TypeError(f"{name} value must be an integer") + if color < 0 or color > 255: + raise ValueError(f"{name} value must be between 0 and 255") + + # Convert to hex, removing '0x' prefix and zero-padding to 2 digits + hex_color = '#{:02X}{:02X}{:02X}'.format(r, g, b) + + return hex_color \ No newline at end of file From 462822c32a1782adccbee64ab103b0c8d390b1a5 Mon Sep 17 00:00:00 2001 From: laura-abro Date: Mon, 14 Apr 2025 14:13:09 +0000 Subject: [PATCH 15/15] Add comprehensive tests for RGB to Hex converter --- tests/test_rgb_to_hex.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_rgb_to_hex.py diff --git a/tests/test_rgb_to_hex.py b/tests/test_rgb_to_hex.py new file mode 100644 index 00000000..f9457c4a --- /dev/null +++ b/tests/test_rgb_to_hex.py @@ -0,0 +1,37 @@ +import pytest +from src.rgb_to_hex import rgb_to_hex + +def test_basic_conversion(): + """Test basic RGB to Hex conversion""" + assert rgb_to_hex(255, 0, 0) == '#FF0000' # Red + assert rgb_to_hex(0, 255, 0) == '#00FF00' # Green + assert rgb_to_hex(0, 0, 255) == '#0000FF' # Blue + assert rgb_to_hex(128, 128, 128) == '#808080' # Gray + +def test_edge_cases(): + """Test edge case values""" + assert rgb_to_hex(0, 0, 0) == '#000000' # Black + assert rgb_to_hex(255, 255, 255) == '#FFFFFF' # White + +def test_invalid_inputs(): + """Test error handling for invalid inputs""" + # Out of range values + with pytest.raises(ValueError, match="Red value must be between 0 and 255"): + rgb_to_hex(-1, 0, 0) + + with pytest.raises(ValueError, match="Green value must be between 0 and 255"): + rgb_to_hex(0, 256, 0) + + with pytest.raises(ValueError, match="Blue value must be between 0 and 255"): + rgb_to_hex(0, 0, 300) + +def test_type_errors(): + """Test type checking for inputs""" + with pytest.raises(TypeError, match="Red value must be an integer"): + rgb_to_hex('255', 0, 0) + + with pytest.raises(TypeError, match="Green value must be an integer"): + rgb_to_hex(0, '255', 0) + + with pytest.raises(TypeError, match="Blue value must be an integer"): + rgb_to_hex(0, 0, '255') \ No newline at end of file