Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Jul 17, 2024
1 parent 7706018 commit e79bd00
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions subprojects/common/analysis/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ dependencies {
implementation(project(":theta-graph-solver"))
implementation(project(mapOf("path" to ":theta-solver-z3-legacy")))
testImplementation(project(":theta-solver-z3-legacy"))
testImplementation(project(":theta-solver-z3"))
implementation("com.corundumstudio.socketio:netty-socketio:2.0.6")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024 Budapest University of Technology and Economics
*
* 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 hu.bme.mit.theta.analysis.algorithm

import hu.bme.mit.theta.analysis.algorithm.chc.HornChecker
import hu.bme.mit.theta.common.logging.NullLogger
import hu.bme.mit.theta.core.Relation
import hu.bme.mit.theta.core.decl.Decls.Param
import hu.bme.mit.theta.core.plus
import hu.bme.mit.theta.core.type.inttype.IntExprs.*
import hu.bme.mit.theta.solver.z3.Z3SolverFactory
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class HornTest {

@Test
fun testHornUnsafe() {
val inv = Relation("inv", Int())
val p0 = Param("P0", Int())
val p1 = Param("P1", Int())
inv(p0.ref) += Eq(p0.ref, Int(0))
inv(p1.ref) += inv(p0.ref).expr + Eq(p1.ref, Add(p0.ref, Int(1)))
!(inv(p0.ref) with Eq(p0.ref, Int(5)))

val checker = HornChecker(listOf(inv), Z3SolverFactory.getInstance(), NullLogger.getInstance())
Assertions.assertTrue(checker.check().isUnsafe)
}

@Test
fun testHornSafe() {
val inv = Relation("inv", Int())
val p0 = Param("P0", Int())
val p1 = Param("P1", Int())
inv(p0.ref) += Eq(p0.ref, Int(0))
inv(p1.ref) += inv(p0.ref).expr + Eq(p1.ref, Add(p0.ref, Int(2)))
!(inv(p0.ref) with Eq(p0.ref, Int(5)))

val checker = HornChecker(listOf(inv), Z3SolverFactory.getInstance(), NullLogger.getInstance())
Assertions.assertTrue(checker.check().isSafe)
}
}

0 comments on commit e79bd00

Please sign in to comment.