Skip to content
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

--below argument works incorrectly #10

Closed
sobolevn opened this issue Sep 21, 2018 · 1 comment
Closed

--below argument works incorrectly #10

sobolevn opened this issue Sep 21, 2018 · 1 comment

Comments

@sobolevn
Copy link

After updating to 0.9.1 I have faced a new issue:

  1. create an example.py file from the readme
  2. run cohesion -f example.py, output will be:
File: example.py
  Class: ExampleClass1 (1:0)
    Function: func1 2/3 66.67%
    Function: func2 1/3 33.33%
    Function: func3 staticmethod
    Total: 33.33%
  Class: ExampleClass2 (22:0)
    Function: func1 1/1 100.00%
    Total: 100.00%
  1. then run cohesion --below 100 -f example.py, output will not change
File: example.py
  Class: ExampleClass1 (1:0)
    Function: func1 2/3 66.67%
    Function: func2 1/3 33.33%
    Function: func3 staticmethod
    Total: 33.33%
  Class: ExampleClass2 (22:0)
    Function: func1 1/1 100.00%
    Total: 100.00%

However, 100 is not below 100. It is equal.

Just for the reference, running cohesion --below 99 -f example.py:

File: example.py
  Class: ExampleClass1 (1:0)
    Function: func1 2/3 66.67%
    Function: func2 1/3 33.33%
    Function: func3 staticmethod
    Total: 33.33%

It works well.

@mschwager
Copy link
Owner

This is the expected behavior.

If you look at the help text it states this:

$ PYTHONPATH=lib:$PYTHONPATH python3 -m cohesion -h
usage: __main__.py [-h] [-v | -x] (-f FILES [FILES ...] | -d DIRECTORY)
                   [-b BELOW | -a ABOVE]
...
  -b BELOW, --below BELOW
                        only show results with this percentage or lower
  -a ABOVE, --above ABOVE
                        only show results with this percentage or higher

Further, there's even tests confirming this behavior: test_module.test_module_filter_above_equal and test_module.test_module_filter_below_equal.

My rationale behind this decision was that there will often be classes that sit on the boundary of common fraction's percentages (e.g. 1/2 -> 50%, 1/4 -> 25%, 1/10 -> 10%). Further, if you're really curious about classes with cohesion below 25%, then there's probably many classes sitting at exactly 25% that you're also curious about.

On toy files like the example it's not as obvious why this would be helpful, but in larger code bases with many classes and a large variation in cohesion percentages it can be helpful.

Hope this clears things up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants