Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bit_manipulation/scale_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Scale List Elements
-------------------
This function multiplies every element of the input list by a given factor.
"""


def scale_list(numbers: list, factor: float) -> list:
"""
Scale each number in the list by a given factor.

Args:
numbers (list): List of numbers.
factor (float): The factor to scale each number by.

Returns:
list: Scaled list of numbers.
"""
return [num * factor for num in numbers]


if __name__ == "__main__":
# Example usage
print(scale_list([1, 2, 3], 2)) # Output: [2, 4, 6]
13 changes: 13 additions & 0 deletions bit_manipulation/test_scale_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from bit_manipulation.scale_list import scale_list

Check failure on line 2 in bit_manipulation/test_scale_list.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bit_manipulation/test_scale_list.py:1:1: I001 Import block is un-sorted or un-formatted


class TestScaleList(unittest.TestCase):
def test_scaling(self):
self.assertEqual(scale_list([1, 2, 3], 2), [2, 4, 6])

Check failure on line 7 in bit_manipulation/test_scale_list.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PT009)

bit_manipulation/test_scale_list.py:7:9: PT009 Use a regular `assert` instead of unittest-style `assertEqual`
self.assertEqual(scale_list([-1, -2], 3), [-3, -6])

Check failure on line 8 in bit_manipulation/test_scale_list.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PT009)

bit_manipulation/test_scale_list.py:8:9: PT009 Use a regular `assert` instead of unittest-style `assertEqual`
self.assertEqual(scale_list([0, 1], 0), [0, 0])

Check failure on line 9 in bit_manipulation/test_scale_list.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (PT009)

bit_manipulation/test_scale_list.py:9:9: PT009 Use a regular `assert` instead of unittest-style `assertEqual`


if __name__ == "__main__":
unittest.main()
Loading