-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
6 changed files
with
71 additions
and
22 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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
name: Test py file | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
hello: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
|
||
- run: python square.py |
Binary file not shown.
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,5 @@ | ||
#!/bin/bash | ||
|
||
git add . | ||
git commit -m "some changes" | ||
git push -f origin master |
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,49 @@ | ||
def square_number(number: float) -> float: | ||
""" | ||
Squares a number (second degree). | ||
Args: | ||
number (float): The number to square | ||
Returns: | ||
Float: The result of squaring | ||
Raises: | ||
TypeError: If the input parameter is not a number | ||
""" | ||
if not isinstance(number, (int, float)): | ||
raise TypeError("The input parameter must be a number") | ||
return number ** 2 | ||
|
||
import unittest | ||
|
||
class TestSquareNumber(unittest.TestCase): | ||
def test_positive_numbers(self): | ||
self.assertEqual(square_number(2), 4) | ||
self.assertEqual(square_number(5), 25) | ||
self.assertEqual(square_number(10), 100) | ||
|
||
def test_negative_numbers(self): | ||
self.assertEqual(square_number(-2), 4) | ||
self.assertEqual(square_number(-5), 25) | ||
|
||
def test_zero(self): | ||
self.assertEqual(square_number(0), 0) | ||
|
||
def test_float_numbers(self): | ||
self.assertAlmostEqual(square_number(1.5), 2.25) | ||
self.assertAlmostEqual(square_number(-1.5), 2.25) | ||
|
||
def test_invalid_types(self): | ||
# Check that the function calls TypeError for invalid types | ||
with self.assertRaises(TypeError): | ||
square_number("2") | ||
with self.assertRaises(TypeError): | ||
square_number([1, 2, 3]) | ||
with self.assertRaises(TypeError): | ||
square_number(None) | ||
with self.assertRaises(TypeError): | ||
square_number({"number": 2}) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |