Created
March 18, 2023 15:52
-
-
Save TechWithTy/2558c2b3ee0d3bd63780b15d953879ea to your computer and use it in GitHub Desktop.
PYTHON: Demonstrating - Continuous Integration | Continuous Delivery | Continuous Deployment | Big O | Unit Testing | Type Checking
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
# Import necessary modules | |
from typing import List, Optional | |
import pytest | |
# Define a function that finds the maximum value in a list of integers | |
def find_max(numbers: List[int]) -> Optional[int]: | |
if not numbers: | |
return None | |
else: | |
return max(numbers) | |
# Define a function that sorts a list of integers using the bubble sort algorithm | |
def bubble_sort(numbers: List[int]) -> List[int]: | |
n = len(numbers) | |
for i in range(n): | |
for j in range(n-i-1): | |
if numbers[j] > numbers[j+1]: | |
numbers[j], numbers[j+1] = numbers[j+1], numbers[j] | |
return numbers | |
# Define a test function that tests the find_max function | |
def test_find_max(): | |
assert find_max([1, 2, 3]) == 3 | |
assert find_max([-1, -2, -3]) == -1 | |
assert find_max([]) is None | |
# Define a test function that tests the bubble_sort function | |
def test_bubble_sort(): | |
assert bubble_sort([3, 2, 1]) == [1, 2, 3] | |
assert bubble_sort([-3, -2, -1]) == [-3, -2, -1] | |
assert bubble_sort([1, 2, 3]) == [1, 2, 3] | |
# Use continuous integration to automatically run tests whenever code changes are made | |
# This can be achieved using tools like Travis CI or CircleCI | |
# The following line of code can be added to a configuration file, such as .travis.yml or .circleci/config.yml | |
# python -m pytest | |
# Use continuous delivery to automatically deploy code changes to a staging environment | |
# This can be achieved using tools like Docker or Kubernetes | |
# The following line of code can be added to a deployment script, such as deploy.sh | |
# docker build -t myapp . | |
# docker run -d --name myapp-container myapp | |
# Use continuous deployment to automatically deploy code changes to a production environment | |
# This can also be achieved using tools like Docker or Kubernetes | |
# The following line of code can be added to a deployment script, such as deploy.sh | |
# docker push myusername/myapp:latest | |
# kubectl apply -f deployment.yaml | |
# When writing code, make sure to optimize for the best Big O notation | |
# For example, the bubble sort algorithm used in this example has a time complexity of O(n^2), which is not ideal for large lists | |
# Other sorting algorithms, such as quicksort or mergesort, have a better time complexity of O(n log n) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment