Skip to content

Commit

Permalink
Adds classes to java test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dburriss committed Jun 24, 2023
1 parent 6b4c952 commit 9ef21cf
Showing 1 changed file with 53 additions and 46 deletions.
99 changes: 53 additions & 46 deletions src/metrics/cognitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,12 +1741,13 @@ mod tests {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 0.0,
"average": null,
"min": 0.0,
"max": 0.0
}"###
{
"sum": 0.0,
"average": null,
"min": 0.0,
"max": 0.0
}
"###
);
});
}
Expand All @@ -1764,12 +1765,13 @@ mod tests {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 1.0,
"average": null,
"min": 1.0,
"max": 1.0
}"###
{
"sum": 1.0,
"average": null,
"min": 1.0,
"max": 1.0
}
"###
);
},
);
Expand All @@ -1794,12 +1796,13 @@ mod tests {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 3.0,
"average": null,
"min": 3.0,
"max": 3.0
}"###
{
"sum": 3.0,
"average": null,
"min": 3.0,
"max": 3.0
}
"###
);
},
);
Expand All @@ -1808,23 +1811,24 @@ mod tests {
#[test]
fn java_compound_conditions() {
check_metrics::<JavaParser>(
"public static void print(Boolean a, Boolean b, Boolean c, Boolean d){
if(a && b){ // +2
System.out.println(\"test1\");
}
if(c && d){ // +2
System.out.println(\"test2\");
}
}",
"class X {
public static void print(Boolean a, Boolean b, Boolean c, Boolean d){
if(a && b){ // +2
System.out.println(\"test1\");
}
if(c && d){ // +2
System.out.println(\"test2\");
}
}}",
"foo.java",
|metric| {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 4.0,
"average": null,
"min": 4.0,
"average": 4.0,
"min": 0.0,
"max": 4.0
}"###
);
Expand All @@ -1835,7 +1839,8 @@ mod tests {
#[test]
fn java_switch_statement() {
check_metrics::<JavaParser>(
"public static void print(Boolean a, Boolean b, Boolean c, Boolean d){ // +1
"class X {
public static void print(Boolean a, Boolean b, Boolean c, Boolean d){ // +1
switch(expr){ //+1
case 1:
System.out.println(\"test1\");
Expand All @@ -1846,16 +1851,16 @@ mod tests {
default:
System.out.println(\"test\");
}
}",
}}",
"foo.java",
|metric| {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 1.0,
"average": null,
"min": 1.0,
"average": 1.0,
"min": 0.0,
"max": 1.0
}"###
);
Expand All @@ -1866,22 +1871,23 @@ mod tests {
#[test]
fn java_switch_expression() {
check_metrics::<JavaParser>(
"public static void print(Boolean a, Boolean b, Boolean c, Boolean d){ // +1
switch(expr){ // +1
case 1 -> System.out.println(\"test1\");
case 2 -> System.out.println(\"test2\");
default -> System.out.println(\"test\");
}
}",
"class X {
public static void print(Boolean a, Boolean b, Boolean c, Boolean d){ // +1
switch(expr){ // +1
case 1 -> System.out.println(\"test1\");
case 2 -> System.out.println(\"test2\");
default -> System.out.println(\"test\");
}
}}",
"foo.java",
|metric| {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 1.0,
"average": null,
"min": 1.0,
"average": 1.0,
"min": 0.0,
"max": 1.0
}"###
);
Expand All @@ -1892,24 +1898,25 @@ mod tests {
#[test]
fn java_not_booleans() {
check_metrics::<JavaParser>(
"public static void print(Boolean a, Boolean b, Boolean c, Boolean d){ // +1
"class X {
public static void print(Boolean a, Boolean b, Boolean c, Boolean d){ // +1
if (a && !(b && c)) { // +3 (+1 &&, +1 &&)
printf(\"test\");
}
}",
}}",
"foo.java",
|metric| {
insta::assert_json_snapshot!(
metric.cognitive,
@r###"
{
"sum": 3.0,
"average": null,
"min": 3.0,
"average": 3.0,
"min": 0.0,
"max": 3.0
}"###
);
},
);
}
}
}

0 comments on commit 9ef21cf

Please sign in to comment.