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

Add unit tests for Java, split test cases per language #42

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a277bc5
java test added
mylinh-dao-mw Jan 23, 2024
e5af6a1
correct java tests to adapt to the new implementation in GenericParse…
mylinh-dao-mw Jan 23, 2024
5e13124
change name of the test function
mylinh-dao-mw Jan 23, 2024
9dc0bf6
extract Java test cases from GenericParse.test to enhance test modula…
mylinhdao Jan 24, 2024
2064b4c
add Java test for overloaded functions
mylinhdao Jan 24, 2024
ad6d3ff
change test file location
mylinhdao Jan 25, 2024
5a9e95a
Split GenericParser into tests for multiple languages
mylinhdao Jan 25, 2024
d134dad
add missing Snapshots
mylinhdao Jan 25, 2024
56e7c23
delete snapshot for GenericParser.test.ts
mylinhdao Jan 25, 2024
250d722
Adjustments due to review
ResistantBear Jan 29, 2024
9560b4c
Add comment metric test for Java language and restructure the testing…
mylinhdao Jan 30, 2024
b076c1d
Replace hard coded metric names (string) with enum for all metric tes…
mylinhdao Jan 30, 2024
74d016a
Added missing documentation
ResistantBear Jan 30, 2024
fee1dfb
Improved error handling for undefined root node
ResistantBear Jan 30, 2024
d4d614b
Merged test cases added in the main
ResistantBear Jan 30, 2024
df7c415
Using type system to await a FileMetric-Enum entry
ResistantBear Jan 31, 2024
db9ca48
Removed unreachable if
ResistantBear Jan 31, 2024
36f7c5f
Manually merged changes from main
ResistantBear Jan 31, 2024
36dacf3
Delete obsolte files
ResistantBear Jan 31, 2024
1d1ed80
Fixes bug caused by a wrong file extension
ResistantBear Feb 1, 2024
bf64dea
Updated .gitignore to include /dist snapshot test files, updated snap…
ResistantBear Feb 1, 2024
27d7e29
Temporal workaround for test case race condition
ResistantBear Feb 1, 2024
feac150
Exclude dist folder from jest
ResistantBear Feb 1, 2024
9f06508
Add test for switch-statement, adjust test cases for calculate mcc (J…
mylinhdao Feb 2, 2024
2dd172a
Adjusted switch case test #40
ResistantBear Feb 2, 2024
4316cef
added line break #40
ResistantBear Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ node_modules
.clinic
.DS_Store

dist/*
!dist/parser/
dist/parser/*
!dist/parser/__snapshots__/

!dist/commands
dist/commands/*
!dist/commands/__snapshots__/
dist

./resources/output.json
3 changes: 0 additions & 3 deletions dist/commands/__snapshots__/outputMetrics.test.js.snap

This file was deleted.

1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
coverageDirectory: "<rootDir>/dist/coverage",
collectCoverageFrom: ["<rootDir>/src/**/*.{ts,tsx}", "!**/node_modules/**"],
coveragePathIgnorePatterns: ["(/__tests__/.*|\\.(test|e2e))\\.(ts|tsx)$"],
testPathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/node_modules/"],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"start": "tsc && node dist/app.js",
"test": "tsc && jest",
"test": "tsc && jest --maxWorkers=24",
"format": "prettier --write \"./**/*\"",
"format:quick": "pretty-quick --staged",
"lint": "eslint \"src/**/*.ts\"",
Expand Down
Empty file added resources/java/Empty.java
Empty file.
24 changes: 24 additions & 0 deletions resources/java/classes/ClassWithFieldsAndMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class MyClass {
private int myNumber; // Variable
InnerClass innerClass;

// Constructor
public MyClass(int initialNumber) {
this.myNumber = initialNumber;
this.innerClass = new InnerClass();
innerClass.key = initialNumber;
}

// Method
public void printNumber() {
System.out.println("My number is: " + myNumber);
}

// Getter for the variable
public int getMyNumber() {
return myNumber;
}
public class InnerClass {
int key;
}
}
6 changes: 6 additions & 0 deletions resources/java/classes/Classes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Student { //the student
}
public class Professor { //the professor

}

11 changes: 11 additions & 0 deletions resources/java/classes/Classlike.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum Food{
Fish,
Vegetable
}
class Kitchen{
}
interface World {
}
abstract class Abstraction{

}
28 changes: 28 additions & 0 deletions resources/java/classes/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

//public class HelloWorld {}
/**
* public class MyClass {
* private int myNumber; // Variable
* InnerClass innerClass;
*
* // Constructor
* public MyClass(int initialNumber) {
* this.myNumber = initialNumber;
* this.innerClass = new InnerClass();
* innerClass.key = initialNumber;
* }
*
* // Method
* public void printNumber() {
* System.out.println("My number is: " + myNumber);
* }
*
* // Getter for the variable
* public int getMyNumber() {
* return myNumber;
* }
* public class InnerClass {
* int key;
* }
* }
*/
17 changes: 17 additions & 0 deletions resources/java/classes/NestedClasses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class NestedClassesExample {
public static class StaticNestedClass {
public void staticNestedMethod() {
System.out.println("Inside StaticNestedClass's method");
}
}

private class InnerClass {
public void innerMethod() {
System.out.println("Inside InnerClass's method");
}
}
protected class Treasure{

}
}

37 changes: 37 additions & 0 deletions resources/java/comment_lines/DifferentKindOfComments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Single-line comment

/*
* Multi-line comment
*
* This is another line of the multi-line comment.
*/

/*
Multi-line comment containing line break



This is another line of the multi-line comment.
*/
public class CommentExample {
/**
* Main method to demonstrate comments.
* @param number .
*/
public void doSomething(int number){
number++; //increment
number--; /* short comment*/
System.out.print(/*between the line*/ "hello world"); /*hello*/ //greeting
System.out.print(/* multiline
more multiline
*/"hello");
System.out.print(
//hello
"hello"
//hello
);
// ╔════════════╗
// ║ Hello! ║
// ╚════════════╝
}
}
10 changes: 10 additions & 0 deletions resources/java/functions/AbstractClassFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
abstract class MyAbstractClass {

// Abstract method in the abstract class
public abstract void abstractMethod(); //abstract

// Concrete method in the abstract class
public void concreteMethod() { //concrete
System.out.println("Concrete method in MyAbstractClass");
}
}
80 changes: 80 additions & 0 deletions resources/java/functions/Constructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
public class Book {
private String title;
private String author;
private int pageCount;

// Constructor with no parameters
public Book() {
this.title = "Unknown Title";
this.author = "Unknown Author";
this.pageCount = 0;
}

// Constructor with title and author parameters
public Book(String title, String author) {
this.title = title;
this.author = author;
this.pageCount = 0; // Default page count
}

// Constructor with all parameters
public Book(String title, String author, int pageCount) {
this.title = title;
this.author = author;
this.pageCount = pageCount;
}

// Getter methods for accessing private fields
public String getTitle() {
return title;
}

public String getAuthor() {
return author;
}

public int getPageCount() {
return pageCount;
}

// Setter methods for modifying private fields
public void setTitle(String title) {
this.title = title;
}

public void setAuthor(String author) {
this.author = author;
}

public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}

// Method to display book information
public void displayBookInfo() {
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("Page Count: " + pageCount);
}

/**
* Main method to demonstrate the usage of the Book class with different constructors.
*
* @param args Command-line arguments (not used in this example).
*/
public static void main(String[] args) {
// Using different constructors to create Book objects
Book book1 = new Book(); // Using the default constructor
Book book2 = new Book("Java Programming", "John Doe"); // Using the constructor with title and author
Book book3 = new Book("Design Patterns", "Jane Smith", 300); // Using the constructor with all parameters

// Displaying book information
book1.displayBookInfo();
System.out.println();

book2.displayBookInfo();
System.out.println();

book3.displayBookInfo();
}
}
19 changes: 19 additions & 0 deletions resources/java/functions/FunctionAccessModifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class AccessModifierExample {

public void publicMethod() {
this.protectedMethod();
System.out.println("This is a public method.");
}

protected void protectedMethod() {
System.out.println("This is a protected method.");
}

void defaultMethod() {
System.out.println("This is a default (package-private) method.");
}

private void privateMethod() {
System.out.println("This is a private method.");
}
}
8 changes: 8 additions & 0 deletions resources/java/functions/InterfaceFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public interface MyInterface {
// Abstract method in the interface
void interfaceMethod();

// Default method in the interface (introduced in Java 8)
default void defaultMethod() {
System.out.println("Default implementation in MyInterface");
}
17 changes: 17 additions & 0 deletions resources/java/functions/OverloadFuntion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class OverloadedFunctionsExample {

// Overloaded function with two integer parameters
public static int add(int a, int b) {
return a + b;
}

// Overloaded function with three integer parameters
public static int add(int a, int b, int c) {
return a + b + c;
}

// Overloaded function with two double parameters
public static double add(double a, double b) {
return a + b;
}
}
21 changes: 21 additions & 0 deletions resources/java/functions/StaticFuntions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class ExampleClass {
private static int staticVariable = 0;
private int instanceVariable = 0;
private String message = "message";
public static void incrementStaticVariable() {
staticVariable++;
}
public static int returnStaticMessage() {
return "Hello";
}
public void incrementInstanceVariable() {
instanceVariable++;
}
public void returnMessage() {
return this.message;
}
public static void main(String[] args) {
ExampleClass obj1 = new ExampleClass(5);
ExampleClass obj2 = new ExampleClass(10);
}
}
24 changes: 24 additions & 0 deletions resources/java/lines_of_code/ClassForLOC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class MyClass {
private int myNumber; // Variable
InnerClass innerClass;

// Constructor
public MyClass(int initialNumber) {
this.myNumber = initialNumber;
this.innerClass = new InnerClass();
innerClass.key = initialNumber;
}

// Method
public void printNumber() {
System.out.println("My number is: " + myNumber);
}

// Getter for the variable
public int getMyNumber() {
return myNumber;
}
public class InnerClass {
int key;
}
}
6 changes: 6 additions & 0 deletions resources/java/lines_of_code/Linebreak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

class Cat{



}
30 changes: 30 additions & 0 deletions resources/java/lines_of_code/MultilineLineOfCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class MultiLine {
interface MyFunctionalInterface {
void myMethod();
}



String multiLineString = "This is a multi-line \n"
+ "string using escape characters.";


String multiLineString = """
This is a multi-line
string using text blocks.
""";

int result = addNumbers(
10,
20,
30
);


int[] numbers = {
1,
2,
3,
4
};
}
Loading