Skip to content

Dev sprint ideas: More tests, type hints and less complexity #2128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 of 13 tasks
itsvinayak opened this issue Jun 17, 2020 · 13 comments
Closed
3 of 13 tasks

Dev sprint ideas: More tests, type hints and less complexity #2128

itsvinayak opened this issue Jun 17, 2020 · 13 comments
Assignees
Labels
enhancement This PR modified some existing files good first issue help wanted

Comments

@itsvinayak
Copy link
Member

itsvinayak commented Jun 17, 2020

currently, some of the programs use static type checking like this program but some of the programs did not use static typing.

it's a good practice to use static typing as it makes code more clear and readable, should we make it a standard for this repository.we can use mypy for testing code

more on static typing

thank you

Dev sprint ideas:

@itsvinayak itsvinayak added question enhancement This PR modified some existing files labels Jun 17, 2020
@cclauss
Copy link
Member

cclauss commented Jun 17, 2020

We push all new contributions to use type hints as discussed in CONTRIBUTING.md.
All efforts to add type hints to existing algorithms would be warmly received.

We can use mypy for testing code

We do this already https://github.com/TheAlgorithms/Python/blob/master/.travis.yml#L17

@onlinejudge95
Copy link
Collaborator

@cclauss How about a dev sprint kind of thing where we go about adding all such improvements?

@cclauss
Copy link
Member

cclauss commented Jun 17, 2020

Cool idea! Another thing (a sprint topic?) that is bugging me is code complexity which we currently set to 25 but I would be much happier to see it at 15. We would need to ensure that the files have strong type hints and tests before modifying them to reduce their cyclomatic complexity.

@cclauss
Copy link
Member

cclauss commented Jun 17, 2020

Another cool sprint topic would be to add doctests to Python files that have <10% test coverage. Some files like file_transfer/send_file.py and the web programming files are difficult to write tests for but others should be fair game.

@cclauss cclauss changed the title Static typing standard for repository Dev sprint ideas: More tests, type hints and less cyclomatic complexity Jun 17, 2020
@cclauss cclauss changed the title Dev sprint ideas: More tests, type hints and less cyclomatic complexity Dev sprint ideas: More tests, type hints and less code complexity Jun 17, 2020
@cclauss cclauss changed the title Dev sprint ideas: More tests, type hints and less code complexity Dev sprint ideas: More tests, type hints and less complexity Jun 17, 2020
@cclauss
Copy link
Member

cclauss commented Jun 20, 2020

Should we have a short sprint or a long one? One idea would be 24 hour sprint — given that tomorrow is summer solstice (longest day of the year) — the sprint could start at midnight tonight (in whatever timezone the contributer is in) and last for 24 hours. #2128 could be our tracking issue for keeping track of tasks and accomplishments. Thoughts on this Summer Solstice Special Sprint idea.

@onlinejudge95
Copy link
Collaborator

Seems awesome, we can gain some attention by Summer Solstice Special Sprint, I am up on gitter if you want to discuss

cclauss added a commit that referenced this issue Jun 21, 2020
Work In Progress Draft: Do not merge if test are not passing!!

Related to #2128, find all files that contain algorithms with > 15% McCabe complexity.
cclauss added a commit that referenced this issue Jun 21, 2020
cclauss added a commit that referenced this issue Jun 21, 2020
@cclauss cclauss removed the question label Jun 21, 2020
@l3str4nge
Copy link
Member

l3str4nge commented Jun 22, 2020

Another cool sprint topic would be to add doctests to Python files that have <10% test coverage. Some files like file_transfer/send_file.py and the web programming files are difficult to write tests for but others should be fair game.

Difficult but not impossible. We can create issue with some labels. Perhaps we find someone who will write tests or even code (for example simple server for response) for testing it 😃

cclauss added a commit that referenced this issue Jun 22, 2020
* Euler problem 551 sol 1: Reduce McCabe code complexity

As discussed in #2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
cclauss added a commit that referenced this issue Jun 22, 2020
* hamming_code.py: Reduce McCabe code complexity

As discussed in #2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
NumberPiOso added a commit to NumberPiOso/Python that referenced this issue Oct 2, 2020
- Test lists were not ordered, this is required for Fibonacci search
- Place documentation of function inside function
- Create multiple different tests including, float, char and negatives
- Add type hints in line with TheAlgorithms#2128
@ronnydw
Copy link

ronnydw commented Oct 3, 2020

Concerning complexity and maintainability, I've run the repo through wily (https://github.com/tonybaloney/wily), a command-line application for tracking, reporting on the complexity of Python tests and applications.

Here are the results for maintainability index [0..100] per module. The scale considers anything lower than 25 as hard to maintain, and anything over 75 as easy to maintain.

│ File                                                                    │   Maintainability Index │
│ hashes                                                                  │                 60.1865 │
│ neural_network                                                          │                 67.4381 │
│ ciphers                                                                 │                 67.8471 │
│ graphs                                                                  │                 68.9013 │
│ bit_manipulation                                                        │                 69.5657 │
│ linear_algebra                                                          │                 69.6743 │
│ searches                                                                │                 70.5201 │
│ backtracking                                                            │                 71.0636 │
│ divide_and_conquer                                                      │                 71.504  │
│ blockchain                                                              │                 71.9272 │
│ data_structures                                                         │                 71.9902 │
│ matrix                                                                  │                 72.5374 │
│ scripts                                                                 │                 73.9013 │
│ strings                                                                 │                 74.1231 │
│ machine_learning                                                        │                 75.3904 │
│ sorts                                                                   │                 75.6606 │
│ maths                                                                   │                 75.6964 │
│ other                                                                   │                 75.6972 │
│ traversals                                                              │                 76.3276 │
│ geodesy                                                                 │                 76.5739 │
│ dynamic_programming                                                     │                 76.6071 │
│ conversions                                                             │                 77.2626 │
│ boolean_algebra                                                         │                 78.4325 │
│ scheduling                                                              │                 78.8933 │
│ greedy_method                                                           │                 79.298  │
│ compression                                                             │                 80.0726 │
│ networking_flow                                                         │                 81.1551 │
│ arithmetic_analysis                                                     │                 83.0291 │
│ genetic_algorithm                                                       │                 83.2064 │
│ project_euler                                                           │                 83.7122 │
│ web_programming                                                         │                 84.3123 │
│ graphics                                                                │                 84.6733 │
│ computer_vision                                                         │                 84.8111 │
│ digital_image_processing                                                │                 86.2331 │
│ cellular_automata                                                       │                 87.3411 │
│ fuzzy_logic                                                             │                 87.7142 │
│ file_transfer                                                           │                 96.1178 │
│ quantum                                                                 │                100      │
│ images                                                                  │                100      │
│ Total                                                                   │                 77.2957 │

This allows us to track the overall maintainability of the repo (=77.3) and focus improvements on the less maintainable files. For new files, a threshold of 75 could be set for the maintainability index.

@cclauss
Copy link
Member

cclauss commented Oct 3, 2020

Please pick one directory (and ONLY one directory) [like hashes] and create a PR that demonstrates how we can improve.

dhruvmanila added a commit that referenced this issue Oct 8, 2020
* Fix: Multiple errors in fibonacci search.

- Test lists were not ordered, this is required for Fibonacci search
- Place documentation of function inside function
- Create multiple different tests including, float, char and negatives
- Add type hints in line with #2128

* Fix: sort of modules and delete typehint.

* Apply suggestions from code review

Co-authored-by: Dhruv <[email protected]>

* Correct invocation of lru_cache.

* Add check for input in fibonacci and doctest.

* Correct typehints to comply to numpy style.

* Correct ValueError to TypeError.

Co-authored-by: Dhruv <[email protected]>

* Correct doctest for TypeError.

* Rename  single letter names as mentioned in CONTRIBUTING.md.

* Fix: Bug in big lists.

* Remove print(.) in doctests.

* Refactor iterator to while loop.

* Update searches/fibonacci_search.py

Co-authored-by: Dhruv <[email protected]>
@poyea poyea closed this as completed in c2a5033 Oct 8, 2020
cclauss pushed a commit that referenced this issue Oct 15, 2020
* graphs/kruskal: add doctest & type hints

this is a child of a previous PR #2443

its ancestor is #2128

* updating DIRECTORY.md

* graphs/kruskal: fix max-line-length violation

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
@tanyonghe tanyonghe mentioned this issue Oct 19, 2020
16 tasks
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
…#2141)

* Euler problem 551 sol 1: Reduce McCabe code complexity

As discussed in TheAlgorithms#2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
* hamming_code.py: Reduce McCabe code complexity

As discussed in TheAlgorithms#2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
…eAlgorithms#2241)

* added type hints and doctests to arithmetic_analysis/bisection.py

continuing in line with TheAlgorithms#2128

* modified arithmetic_analysis/bisection.py

Put back print statement at the end, replaced algorithm's print statement with an exception.

