Skip to content

Commit

Permalink
added JUnit5 variations of the testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwinOlie2 committed Nov 2, 2023
1 parent ac05b42 commit a8289fc
Show file tree
Hide file tree
Showing 110 changed files with 2,406 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/example-all-fail-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm") version "1.9.0"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("passed", "failed", "skipped")
}
}
61 changes: 61 additions & 0 deletions tests/example-all-fail-junit5/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": 2,
"status": "fail",
"message": "",
"tests": [
{
"name": "divisible by 400 but not by 125",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 100, not divisible by 400",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 400",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "not divisible by 4",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 2, not divisible by 4",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 4 and 5",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 4, not divisible by 100",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 200, not divisible by 400",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
},
{
"name": "divisible by 100 but not by 3",
"status": "fail",
"message": "expected: <false> but was: <true>",
"output": ""
}
]
}
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/example-all-fail-junit5/src/main/kotlin/Leap.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data class Year(private val year: Int) {
val isLeap: Boolean by lazy { ! (divisibleBy(4) && (divisibleBy(400) || !divisibleBy(100))) }

private fun divisibleBy(i: Int) = year % i == 0
}
45 changes: 45 additions & 0 deletions tests/example-all-fail-junit5/src/test/kotlin/LeapTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue

class LeapTest {
@Test
fun `not divisible by 4`() = assertYearIsCommon(2015)

@Disabled
@Test
fun `divisible by 2, not divisible by 4`() = assertYearIsCommon(1970)

@Disabled
@Test
fun `divisible by 4, not divisible by 100`() = assertYearIsLeap(1996)

@Disabled
@Test
fun `divisible by 4 and 5`() = assertYearIsLeap(1960)

@Disabled
@Test
fun `divisible by 100, not divisible by 400`() = assertYearIsCommon(2100)

@Disabled
@Test
fun `divisible by 100 but not by 3`() = assertYearIsCommon(1900)

@Disabled
@Test
fun `divisible by 400`() = assertYearIsLeap(2000)

@Disabled
@Test
fun `divisible by 400 but not by 125`() = assertYearIsLeap(2400)

@Disabled
@Test
fun `divisible by 200, not divisible by 400`() = assertYearIsCommon(1800)
}

private fun assertYearIsLeap(year: Int) = assertTrue(Year(year).isLeap)

private fun assertYearIsCommon(year: Int) = assertFalse(Year(year).isLeap)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/example-empty-file-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm") version "1.9.0"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("passed", "failed", "skipped")
}
}
6 changes: 6 additions & 0 deletions tests/example-empty-file-junit5/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 2,
"status": "error",
"message": "[ERROR] src/test/kotlin/LeapTest.kt:[43,54] Unresolved reference: Year\n[ERROR] src/test/kotlin/LeapTest.kt:[45,57] Unresolved reference: Year",
"tests": []
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions tests/example-empty-file-junit5/src/test/kotlin/LeapTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue

class LeapTest {
@Test
fun `not divisible by 4`() = assertYearIsCommon(2015)

@Disabled
@Test
fun `divisible by 2, not divisible by 4`() = assertYearIsCommon(1970)

@Disabled
@Test
fun `divisible by 4, not divisible by 100`() = assertYearIsLeap(1996)

@Disabled
@Test
fun `divisible by 4 and 5`() = assertYearIsLeap(1960)

@Disabled
@Test
fun `divisible by 100, not divisible by 400`() = assertYearIsCommon(2100)

@Disabled
@Test
fun `divisible by 100 but not by 3`() = assertYearIsCommon(1900)

@Disabled
@Test
fun `divisible by 400`() = assertYearIsLeap(2000)

@Disabled
@Test
fun `divisible by 400 but not by 125`() = assertYearIsLeap(2400)

@Disabled
@Test
fun `divisible by 200, not divisible by 400`() = assertYearIsCommon(1800)
}

private fun assertYearIsLeap(year: Int) = assertTrue(Year(year).isLeap)

private fun assertYearIsCommon(year: Int) = assertFalse(Year(year).isLeap)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
23 changes: 23 additions & 0 deletions tests/example-partial-fail-junit5/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"blurb": "Given a year, report if it is a leap year.",
"authors": ["sdavids13"],
"contributors": [
"dector",
"eparovyshnaya",
"jtigger",
"lihofm",
"mdowds",
"nithia",
"sjwarner-bp",
"SleeplessByte",
"stkent",
"uzilan"
],
"files": {
"solution": ["src/main/kotlin/Leap.kt"],
"test": ["src/test/kotlin/LeapTest.kt"],
"example": [".meta/src/reference/kotlin/Leap.kt"]
},
"source": "JavaRanch Cattle Drive, exercise 3",
"source_url": "http://www.javaranch.com/leap.jsp"
}
1 change: 1 addition & 0 deletions tests/example-partial-fail-junit5/.meta/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.6.0
22 changes: 22 additions & 0 deletions tests/example-partial-fail-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm") version "1.9.0"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

tasks.withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events("passed", "failed", "skipped")
}
}
61 changes: 61 additions & 0 deletions tests/example-partial-fail-junit5/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": 2,
"status": "fail",
"message": "",
"tests": [
{
"name": "divisible by 400 but not by 125",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "divisible by 100, not divisible by 400",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 400",
"status": "fail",
"message": "expected: <true> but was: <false>",
"output": ""
},
{
"name": "not divisible by 4",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 2, not divisible by 4",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 4 and 5",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 4, not divisible by 100",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 200, not divisible by 400",
"status": "pass",
"message": "",
"output": ""
},
{
"name": "divisible by 100 but not by 3",
"status": "pass",
"message": "",
"output": ""
}
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit a8289fc

Please sign in to comment.