-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
215 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Aibolit | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
from aibolit.ast_framework import AST, ASTNodeType | ||
from aibolit.utils.ast_builder import build_ast | ||
|
||
|
||
class NumberMethods: | ||
def value(self, filename: str) -> int: | ||
metric = 0 | ||
ast = AST.build_from_javalang(build_ast(filename)) | ||
for class_node in ast.get_proxy_nodes(ASTNodeType.CLASS_DECLARATION): | ||
for method_node in class_node.methods: | ||
metric += 1 | ||
return metric |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This Java code is taken from a public GitHub repository | ||
// and is used inside Aibolit only for integration testing | ||
// purposes. The code is never compiled or executed. | ||
|
||
|
||
class LengthStringComparator implements Comparator<String> { | ||
boolean validate() { // +1 | ||
return new Object() { | ||
boolean check(Struct struct) { | ||
if (!struct.valid()) return false; | ||
for(Struct child : struct.children()) { | ||
if (!check(child)) return false; | ||
} | ||
return true; | ||
} | ||
}.check(_struct); | ||
} | ||
|
||
public static void main(String[] args) // +1 | ||
{ | ||
int test = 3; | ||
main(test); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This Java code is taken from a public GitHub repository | ||
// and is used inside Aibolit only for integration testing | ||
// purposes. The code is never compiled or executed. | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Hospital { | ||
|
||
public static List<Instance> readDataGet(String file) throws FileNotFoundException { // +1 | ||
List<Instance> dataset = new ArrayList<Instance>(); | ||
Scanner scanner = null; | ||
try { | ||
scanner = new Scanner(new File(file)); | ||
while(scanner.hasNextLine()) { | ||
String line = scanner.nextLine(); | ||
if (line.startsWith("#")) { | ||
continue; // +1 | ||
} | ||
String[] columns = line.split("\\s+"); | ||
|
||
// skip first column and last column is the label | ||
int i = 1; | ||
int[] data = new int[columns.length-2]; | ||
for (i=1; i<columns.length-1; i++) { | ||
data[i-1] = Integer.parseInt(columns[i]); | ||
} | ||
int label = Integer.parseInt(columns[i]); | ||
Instance instance = new Instance(label, data); | ||
dataset.add(instance); | ||
} | ||
} finally { | ||
if (scanner != null) | ||
scanner.close(); | ||
} | ||
return dataset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// This Java code is taken from a public GitHub repository | ||
// and is used inside Aibolit only for integration testing | ||
// purposes. The code is never compiled or executed. | ||
|
||
|
||
class LengthStringComparator implements Comparator<String> { | ||
public void recursionFucn() { // +1 | ||
System.out.println("Miss me?!"); | ||
recursionFucn(); | ||
} | ||
|
||
public int fact(int n) // +1 | ||
{ | ||
// wrong base case (it may cause | ||
// stack overflow). | ||
if (n == 100) | ||
return 1; | ||
|
||
else | ||
return n*fact(n-1); | ||
} | ||
|
||
static void printFun(int test) // +1 | ||
{ | ||
if (test < 1) | ||
return; | ||
|
||
else { | ||
System.out.printf("%d ", test); | ||
|
||
// Statement 2 | ||
printFun(test - 1); | ||
|
||
System.out.printf("%d ", test); | ||
return; | ||
} | ||
} | ||
|
||
public static void main(String[] args) // +1 | ||
{ | ||
int test = 3; | ||
printFun(test); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This Java code is taken from a public GitHub repository | ||
// and is used inside Aibolit only for integration testing | ||
// purposes. The code is never compiled or executed. | ||
|
||
|
||
class Test { | ||
public static void main(String[] arg) { // +1 | ||
int a = 1; | ||
if ( a && b && c || d || e && f) { | ||
a = 1; | ||
} | ||
} | ||
|
||
public static void main(String[] arg) { // +1 | ||
int a = 1; | ||
if ( a && !(b && c)) { | ||
a = 1; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2020 Aibolit | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
import os | ||
from unittest import TestCase | ||
from aibolit.metrics.NumberMethods.NumberMethods import NumberMethods | ||
from pathlib import Path | ||
|
||
|
||
class TestCognitive(TestCase): | ||
dir_path = Path(os.path.realpath(__file__)).parent | ||
|
||
def test_one(self): | ||
metric = NumberMethods().value(Path(self.dir_path, 'one.java')) | ||
self.assertEqual(metric, 1) | ||
|
||
def test_simple(self): | ||
metric = NumberMethods().value(Path(self.dir_path, 'simple.java')) | ||
self.assertEqual(metric, 2) | ||
|
||
def test_nested(self): | ||
metric = NumberMethods().value(Path(self.dir_path, 'nested.java')) | ||
self.assertEqual(metric, 2) | ||
|
||
def test_several(self): | ||
metric = NumberMethods().value(Path(self.dir_path, 'several.java')) | ||
self.assertEqual(metric, 4) |
6004964
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: