diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..7b13da7 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,30 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python Test + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: checkout code + uses: actions/checkout@v4 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + - name: Run tests + run: | + python -m unittest test.py + diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..6e9e742 Binary files /dev/null and b/__pycache__/main.cpython-312.pyc differ diff --git a/main.py b/main.py index 52a7635..000dd3a 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,20 @@ - +def fizzbuzz(num): + if num%3 == 0 and num % 5 == 0: + return "fizzbuzz" + elif num%3 == 0: + return "fizz" + elif num % 5 == 0: + return "buzz" + else: + return str(num) + def main(): - print('Hello, World!') - return 0 - -if __name__ == '__main__': - main() - + for i in range(1, 101): + if i%3 == 0 and i % 5 == 0: + return "fizzbuzz" + elif i%3 == 0: + return "fizz" + elif i % 5 == 0: + return "buzz" + else: + return str(i) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..e73c264 --- /dev/null +++ b/test.py @@ -0,0 +1,19 @@ +import unittest; +from main import fizzbuzz; + +class TestFizzbuzz(unittest.TestCase): + def test_isFizz(self): + fizzbuzz(3) + self.assertEqual(fizzbuzz(3), "fizz") + def test_isBuzz(self): + fizzbuzz(5) + self.assertEqual(fizzbuzz(5), "buzz") + def test_isFizzbuzz(self): + fizzbuzz(15) + self.assertEqual(fizzbuzz(15), "fizz") + def test_isNumber(self): + fizzbuzz(1) + self.assertEqual(fizzbuzz(1), "1") + +if __name__ == '__main__': + unittest.main()