* modified arithmetic_analysis/bisection.py

Removed unnecessary type import "Optional"

* modified arithmetic_analysis/bisection.py

Replaced generic Exception with ValueError.

* modified arithmetic_analysis/bisection.py

fixed doctests
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
…TheAlgorithms#2259)

* added type hints and doctests to arithmetic_analysis/newton_method.py

Continuing TheAlgorithms#2128
Also changed some variable names, made them more descriptive.

* Added type hints and doctests to arithmetic_analysis/newton_method.py

added a type alias for Callable[[float], float] and cleaned up the exception handling

* added type hints and doctests to arithmetic_analysis/newton_method.py

improved exception handling

* Update newton_method.py

Co-authored-by: Christian Clauss <[email protected]>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
…Algorithms#2128 (TheAlgorithms#2335)

* Added static type checking to linear_algebra/src/polynom-for-points.py

* Fixed TravisCI errors

* Update polynom-for-points.py

Co-authored-by: Christian Clauss <[email protected]>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
* Fix: Multiple errors in fibonacci search.

- Test lists were not ordered, this is required for Fibonacci search
- Place documentation of function inside function
- Create multiple different tests including, float, char and negatives
- Add type hints in line with TheAlgorithms#2128

* Fix: sort of modules and delete typehint.

* Apply suggestions from code review

Co-authored-by: Dhruv <[email protected]>

* Correct invocation of lru_cache.

* Add check for input in fibonacci and doctest.

* Correct typehints to comply to numpy style.

* Correct ValueError to TypeError.

Co-authored-by: Dhruv <[email protected]>

* Correct doctest for TypeError.

* Rename  single letter names as mentioned in CONTRIBUTING.md.

* Fix: Bug in big lists.

* Remove print(.) in doctests.

* Refactor iterator to while loop.

* Update searches/fibonacci_search.py

Co-authored-by: Dhruv <[email protected]>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
…TheAlgorithms#2443)

* test/graphs/kruskal: adding a test case to verify the correctness of the algorithm

Fixes TheAlgorithms#2128

* grahps/kruskal: running psf/black

* graphs/kruskal: read edges in a friendlier fashion

Co-authored-by: Christian Clauss <[email protected]>

* Update minimum_spanning_tree_kruskal.py

* fixup! Format Python code with psf/black push

* Update test_min_spanning_tree_kruskal.py

* updating DIRECTORY.md

Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: John Law <[email protected]>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
stokhos pushed a commit to stokhos/Python that referenced this issue Jan 3, 2021
* graphs/kruskal: add doctest & type hints

this is a child of a previous PR TheAlgorithms#2443

its ancestor is TheAlgorithms#2128

* updating DIRECTORY.md

* graphs/kruskal: fix max-line-length violation

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this issue May 13, 2021
* Fix: Multiple errors in fibonacci search.

- Test lists were not ordered, this is required for Fibonacci search
- Place documentation of function inside function
- Create multiple different tests including, float, char and negatives
- Add type hints in line with TheAlgorithms#2128

* Fix: sort of modules and delete typehint.

* Apply suggestions from code review

Co-authored-by: Dhruv <[email protected]>

* Correct invocation of lru_cache.

* Add check for input in fibonacci and doctest.

* Correct typehints to comply to numpy style.

* Correct ValueError to TypeError.

Co-authored-by: Dhruv <[email protected]>

* Correct doctest for TypeError.

* Rename  single letter names as mentioned in CONTRIBUTING.md.

* Fix: Bug in big lists.

* Remove print(.) in doctests.

* Refactor iterator to while loop.

* Update searches/fibonacci_search.py

Co-authored-by: Dhruv <[email protected]>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this issue May 13, 2021
…TheAlgorithms#2443)

* test/graphs/kruskal: adding a test case to verify the correctness of the algorithm

Fixes TheAlgorithms#2128

* grahps/kruskal: running psf/black

* graphs/kruskal: read edges in a friendlier fashion

Co-authored-by: Christian Clauss <[email protected]>

* Update minimum_spanning_tree_kruskal.py

* fixup! Format Python code with psf/black push

* Update test_min_spanning_tree_kruskal.py

* updating DIRECTORY.md

Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: John Law <[email protected]>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this issue May 13, 2021
* graphs/kruskal: add doctest & type hints

this is a child of a previous PR TheAlgorithms#2443

its ancestor is TheAlgorithms#2128

* updating DIRECTORY.md

* graphs/kruskal: fix max-line-length violation

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files good first issue help wanted
Projects
None yet
10 participants