Skip to content

Commit

Permalink
Migrate test classes to Kotlin.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-rapp committed Aug 29, 2018
1 parent 308d927 commit 5a3f3bc
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 401 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation "com.github.michael-rapp:java-util:$version_java_util"
compile 'org.jetbrains:annotations:[15.0,16.0)'
compile 'org.slf4j:slf4j-api:[1.7,1.8)'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$version_kotlin"
testCompile 'junit:junit:[4.0,5.0)'
testCompile 'org.mockito:mockito-core:[2.8,2.9)'
testCompile 'ch.qos.logback:logback-classic:[1.2,1.3)'
Expand Down
84 changes: 0 additions & 84 deletions src/test/java/de/mrapp/apriori/metrics/ConfidenceTest.java

This file was deleted.

62 changes: 62 additions & 0 deletions src/test/java/de/mrapp/apriori/metrics/ConfidenceTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2017 Michael Rapp
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package de.mrapp.apriori.metrics

import de.mrapp.apriori.AssociationRule
import de.mrapp.apriori.ItemSet
import de.mrapp.apriori.NamedItem
import kotlin.test.Test
import kotlin.test.assertEquals

/**
* Tests the functionality of the class [Confidence].
*
* @author Michael Rapp
*/
class ConfidenceTest {

@Test
fun testEvaluate() {
val bodySupport = 0.7
val body = ItemSet<NamedItem>()
body.add(NamedItem("a"))
body.support = bodySupport
val head = ItemSet<NamedItem>()
head.add(NamedItem("b"))
val support = 0.5
val rule = AssociationRule(body, head, support)
assertEquals(support / bodySupport, Confidence().evaluate(rule))
}

@Test
fun testEvaluateDivisionByZero() {
val body = ItemSet<NamedItem>()
body.add(NamedItem("a"))
val head = ItemSet<NamedItem>()
head.add(NamedItem("b"))
val rule = AssociationRule(body, head, 0.5)
assertEquals(0.0, Confidence().evaluate(rule))
}

@Test
fun testMinValue() {
assertEquals(0.0, Confidence().minValue())
}

@Test
fun testMaxValue() {
assertEquals(1.0, Confidence().maxValue())
}

}
88 changes: 0 additions & 88 deletions src/test/java/de/mrapp/apriori/metrics/ConvictionTest.java

This file was deleted.

66 changes: 66 additions & 0 deletions src/test/java/de/mrapp/apriori/metrics/ConvictionTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2017 Michael Rapp
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package de.mrapp.apriori.metrics

import de.mrapp.apriori.AssociationRule
import de.mrapp.apriori.ItemSet
import de.mrapp.apriori.NamedItem
import kotlin.test.Test
import kotlin.test.assertEquals

/**
* Tests the functionality of the class [Conviction].
*
* @author Michael Rapp
*/
class ConvictionTest {

@Test
fun testEvaluate() {
val bodySupport = 0.7
val body = ItemSet<NamedItem>()
body.add(NamedItem("a"))
body.support = bodySupport
val headSupport = 0.8
val head = ItemSet<NamedItem>()
head.add(NamedItem("b"))
head.support = headSupport
val support = 0.5
val rule = AssociationRule(body, head, support)
val confidence = Confidence().evaluate(rule)
assertEquals((1 - headSupport) / (1 - confidence), Conviction().evaluate(rule))
}

@Test
fun testEvaluateDivisionByZero() {
val body = ItemSet<NamedItem>()
body.add(NamedItem("a"))
body.support = 0.5
val head = ItemSet<NamedItem>()
head.add(NamedItem("b"))
val rule = AssociationRule(body, head, 0.5)
assertEquals(0.0, Conviction().evaluate(rule))
}

@Test
fun testMinValue() {
assertEquals(0.0, Conviction().minValue())
}

@Test
fun testMaxValue() {
assertEquals(Double.MAX_VALUE, Conviction().maxValue())
}

}
73 changes: 0 additions & 73 deletions src/test/java/de/mrapp/apriori/metrics/LeverageTest.java

This file was deleted.

Loading

0 comments on commit 5a3f3bc

Please sign in to comment.