Skip to content
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

Refactoring in Summary Module #2425

Merged
merged 8 commits into from
Jul 20, 2023
Merged

Refactoring in Summary Module #2425

merged 8 commits into from
Jul 20, 2023

Conversation

sofurihafe
Copy link
Member

@sofurihafe sofurihafe commented Jul 18, 2023

Description

Fixes a bunch of bugs in Summary Module including refactoring.

This PR includes:

  • Fix: whole method body in display names (for switches, methods that throw exceptions)
  • Fix: whole method body in summary comment (for methods with else if)
  • Fix: wrong logic when, for example, n < 0 was considered as a place in code, not as a condition
  • Added new scenario for Summary generation of Switches, when exception was thrown in switch agrument (switch(argument))
  • Enh: instead of switch case: 'E' it was decided to add extra info, now it's switch(arg) case: 'E'

See #2322 (comment)

Also Fixes #2376

How to test

Automated tests

Added extra tests for Summary Module.

Manual tests

See #2322 (comment) to check that it was fixed.

@sofurihafe sofurihafe added comp-summaries Something related to the method names, code comments and display names generation ctg-bug-fix PR is fixing a bug labels Jul 19, 2023
@sofurihafe sofurihafe marked this pull request as ready for review July 19, 2023 13:31
@@ -37,19 +37,19 @@ class SummaryBinarySearchTest : SummaryTestCaseGeneratorTest(
"returns from: return right + 1;\n"
val summary5 = "Test invokes:\n" +
" org.utbot.examples.algorithms.BinarySearch#isUnsorted(long[]) once\n" +
"throws NullPointerException in: isUnsorted(array)\n"
"throws NullPointerException when: isUnsorted(array)\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have a function that does not return boolean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two possible cases: when we throw an exception somewhere (in this case we use "in" preposition) and when we throw depending on a condition (we use "when").

So, if isUnsorted(...) returns not a boolean, we will use "in" preposition.

@@ -12,7 +12,7 @@ class SummarySimpleClassExampleTest : SummaryTestCaseGeneratorTest(
@Test
fun testImmutableFieldAccess() {
val summary1 = "Test \n" +
"throws NullPointerException in: c.b == 10\n"
"throws NullPointerException when: c.b == 10\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question: what if it is not a condition statement, but just something else that contains exception?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After that, what is \n here and for what it is here?


val displayName1 = "switch(mode) case: FLOOR -> return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(x)"
val displayName2 = "switch(mode) case: CEILING -> return Integer.SIZE - Integer.numberOfLeadingZeros(x - 1)"
val displayName3 = "switch(mode) case: HALF_EVEN -> return logFloor + lessThanBranchFree(cmp, x)"
val displayName4 = "switch(mode) case: -> ThrowNullPointerException"
val displayName4 = "switch(mode) -> ThrowNullPointerException"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that case here is unknown, we can't determine it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we try to pass null in switch(...) as an argument, we get "ThrowNullPointerException".

In this case we don't proceed inside the switch and the reason of an exception is switch itself.

@EgorkaKulikov EgorkaKulikov self-requested a review July 20, 2023 07:53
Copy link
Collaborator

@EgorkaKulikov EgorkaKulikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a kind of genius work of digging in the shit!

@EgorkaKulikov EgorkaKulikov linked an issue Jul 20, 2023 that may be closed by this pull request
@EgorkaKulikov EgorkaKulikov enabled auto-merge (squash) July 20, 2023 07:54
@EgorkaKulikov EgorkaKulikov merged commit 231d9e0 into main Jul 20, 2023
28 checks passed
@EgorkaKulikov EgorkaKulikov deleted the andrey-t/summary_fixes branch July 20, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-summaries Something related to the method names, code comments and display names generation ctg-bug-fix PR is fixing a bug
Projects
None yet
2 participants