Skip to content
Snippets Groups Projects
Brandon Rodriguez's avatar
Brandon Rodriguez authored
804b035c

Python - Operation Counting and Asymptotic Analysis

Description

Python implementation of basic psuedo-code functions.

Psuedo-Code Modifications

  • OddAverage:
    • Line: sum = sum / count
      • Problem: Potential "divide by 0" error.
      • Solution: Add if statement to check for count = 0.
  • CountPositive:
    • No modifications.
  • MakeArrayPositive:
    • No modifications.

Python Environment

This project is tested using Python3.7. Written using PyCharm.

Creating a New Env

Most installations of Python3 will allow you to simply run python3.7 -m venv ./.venv to create a new Python3.7 environment called ".venv" at the current directory folder.

Once created, load this environment with source .venv/bin/activate on Linux or . .venv/Scripts/activate on Windows.

Third Party Libraries

  • If any additional libraries have been used, then they will be found in requrements.txt at the project root.
  • To install, load your local Python Environment and run pip install -r requirements.txt when at the project root.

Running the Program

Run the program via python ./main.py while at the project root.

Expected Output

Minimal output. Project has very little to run from main.py. All functions are run through UnitTests though.

Running Tests

The following are two methods to "run all tests in a given directory". NOTE: For these to work as intended, there needs to be an "init.py" file in each subdirectory of the testing folder.

  • Terminal: From a terminal at the project root, run python -m unittest discover ./tests/ -p "*.py"
  • Pycharm: Create a new unittest configuration with:
    • Target: custom
    • Additional Arguments: discover -s tests -p "*.py" -v
    • Python Interpreter: <your preferred interpreter environment>
    • Working Directory: <project root>

References

Logging Logic

The contents of resources/logging.py (and all associated logic) originally started from me trying to learn how to log information through Django (the Python Web Framework) using a Dictionary type format. (See https://docs.djangoproject.com/en/dev/topics/logging/ for reference).

In 2017, I started expanding and changing this logic to be usable in Non-Django applications, such as personal projects and school assignments. After repeatedly importing and updating as needed, the logging.py file has slowly changed into what it is today.

Logging files can be found in resources/logs/.

UnitTesting