cqfn / aibolit

Static Analyzer for Java Code with Machine Learning in Mind
https://pypi.org/project/aibolit/
51 stars 17 forks source link

Refactored cognitive #479

Closed Vitaly-Protasov closed 4 years ago

aravij commented 4 years ago

@Vitaly-Protasov The understandability of this code had really increased! Great! Do I understand correctly there is absolutely no problems with test?

Vitaly-Protasov commented 4 years ago

@Vitaly-Protasov The understandability of this code had really increased! Great! Do I understand correctly there is absolutely no problems with test?

nope, there are 4 false tests.

` FAIL: test4 (test.metrics.cognitiveC.test_cognitive_c.TestCognitive)

Traceback (most recent call last): File "C:\Users\Vitaly\Desktop\Work\aibolit\test\metrics\cognitiveC\test_cognitive_c.py", line 47, in test4 self.assertEqual(lines, 6) AssertionError: 8 != 6

====================================================================== FAIL: test5 (test.metrics.cognitiveC.test_cognitive_c.TestCognitive)

Traceback (most recent call last): File "C:\Users\Vitaly\Desktop\Work\aibolit\test\metrics\cognitiveC\test_cognitive_c.py", line 51, in test5 self.assertEqual(lines, 7) AssertionError: 4 != 7

====================================================================== FAIL: test6 (test.metrics.cognitiveC.test_cognitive_c.TestCognitive)

Traceback (most recent call last): File "C:\Users\Vitaly\Desktop\Work\aibolit\test\metrics\cognitiveC\test_cognitive_c.py", line 55, in test6 self.assertEqual(lines, 14) AssertionError: 17 != 14

====================================================================== FAIL: test7 (test.metrics.cognitiveC.test_cognitive_c.TestCognitive)

Traceback (most recent call last): File "C:\Users\Vitaly\Desktop\Work\aibolit\test\metrics\cognitiveC\test_cognitive_c.py", line 59, in test7 self.assertEqual(lines, 7) AssertionError: 6 != 7 `

Vitaly-Protasov commented 4 years ago

@aravij Let's consider this example:

class Test {
    public static void main(String[] arg) {
        int a = 1;
        if ( a && b && c ) {
            a = 1;
    }
}

}

This function return Cognitive complexity = 3; but it shoulb be equal to 2.

It doesn't work right for Binary Operations

aravij commented 4 years ago

@acheshkov please merge

acheshkov commented 4 years ago

@rultor merge

rultor commented 4 years ago

@rultor merge

@acheshkov OK, I'll try to merge now. You can check the progress of the merge here

rultor commented 4 years ago

@rultor merge

@vitaly-protasov @acheshkov Oops, I failed. You can see the full log here (spent 13min)

Requirement already satisfied: Jinja2>=2.3 in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (2.11.2)
Requirement already satisfied: sphinxcontrib-jsmath in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (1.0.1)
Requirement already satisfied: snowballstemmer>=1.1 in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (2.0.0)
Requirement already satisfied: Pygments>=2.0 in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (2.6.1)
Requirement already satisfied: sphinxcontrib-qthelp in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (1.0.3)
Requirement already satisfied: sphinxcontrib-serializinghtml in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (1.1.4)
Requirement already satisfied: alabaster<0.8,>=0.7 in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (0.7.12)
Requirement already satisfied: sphinxcontrib-htmlhelp in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (1.0.3)
Requirement already satisfied: imagesize in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (1.2.0)
Requirement already satisfied: sphinxcontrib-applehelp in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (1.0.2)
Requirement already satisfied: docutils>=0.12 in /home/r/.local/lib/python3.6/site-packages (from sphinx==2.3.1->aibolit==0.0.0) (0.16)
Requirement already satisfied: retrying>=1.3.3 in /home/r/.local/lib/python3.6/site-packages (from plotly->catboost==0.22->aibolit==0.0.0) (1.3.3)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/lib/python3/dist-packages (from requests>=2.7.9->codecov==2.0.15->aibolit==0.0.0) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python3/dist-packages (from requests>=2.7.9->codecov==2.0.15->aibolit==0.0.0) (1.22)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3/dist-packages (from requests>=2.7.9->codecov==2.0.15->aibolit==0.0.0) (2.6)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.7.9->codecov==2.0.15->aibolit==0.0.0) (2018.1.18)
Requirement already satisfied: MarkupSafe>=0.23 in /home/r/.local/lib/python3.6/site-packages (from Jinja2>=2.3->sphinx==2.3.1->aibolit==0.0.0) (1.1.1)
Building wheels for collected packages: aibolit
  Building wheel for aibolit (setup.py) ... \u001b[?25l-\u0008 \u0008\\u0008 \u0008|\u0008 \u0008/\u0008 \u0008-\u0008 \u0008\\u0008 \u0008done
\u001b[?25h  Created wheel for aibolit: filename=aibolit-0.0.0-py2.py3-none-any.whl size=12101147 sha256=86029a11eb7f70ef0d7cec8d9261500b5c106dad9da6a503e57223292695ab3c
  Stored in directory: /tmp/pip-ephem-wheel-cache-8nipqhuy/wheels/6a/94/20/fb6515fe78e005049099e68caee81e4e2e53c92744d4ab767f
Successfully built aibolit
Installing collected packages: aibolit
\u001b[33m  WARNING: The script aibolit is installed in '/home/r/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\u001b[0m
Successfully installed aibolit-0.0.0
\u001b[33mWARNING: You are using pip version 20.0.2; however, version 20.1.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.\u001b[0m
python3 -m flake8 aibolit test scripts setup.py --exclude scripts/target/*
python3 -m mypy aibolit
\u001b[1m\u001b[32mSuccess: no issues found in 137 source files\u001b(B\u001b[m
python3 -m coverage run -m unittest discover
.......................sss................sss.............................sssssss......................................................................sssssssssssssss..........................sssssssssssss...........ss...........................................................................................................................................................
----------------------------------------------------------------------
Ran 373 tests in 15.062s

OK (skipped=43)
python3 aibolit --version
Version 1.1.2 is available, but you are using 0.0.0
aibolit 0.0.0
xcop 
python3 ./test/integration/all.py
+ mv /home/r/repo .
++ whoami
+ chown -R root repo
+ '[' -n '' ']'
++ whoami
+ sudo chown -R rultor repo
+ cd repo
+ git push origin master
To git@github.com:cqfn/aibolit.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:cqfn/aibolit.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
container 5e92f13dc713f5afbe920a5567c3a28a5d64b684d4809796bbacf076a89d1f0e is dead
Tue Jul  7 18:23:42 CEST 2020
Vitaly-Protasov commented 4 years ago

@rultor merge

rultor commented 4 years ago

@rultor merge

@vitaly-protasov Thanks for your request. @yegor256 Please confirm this.

acheshkov commented 4 years ago

@rultor merge

rultor commented 4 years ago

@rultor merge

@acheshkov OK, I'll try to merge now. You can check the progress of the merge here

rultor commented 4 years ago

@rultor merge

@acheshkov Done! FYI, the full log is here (took me 15min)