-
Notifications
You must be signed in to change notification settings - Fork 26
Add operator #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add operator #277
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ce44a11
Move operators tests into a separate folder
CaelmBleidd ba6d4a5
Add support
CaelmBleidd c212059
Fake objects support in addiction
CaelmBleidd da96668
fix
CaelmBleidd 154e7dd
Version with bug in the model
CaelmBleidd ef92eb9
Fix
CaelmBleidd b68a31f
Remove asserts from binary operators resolution
CaelmBleidd c0b2730
Add test
CaelmBleidd 8bcb369
Fix eof
CaelmBleidd a065715
fix test
CaelmBleidd db150d4
Format
Lipen 0f11650
Fix review requests
CaelmBleidd b5ec561
Fix compilation error
CaelmBleidd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
343 changes: 302 additions & 41 deletions
343
usvm-ts/src/main/kotlin/org/usvm/machine/operator/TsBinaryOperator.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| package org.usvm.samples.operators | ||
|
|
||
| import org.jacodb.ets.model.EtsScene | ||
| import org.usvm.api.TsTestValue | ||
| import org.usvm.util.TsMethodTestRunner | ||
| import org.usvm.util.toDouble | ||
| import kotlin.test.Test | ||
|
|
||
| class Add : TsMethodTestRunner() { | ||
| private val className = this::class.simpleName!! | ||
|
|
||
| override val scene: EtsScene = loadSampleScene(className, folderPrefix = "operators") | ||
|
|
||
| @Test | ||
| fun `bool + bool`() { | ||
| val method = getMethod(className, "addBoolAndBool") | ||
| discoverProperties<TsTestValue.TsBoolean, TsTestValue.TsBoolean, TsTestValue.TsNumber>( | ||
| method = method, | ||
| { a, b, r -> r.number == 1.0 && !a.value && !b.value }, | ||
| { a, b, r -> r.number == 2.0 && !a.value && b.value }, | ||
| { a, b, r -> r.number == 3.0 && a.value && !b.value }, | ||
| { a, b, r -> r.number == 4.0 && a.value && b.value }, | ||
| invariants = arrayOf( | ||
| { _, _, r -> r.number != -1.0 } | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `bool + number`() { | ||
| val method = getMethod(className, "addBoolAndNumber") | ||
| discoverProperties<TsTestValue.TsBoolean, TsTestValue.TsNumber, TsTestValue.TsNumber>( | ||
| method = method, | ||
| { a, b, r -> r.number == 1.0 && a.value && b.number == -1.0 }, | ||
| { a, b, r -> r.number == 2.0 && !a.value && b.number == 0.0 }, | ||
| { a, b, r -> r.number == 3.0 && a.value && b.number == 5.0 }, | ||
| { _, b, r -> r.number.isNaN() && b.number.isNaN() }, | ||
| { a, b, r -> | ||
| val result = a.value.toDouble() + b.number | ||
| r.number == 4.0 && result != 2.2 && !result.isNaN() | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `number + number`() { | ||
| val method = getMethod(className, "addNumberAndNumber") | ||
| discoverProperties<TsTestValue.TsNumber, TsTestValue.TsNumber, TsTestValue.TsNumber>( | ||
| method = method, | ||
| { a, b, r -> a.number.isNaN() && r.number.isNaN() }, | ||
| { a, b, r -> !a.number.isNaN() && b.number.isNaN() && r.number.isNaN() }, | ||
| { a, b, r -> a.number + b.number == r.number }, | ||
| { a, b, r -> !a.number.isNaN() && !b.number.isNaN() && r.number == 0.0 }, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `number + undefined`() { | ||
| val method = getMethod(className, "addNumberAndUndefined") | ||
| discoverProperties<TsTestValue.TsNumber, TsTestValue.TsNumber>( | ||
| method = method, | ||
| invariants = arrayOf( | ||
| { a, r -> r.number != -1.0 }, | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `number + null`() { | ||
| val method = getMethod(className, "addNumberAndNull") | ||
| discoverProperties<TsTestValue.TsNumber, TsTestValue.TsNumber>( | ||
| method = method, | ||
| { a, r -> a.number.isNaN() && r.number.isNaN() }, | ||
| { a, r -> !a.number.isNaN() && r.number == a.number }, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `add unknown values`() { | ||
| val method = getMethod(className, "addUnknownValues") | ||
| discoverProperties<TsTestValue, TsTestValue, TsTestValue.TsNumber>( | ||
| method = method, | ||
| { a, b, r -> a is TsTestValue.TsUndefined || b is TsTestValue.TsUndefined && r.number.isNaN() }, | ||
| { a, b, r -> | ||
| (a is TsTestValue.TsClass | ||
| || b is TsTestValue.TsClass | ||
| || (a as? TsTestValue.TsNumber)?.number?.isNaN() == true | ||
| || (b as? TsTestValue.TsNumber)?.number?.isNaN() == true) | ||
| && r.number.isNaN() | ||
| }, | ||
| { a, b, r -> r.number == 7.0 }, | ||
| { a, b, r -> a is TsTestValue.TsNull && b is TsTestValue.TsNull && r.number == 0.0 }, | ||
| { a, b, r -> r.number == 42.0 } | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package org.usvm.util | ||
|
|
||
|
|
||
| fun Boolean.toDouble() = if (this) 1.0 else 0.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| class Add { | ||
| addBoolAndBool(a: boolean, b: boolean): number { | ||
| res = a + b; | ||
|
|
||
| if (res == 0 && (a || b)) return -1 // unreachable | ||
| if (res < 0 || res > 2) return -1 // unreachable | ||
| if (res == 1 && a && b) return -1 // unreachable | ||
| if (res == 2 && !(a && b)) return -1 // unreachable | ||
|
|
||
| if (res == 0) return 1 // false false | ||
| if (res == 1 && !a) return 2 // false true | ||
| if (res == 1 && !b) return 3 // true false | ||
| if (res == 2) return 4 // true true | ||
|
|
||
| return -1 // unreachable | ||
| } | ||
|
|
||
| addBoolAndNumber(a: boolean, b: number): number { | ||
| res = a + b; | ||
|
|
||
| if (res == 0 && a) return 1 // true -1 | ||
| if (res == 0 && !a) return 2 // false 0 | ||
|
|
||
| if (res == 6 && a) return 3 | ||
|
|
||
| if (b != b) return res // _ NaN | ||
|
|
||
| return 4 | ||
| } | ||
|
|
||
| addNumberAndNumber(a: number, b: number): number { | ||
| res = a + b; | ||
|
|
||
| if (a != a) return res | ||
| if (b != b) return res | ||
|
|
||
| if (res == 1.1) return res | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| addNumberAndUndefined(a: number): number { | ||
| res = a + undefined; | ||
|
|
||
| if (res == 0) return -1 // unreachable | ||
|
|
||
| return res | ||
| } | ||
|
|
||
| addNumberAndNull(a: number): number { | ||
| res = a + null; | ||
|
|
||
| if (res != a) return res | ||
|
|
||
| return res | ||
| } | ||
|
|
||
| addUnknownValues(a, b) { | ||
| res = a + b; | ||
|
|
||
| if (a === undefined || b === undefined) return res | ||
|
|
||
| if (res != res) return res | ||
|
|
||
| if (res == 7) return res | ||
|
|
||
| if (a === null && b === null) return res | ||
|
|
||
| return 42 | ||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.