From 1a6ae9813861e659805f755d27f8cdec80ffe054 Mon Sep 17 00:00:00 2001 From: Matt Uebel Date: Tue, 22 Oct 2024 16:07:10 -0400 Subject: [PATCH] Add tests and continuous integration Add unit tests and CI workflow for the repository. * **Unit Tests** - Add `tests/test_example1.py` with unit tests for `add`, `subtract`, `multiply`, and `divide` functions, including edge cases like division by zero. - Add `tests/test_example2.py` with unit tests for `greet` and `farewell` functions, including tests for different names. * **CI Workflow** - Add `.github/workflows/ci.yml` to set up GitHub Actions workflow to run tests on each commit. - Use Python 3.8 for the testing environment. - Install dependencies and run tests using `pytest`. * **README.md** - Add a badge to show the build status of the repository. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/MattUebel/copilot-presentation?shareId=XXXX-XXXX-XXXX-XXXX). --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ README.md | 2 ++ tests/test_example1.py | 25 +++++++++++++++++++++++++ tests/test_example2.py | 17 +++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/test_example1.py create mode 100644 tests/test_example2.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8e66aba --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + - name: Run tests + run: | + pytest diff --git a/README.md b/README.md index b6a0f98..8192178 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # GitHub Copilot: Your AI-Powered Coding Partner +[![Build Status](https://github.com/MattUebel/copilot-presentation/actions/workflows/ci.yml/badge.svg)](https://github.com/MattUebel/copilot-presentation/actions) + Welcome to the staging area for materials related to the talk, **"GitHub Copilot: Your AI-Powered Coding Partner."** This repository serves as a central hub for content, resources, and links that will help you understand and utilize GitHub Copilot in your coding workflows. ## Overview diff --git a/tests/test_example1.py b/tests/test_example1.py new file mode 100644 index 0000000..7d6a16c --- /dev/null +++ b/tests/test_example1.py @@ -0,0 +1,25 @@ +import pytest +from presentation.examples.example1 import add, subtract, multiply, divide + +def test_add(): + assert add(2, 3) == 5 + assert add(-1, 1) == 0 + assert add(0, 0) == 0 + +def test_subtract(): + assert subtract(5, 3) == 2 + assert subtract(0, 1) == -1 + assert subtract(-1, -1) == 0 + +def test_multiply(): + assert multiply(2, 3) == 6 + assert multiply(-1, 1) == -1 + assert multiply(0, 100) == 0 + +def test_divide(): + assert divide(6, 3) == 2 + assert divide(-4, 2) == -2 + assert divide(5, 2) == 2.5 + + with pytest.raises(ValueError): + divide(10, 0) diff --git a/tests/test_example2.py b/tests/test_example2.py new file mode 100644 index 0000000..4ee9c11 --- /dev/null +++ b/tests/test_example2.py @@ -0,0 +1,17 @@ +import unittest +from presentation.examples.example2 import greet, farewell + +class TestExample2(unittest.TestCase): + + def test_greet(self): + self.assertEqual(greet("Alice"), "Hello, Alice!") + self.assertEqual(greet("Bob"), "Hello, Bob!") + self.assertEqual(greet(""), "Hello, !") + + def test_farewell(self): + self.assertEqual(farewell("Alice"), "Goodbye, Alice!") + self.assertEqual(farewell("Bob"), "Goodbye, Bob!") + self.assertEqual(farewell(""), "Goodbye, !") + +if __name__ == '__main__': + unittest.main()