Skip to content

Commit

Permalink
Convert Leap analyzer unit tests to golden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderploegsma committed Jan 21, 2024
1 parent c9383c1 commit 17f0bda
Show file tree
Hide file tree
Showing 31 changed files with 269 additions and 63 deletions.
10 changes: 5 additions & 5 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
exit_code=0

# Iterate over all test directories
for test_dir in tests/*; do
test_dir_name=$(basename "${test_dir}")
for test_dir in $(find tests -name expected_analysis.json | rev | cut -d '/' -f 2- | rev); do
test_dir_path=$(realpath "${test_dir}")
test_slug=$(echo "${test_dir}" | awk -F/ '{ print $2 }')

bin/run.sh "${test_dir_name}" "${test_dir_path}/" "${test_dir_path}/"
bin/run.sh "${test_slug}" "${test_dir_path}/" "${test_dir_path}/"

for file in analysis.json tags.json; do
expected_file="expected_${file}"
echo "${test_dir_name}: comparing ${file} to ${expected_file}"
echo "${test_dir}: comparing ${file} to ${expected_file}"

if ! diff "${test_dir_path}/${file}" "${test_dir_path}/${expected_file}"; then
exit_code=1
fi
done
done

exit ${exit_code}
exit ${exit_code}
51 changes: 0 additions & 51 deletions src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/resources/analyzer/exercises/leap/UsesJavaTime.java

This file was deleted.

29 changes: 29 additions & 0 deletions tests/leap/hard-coded-test-cases/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
14 changes: 14 additions & 0 deletions tests/leap/hard-coded-test-cases/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{"comments": [
{
"comment": "java.general.avoid_hard_coded_test_cases",
"type": "essential"
},
{
"comment": "java.leap.use_minimum_number_of_checks",
"type": "actionable"
},
{
"comment": "java.general.feedback_request",
"type": "informative"
}
]}
File renamed without changes.
29 changes: 29 additions & 0 deletions tests/leap/optimal-solution/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
1 change: 1 addition & 0 deletions tests/leap/optimal-solution/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions tests/leap/optimal-solution/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
29 changes: 29 additions & 0 deletions tests/leap/using-gregorian-calendar/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
File renamed without changes.
1 change: 1 addition & 0 deletions tests/leap/using-gregorian-calendar/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
29 changes: 29 additions & 0 deletions tests/leap/using-if-statements/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
10 changes: 10 additions & 0 deletions tests/leap/using-if-statements/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"comments": [
{
"comment": "java.leap.avoid_conditional_logic",
"type": "actionable"
},
{
"comment": "java.general.feedback_request",
"type": "informative"
}
]}
1 change: 1 addition & 0 deletions tests/leap/using-if-statements/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
29 changes: 29 additions & 0 deletions tests/leap/using-java-time/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
10 changes: 10 additions & 0 deletions tests/leap/using-java-time/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"comments": [
{
"comment": "java.leap.no_built_in_methods",
"type": "essential"
},
{
"comment": "java.general.feedback_request",
"type": "informative"
}
]}
1 change: 1 addition & 0 deletions tests/leap/using-java-time/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
File renamed without changes.
29 changes: 29 additions & 0 deletions tests/leap/using-ternary/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
10 changes: 10 additions & 0 deletions tests/leap/using-ternary/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"comments": [
{
"comment": "java.leap.avoid_conditional_logic",
"type": "actionable"
},
{
"comment": "java.general.feedback_request",
"type": "informative"
}
]}
1 change: 1 addition & 0 deletions tests/leap/using-ternary/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
29 changes: 29 additions & 0 deletions tests/leap/using-too-many-checks/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"authors": [
"sonapraneeth-a"
],
"contributors": [
"jmrunkle",
"lemoncurry",
"msomji",
"muzimuzhi",
"sshine"
],
"files": {
"solution": [
"src/main/java/Leap.java"
],
"test": [
"src/test/java/LeapTest.java"
],
"example": [
".meta/src/reference/java/Leap.java"
],
"invalidator": [
"build.gradle"
]
},
"blurb": "Determine whether a given year is a leap year.",
"source": "CodeRanch Cattle Drive, Assignment 3",
"source_url": "https://coderanch.com/t/718816/Leap"
}
10 changes: 10 additions & 0 deletions tests/leap/using-too-many-checks/expected_analysis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"comments": [
{
"comment": "java.leap.use_minimum_number_of_checks",
"type": "actionable"
},
{
"comment": "java.general.feedback_request",
"type": "informative"
}
]}
1 change: 1 addition & 0 deletions tests/leap/using-too-many-checks/expected_tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 17f0bda

Please sign in to comment.