diff --git a/documents/references.md b/documents/references.md new file mode 100644 index 0000000000000000000000000000000000000000..7c8f4c33ad5f5733218ae92ccb1c69a3b7f769e2 --- /dev/null +++ b/documents/references.md @@ -0,0 +1,44 @@ +# Fractional Knapsack Algorithm > Documents > Testing.md + +## Description +All references to external logic. Includes anything from stack overflow links to notes about logic from previous works. + + +## New References +References new to this project. + +**None so far.** + + +## Old References +References linked in previous assignments. + +### 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 +Getting module imports to work correctly (-t arg): +<https://docs.python.org/3/library/unittest.html#test-discovery> + +Running UnitTests from Console: <https://stackoverflow.com/a/15630454>. + +Running UnitTests from Pycharm: Trial and error with modifying above references. + +Running a single UnitTest: <https://stackoverflow.com/a/43029618> + +### Using Pytest +General Documentation: <https://docs.pytest.org/en/latest/contents.html#toc> + +Running PyTests from Pycharm: <https://www.jetbrains.com/help/pycharm/run-debug-configuration-py-test.html> + +Running a single PyTest: <https://docs.pytest.org/en/latest/getting-started.html#create-your-first-test> + +Issues with module imports: <https://stackoverflow.com/a/50610630> diff --git a/documents/testing.md b/documents/testing.md new file mode 100644 index 0000000000000000000000000000000000000000..11eadc80c03963e7457215f53ff549fa4dc238ed --- /dev/null +++ b/documents/testing.md @@ -0,0 +1,69 @@ +# Fractional Knapsack Algorithm > Documents > Testing.md + + +## Description +General information to run both UnitTests and Pytests, with Python. +Includes information for both running through terminal and through Pycharm. + +> Note: This has been tested on Linux (Ubuntu 16.04). May not work with Windows/Mac. + + +## Testing with UnitTest +Unittests come built into python. No need for third party packages. + +### Running a Single UnitTest +The following will run tests from a single file. + +> NOTE: For the file path of these two commands, replace any `/` characters with `.` instead.<br> +> So for example, `tests/my_tests/test_file.py` would turn into `tests.my_tests.test_file.py`. + +* Terminal: From a terminal, run `python -m unittest <path_to_file>` + +* Pycharm: Create a new `unittest` configuration with the properties: + * Target: `custom` + * Additional Arguments: `python -m unittest <path_to_file>` + * Python Interpreter: `<your_preferred_interpreter_environment>` + * Working Directory: `<project_root>` + + +### Running Multiple UnitTests +The following will "run all tests in a given directory". + +> NOTE: For these to work as intended, there needs to be an "__init__.py" file in each project subdirectory that the +> tests access (even despite using Python3). + +* Terminal: From a terminal at the project root, run `python -m unittest discover <path_to_folder> -p "*.py" -t ./` + +* Pycharm: Create a new `unittest` configuration with the properties: + * Target: `custom` + * Additional Arguments: `discover -s <path_to_folder> -p "*.py" -t ./` + * Python Interpreter: `<your_preferred_interpreter_environment>` + * Working Directory: `<project_root>` + +## PyTest +PyTest is an alternative to UnitTests, using a third party library. +To install, run `pip install pytest`. + +### Running a Single PyTest +The following will run all tests from a single file. + +* Terminal: From a terminal, run `pytest -q <path_to_file>`. + +* Pycharm: Create a new `py.test` or `pytest` configuration (depending on your Pycharm version) with the properties: + * Target: `custom` + * Additional Arguments: `-q <path_to_file>` + * Python Interpreter: `<your_preferred_interpreter_environment>` + * Working Directory: `<project_root>` + +### Running Multiple PyTests +The following will "run all tests in root folder". + +> NOTE: You cannot have an `__init__.py` at project root.<br> +> If you get a ModuleError/ImportError, you also may have to create a blank `conftest.py` at project root. + +* Terminal: From a terminal at the project root, run `pytest`. + +* Pycharm: Create a new `py.test` or `pytest` configuration (depending on your Pycharm version) with the properties: + * Target: `custom` + * Python Interpreter: `<your_preferred_interpreter_environment>` + * Working Directory: `<project_root>` diff --git a/readme.md b/readme.md index 28012d0e8538db3faf7f8d7c9fecf2aa6cdcc54e..108426424d1fbef366bda9e02f3d23dfb399520d 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,16 @@ -# --Title Here-- +# Fractional Knapsack Algorithm ## Description ---Description Here-- +Implementation of the "Fractional Knapsack" algorithm. ### Pseudocode Modifications ---Description Here-- +None so far. ## Python Environment This project is tested using Python3.7. -Written using PyCharm. +Written using PyCharm. Tested with Pycharm 2017.2.3 and 2019.2 versions. ### 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 @@ -27,96 +27,14 @@ Once created, load this environment with `source .venv/bin/activate` on Linux or Run the program via `python ./main.py` while at the project root. ### Expected Output ---Description Here-- +None so far. -## Testing with UnitTest -Unittests come built into python. No need for third party packages. +## Running Tests +To run all unittests for this project, open a terminal and run the `run_unit_tests.sh` bash script. -### Running a Single UnitTest -The following will run tests from a single file. - -NOTE: For the file path of these two commands, replace any `/` characters with `.` instead.<br> -So for example, `tests/my_tests/test_file.py` would turn into `tests.my_tests.test_file.py`. - -* Terminal: From a terminal, run `python -m unittest <path_to_file>` - -* Pycharm: Create a new `unittest` configuration with the properties: - * Target: `custom` - * Additional Arguments: `python -m unittest <path_to_file>` - * Python Interpreter: `<your_preferred_interpreter_environment>` - * Working Directory: `<project_root>` - - -### Running Multiple UnitTests -The following will "run all tests in a given directory".<br> -NOTE: For these to work as intended, there needs to be an "__init__.py" file in each project subdirectory that the tests -access (even despite using Python3). - -* Terminal: From a terminal at the project root, run `python -m unittest discover <path_to_folder> -p "*.py" -t ./` - -* Pycharm: Create a new `unittest` configuration with the properties: - * Target: `custom` - * Additional Arguments: `discover -s <path_to_folder> -p "*.py" -t ./` - * Python Interpreter: `<your_preferred_interpreter_environment>` - * Working Directory: `<project_root>` - -## PyTest -PyTest is an alternative to UnitTests, using a third party library. -To install, run `pip install pytest`. - -### Running a Single PyTest -The following will run all tests from a single file. - -* Terminal: From a terminal, run `pytest -q <path_to_file>`. - -* Pycharm: Create a new `py.test` or `pytest` configuration (depending on your Pycharm version) with the properties: - * Target: `custom` - * Additional Arguments: `-q <path_to_file>` - * Python Interpreter: `<your_preferred_interpreter_environment>` - * Working Directory: `<project_root>` - -### Running Multiple PyTests -The following will "run all tests in root folder". - -NOTE: You cannot have an `__init__.py` at project root.<br> -If you get a ModuleError/ImportError, you also may have to create a blank `conftest.py` at project root. - -* Terminal: From a terminal at the project root, run `pytest`. - -* Pycharm: Create a new `py.test` or `pytest` configuration (depending on your Pycharm version) with the properties: - * Target: `custom` - * Python Interpreter: `<your_preferred_interpreter_environment>` - * Working Directory: `<project_root>` +For more information about testing, see the `documents/testing.md` file. ## 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 -Getting module imports to work correctly (-t arg): -<https://docs.python.org/3/library/unittest.html#test-discovery> - -Running UnitTests from Console: <https://stackoverflow.com/a/15630454>. - -Running UnitTests from Pycharm: Trial and error with modifying above references. - -Running a single UnitTest: <https://stackoverflow.com/a/43029618> - -### Using Pytest -General Documentation: <https://docs.pytest.org/en/latest/contents.html#toc> - -Running PyTests from Pycharm: <https://www.jetbrains.com/help/pycharm/run-debug-configuration-py-test.html> - -Running a single PyTest: <https://docs.pytest.org/en/latest/getting-started.html#create-your-first-test> - -Issues with module imports: <https://stackoverflow.com/a/50610630> +See the `documents/references.md` file.