Skip to content

Commit

Permalink
Cleanup tests (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lipen authored Feb 20, 2025
1 parent 62f8400 commit 131e1c1
Show file tree
Hide file tree
Showing 31 changed files with 354 additions and 357 deletions.
98 changes: 50 additions & 48 deletions usvm-ts/src/test/kotlin/org/usvm/samples/And.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ private fun EtsMethodParameter.toRef(): EtsParameterRef {

class And : TsMethodTestRunner() {

private val className = this::class.simpleName!!

override val scene: EtsScene = run {
val name = "And.ts"
val name = "$className.ts"
val path = getResourcePath("/samples/$name")
val file = loadEtsFileAutoConvert(path)
EtsScene(listOf(file))
Expand All @@ -58,13 +60,13 @@ class And : TsMethodTestRunner() {

@Test
fun `test andOfBooleanAndBoolean`() {
val method = getMethod("And", "andOfBooleanAndBoolean")
val method = getMethod(className, "andOfBooleanAndBoolean")
discoverProperties<TsValue.TsBoolean, TsValue.TsBoolean, TsValue.TsNumber>(
method = method,
{ a, b, r -> a.value && b.value && r.number == 1.0 },
{ a, b, r -> a.value && !b.value && r.number == 2.0 },
{ a, b, r -> !a.value && b.value && r.number == 3.0 },
{ a, b, r -> !a.value && !b.value && r.number == 4.0 },
{ a, b, r -> a.value && b.value && (r.number == 1.0) },
{ a, b, r -> a.value && !b.value && (r.number == 2.0) },
{ a, b, r -> !a.value && b.value && (r.number == 3.0) },
{ a, b, r -> !a.value && !b.value && (r.number == 4.0) },
)
}

Expand Down Expand Up @@ -109,16 +111,16 @@ class And : TsMethodTestRunner() {

discoverProperties<TsValue.TsBoolean, TsValue.TsBoolean, TsValue.TsNumber>(
method = method,
{ a, b, r -> a.value && b.value && r.number == 1.0 },
{ a, b, r -> a.value && !b.value && r.number == 2.0 },
{ a, b, r -> !a.value && b.value && r.number == 3.0 },
{ a, b, r -> !a.value && !b.value && r.number == 4.0 },
{ a, b, r -> a.value && b.value && (r.number == 1.0) },
{ a, b, r -> a.value && !b.value && (r.number == 2.0) },
{ a, b, r -> !a.value && b.value && (r.number == 3.0) },
{ a, b, r -> !a.value && !b.value && (r.number == 4.0) },
)
}

@Test
fun `test andOfNumberAndNumber`() {
// val method = getMethod("And", "andOfNumberAndNumber")
// val method = getMethod(className, "andOfNumberAndNumber")
//
// andOfNumberAndNumber(a: number, b: number): number {
// if (a && b) return 1
Expand Down Expand Up @@ -234,21 +236,21 @@ class And : TsMethodTestRunner() {

discoverProperties<TsValue.TsNumber, TsValue.TsNumber, TsValue.TsNumber>(
method = method,
{ a, b, r -> isTruthy(a) && isTruthy(b) && r.number == 1.0 },
{ a, b, r -> isTruthy(a) && b.number.isNaN() && r.number == 2.0 },
{ a, b, r -> isTruthy(a) && b.number == 0.0 && r.number == 3.0 },
{ a, b, r -> a.number.isNaN() && isTruthy(b) && r.number == 4.0 },
{ a, b, r -> a.number.isNaN() && b.number.isNaN() && r.number == 5.0 },
{ a, b, r -> a.number.isNaN() && b.number == 0.0 && r.number == 6.0 },
{ a, b, r -> a.number == 0.0 && isTruthy(b) && r.number == 7.0 },
{ a, b, r -> a.number == 0.0 && b.number.isNaN() && r.number == 8.0 },
{ a, b, r -> a.number == 0.0 && b.number == 0.0 && r.number == 9.0 },
{ a, b, r -> isTruthy(a) && isTruthy(b) && (r.number == 1.0) },
{ a, b, r -> isTruthy(a) && b.number.isNaN() && (r.number == 2.0) },
{ a, b, r -> isTruthy(a) && (b.number == 0.0) && (r.number == 3.0) },
{ a, b, r -> a.number.isNaN() && isTruthy(b) && (r.number == 4.0) },
{ a, b, r -> a.number.isNaN() && b.number.isNaN() && (r.number == 5.0) },
{ a, b, r -> a.number.isNaN() && (b.number == 0.0) && (r.number == 6.0) },
{ a, b, r -> (a.number == 0.0) && isTruthy(b) && (r.number == 7.0) },
{ a, b, r -> (a.number == 0.0) && b.number.isNaN() && (r.number == 8.0) },
{ a, b, r -> (a.number == 0.0) && (b.number == 0.0) && (r.number == 9.0) },
)
}

@Test
fun `test andOfBooleanAndNumber`() {
// val method = getMethod("And", "andOfBooleanAndNumber")
// val method = getMethod(className, "andOfBooleanAndNumber")
//
// andOfBooleanAndNumber(a: boolean, b: number): number {
// if (a && b) return 1
Expand Down Expand Up @@ -337,18 +339,18 @@ class And : TsMethodTestRunner() {

discoverProperties<TsValue.TsBoolean, TsValue.TsNumber, TsValue.TsNumber>(
method = method,
{ a, b, r -> a.value && isTruthy(b) && r.number == 1.0 },
{ a, b, r -> a.value && b.number.isNaN() && r.number == 2.0 },
{ a, b, r -> a.value && b.number == 0.0 && r.number == 3.0 },
{ a, b, r -> !a.value && isTruthy(b) && r.number == 4.0 },
{ a, b, r -> !a.value && b.number.isNaN() && r.number == 5.0 },
{ a, b, r -> !a.value && b.number == 0.0 && r.number == 6.0 },
{ a, b, r -> a.value && isTruthy(b) && (r.number == 1.0) },
{ a, b, r -> a.value && b.number.isNaN() && (r.number == 2.0) },
{ a, b, r -> a.value && (b.number == 0.0) && (r.number == 3.0) },
{ a, b, r -> !a.value && isTruthy(b) && (r.number == 4.0) },
{ a, b, r -> !a.value && b.number.isNaN() && (r.number == 5.0) },
{ a, b, r -> !a.value && (b.number == 0.0) && (r.number == 6.0) },
)
}

@Test
fun `test andOfNumberAndBoolean`() {
// val method = getMethod("And", "andOfNumberAndBoolean")
// val method = getMethod(className, "andOfNumberAndBoolean")
//
// andOfNumberAndBoolean(a: number, b: boolean): number {
// if (a && b) return 1
Expand Down Expand Up @@ -437,74 +439,74 @@ class And : TsMethodTestRunner() {

discoverProperties<TsValue.TsNumber, TsValue.TsBoolean, TsValue.TsNumber>(
method = method,
{ a, b, r -> isTruthy(a) && b.value && r.number == 1.0 },
{ a, b, r -> isTruthy(a) && !b.value && r.number == 2.0 },
{ a, b, r -> a.number.isNaN() && b.value && r.number == 3.0 },
{ a, b, r -> a.number.isNaN() && !b.value && r.number == 4.0 },
{ a, b, r -> a.number == 0.0 && b.value && r.number == 5.0 },
{ a, b, r -> a.number == 0.0 && !b.value && r.number == 6.0 },
{ a, b, r -> isTruthy(a) && b.value && (r.number == 1.0) },
{ a, b, r -> isTruthy(a) && !b.value && (r.number == 2.0) },
{ a, b, r -> a.number.isNaN() && b.value && (r.number == 3.0) },
{ a, b, r -> a.number.isNaN() && !b.value && (r.number == 4.0) },
{ a, b, r -> (a.number == 0.0) && b.value && (r.number == 5.0) },
{ a, b, r -> (a.number == 0.0) && !b.value && (r.number == 6.0) },
)
}

@Test
@Disabled("Does not work because objects cannot be null")
fun `test andOfObjectAndObject`() {
val method = getMethod("And", "andOfObjectAndObject")
val method = getMethod(className, "andOfObjectAndObject")
discoverProperties<TsValue.TsClass, TsValue.TsClass, TsValue.TsNumber>(
method = method,
{ a, b, r -> isTruthy(a) && isTruthy(b) && r.number == 1.0 },
{ a, b, r -> isTruthy(a) && !isTruthy(b) && r.number == 2.0 },
{ a, b, r -> !isTruthy(a) && isTruthy(b) && r.number == 3.0 },
{ a, b, r -> !isTruthy(a) && !isTruthy(b) && r.number == 4.0 },
{ a, b, r -> isTruthy(a) && isTruthy(b) && (r.number == 1.0) },
{ a, b, r -> isTruthy(a) && !isTruthy(b) && (r.number == 2.0) },
{ a, b, r -> !isTruthy(a) && isTruthy(b) && (r.number == 3.0) },
{ a, b, r -> !isTruthy(a) && !isTruthy(b) && (r.number == 4.0) },
)
}

@Test
fun `test andOfUnknown`() {
val method = getMethod("And", "andOfUnknown")
val method = getMethod(className, "andOfUnknown")
discoverProperties<TsValue, TsValue, TsValue.TsNumber>(
method = method,
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
a.value && b.value && r.number == 1.0
a.value && b.value && (r.number == 1.0)
} else true
},
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
a.value && !b.value && r.number == 2.0
a.value && !b.value && (r.number == 2.0)
} else true
},
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
!a.value && b.value && r.number == 3.0
!a.value && b.value && (r.number == 3.0)
} else true
},
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
!a.value && !b.value && r.number == 4.0
!a.value && !b.value && (r.number == 4.0)
} else true
},
)
}

@Test
fun `test truthyUnknown`() {
val method = getMethod("And", "truthyUnknown")
val method = getMethod(className, "truthyUnknown")
discoverProperties<TsValue, TsValue, TsValue.TsNumber>(
method = method,
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
a.value && !b.value && r.number == 1.0
a.value && !b.value && (r.number == 1.0)
} else true
},
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
!a.value && b.value && r.number == 2.0
!a.value && b.value && (r.number == 2.0)
} else true
},
{ a, b, r ->
if (a is TsValue.TsBoolean && b is TsValue.TsBoolean) {
!a.value && !b.value && r.number == 99.0
!a.value && !b.value && (r.number == 99.0)
} else true
},
)
Expand Down
60 changes: 0 additions & 60 deletions usvm-ts/src/test/kotlin/org/usvm/samples/Arguments.kt

This file was deleted.

23 changes: 13 additions & 10 deletions usvm-ts/src/test/kotlin/org/usvm/samples/Arrays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import org.usvm.util.TsMethodTestRunner
import org.usvm.util.getResourcePath

class Arrays : TsMethodTestRunner() {

private val className = this::class.simpleName!!

override val scene: EtsScene = run {
val name = "Arrays.ts"
val name = "$className.ts"
val path = getResourcePath("/samples/$name")
val file = loadEtsFileAutoConvert(path)
EtsScene(listOf(file))
}

@Test
fun testCreateConstantArrayOfNumbers() {
val method = getMethod("Arrays", "createConstantArrayOfNumbers")
val method = getMethod(className, "createConstantArrayOfNumbers")
discoverProperties<TsValue.TsNumber>(
method = method,
{ r -> r.number == 1.0 },
Expand All @@ -29,7 +32,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testCreateAndReturnConstantArrayOfNumbers() {
val method = getMethod("Arrays", "createAndReturnConstantArrayOfNumbers")
val method = getMethod(className, "createAndReturnConstantArrayOfNumbers")
discoverProperties<TsValue.TsArray<TsValue.TsNumber>>(
method = method,
{ r -> r.values.map { it.number } == listOf(1.0, 2.0, 3.0) },
Expand All @@ -38,7 +41,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testCreateAndAccessArrayOfBooleans() {
val method = getMethod("Arrays", "createAndAccessArrayOfBooleans")
val method = getMethod(className, "createAndAccessArrayOfBooleans")
discoverProperties<TsValue.TsNumber>(
method = method,
{ r -> r.number == 1.0 },
Expand All @@ -50,7 +53,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testCreateArrayOfBooleans() {
val method = getMethod("Arrays", "createArrayOfBooleans")
val method = getMethod(className, "createArrayOfBooleans")
discoverProperties<TsValue.TsArray<TsValue.TsBoolean>>(
method = method,
{ r -> r.values.map { it.value } == listOf(true, false, true) },
Expand All @@ -59,7 +62,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testCreateMixedArray() {
val method = getMethod("Arrays", "createMixedArray")
val method = getMethod(className, "createMixedArray")
discoverProperties<TsValue.TsArray<*>>(
method = method,
{ r ->
Expand All @@ -74,7 +77,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testCreateArrayOfUnknownValues() {
val method = getMethod("Arrays", "createArrayOfUnknownValues")
val method = getMethod(className, "createArrayOfUnknownValues")
discoverProperties<TsValue, TsValue, TsValue, TsValue.TsArray<*>>(
method = method,
{ a, _, _, r -> r.values[0] == a && (a as TsValue.TsNumber).number == 1.1 },
Expand All @@ -88,7 +91,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testCreateArrayOfNumbersAndPutDifferentTypes() {
val method = getMethod("Arrays", "createArrayOfNumbersAndPutDifferentTypes")
val method = getMethod(className, "createArrayOfNumbersAndPutDifferentTypes")
discoverProperties<TsValue.TsArray<*>>(
method = method,
{ r ->
Expand All @@ -103,7 +106,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testAllocatedArrayLengthExpansion() {
val method = getMethod("Arrays", "allocatedArrayLengthExpansion")
val method = getMethod(className, "allocatedArrayLengthExpansion")
discoverProperties<TsValue.TsArray<*>>(
method = method,
{ r ->
Expand All @@ -120,7 +123,7 @@ class Arrays : TsMethodTestRunner() {

@Test
fun testWriteInTheIndexEqualToLength() {
val method = getMethod("Arrays", "writeInTheIndexEqualToLength")
val method = getMethod(className, "writeInTheIndexEqualToLength")
discoverProperties<TsValue.TsArray<TsValue.TsNumber>>(
method = method,
{ r -> r.values.map { it.number } == listOf(1.0, 2.0, 3.0, 4.0) },
Expand Down
8 changes: 5 additions & 3 deletions usvm-ts/src/test/kotlin/org/usvm/samples/Call.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import org.usvm.util.getResourcePath

class Call : TsMethodTestRunner() {

private val className = this::class.simpleName!!

override val scene: EtsScene = run {
val name = "Call.ts"
val name = "$className.ts"
val path = getResourcePath("/samples/$name")
val file = loadEtsFileAutoConvert(path)
EtsScene(listOf(file))
}

@Test
fun `test simpleCall`() {
val method = getMethod("Call", "simpleCall")
val method = getMethod(className, "simpleCall")
discoverProperties<TsValue.TsNumber>(
method = method,
{ r -> r.number == 42.0 },
Expand All @@ -27,7 +29,7 @@ class Call : TsMethodTestRunner() {

@Test
fun `test fib`() {
val method = getMethod("Call", "fib")
val method = getMethod(className, "fib")
discoverProperties<TsValue.TsNumber, TsValue.TsNumber>(
method = method,
{ n, r -> n.number.isNaN() && r.number == 0.0 },
Expand Down
Loading

0 comments on commit 131e1c1

Please sign in to comment.