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

Add more array.sort test combination #68489

Conversation

DDolG
Copy link
Contributor

@DDolG DDolG commented Apr 25, 2022

Fixes: #41376

*Added tests for sorting arrays

*Separated tests for integer from string

*Added comments for integers and strings

EDIT (@krwq): Added Fixes ...

*Added tests for sorting arrays

*Separated tests for integer from string

*Added comments for integers and strings
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Apr 25, 2022
@dnfadmin
Copy link

dnfadmin commented Apr 25, 2022

CLA assistant check
All CLA requirements met.

@krwq
Copy link
Member

krwq commented Apr 25, 2022

@DDolG I assume this is fixing #41376 ? If so can you modify your PR description so that first line says "Fixes #41376" (this way merging PR automatically closes the issue)

@DDolG
Copy link
Contributor Author

DDolG commented Apr 25, 2022

@DDolG I assume this is fixing #41376 ? If so can you modify your PR description so that first line says "Fixes #41376" (this way merging PR automatically closes the issue)

I assume this is fixing #41376 ? Yes.
Thank you very much.
Thank you very much for your last comment. Very concise and understandable. I am very grateful to You.

@DDolG
Copy link
Contributor Author

DDolG commented Apr 26, 2022

@DDolG I assume this is fixing #41376 ? If so can you modify your PR description so that first line says "Fixes #41376" (this way merging PR automatically closes the issue)

Krzysztof I am very grateful to you for the feedback on the code.
Krzysztof, please tell me what these 6 spaces are for. I read the coding style guide, it doesn't say anything about it.

DDolG and others added 2 commits April 26, 2022 12:47
Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com>
Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com>
@krwq
Copy link
Member

krwq commented Apr 26, 2022

this was to align indentations of comments and code so they are the same across the file (in the very end of the coding style doc there is When editing files, keep new code and changes consistent with the style in the files. - not sure why it's in the very end considering it's probably one of the most important style rule 😄)

@DDolG
Copy link
Contributor Author

DDolG commented Apr 26, 2022

Thanks a lot. I began to understand.

@krwq
Copy link
Member

krwq commented Apr 26, 2022

I was thinking of good way to check this PR and here are my conclusions:

  • this PR does improve coverage
  • there is still lots of room for improvement here: i.e. we never hit heap sort cases for large arrays

Here is how you can check what's covered and what's not locally (after running build.cmd -rc Release -s clr+libs at least once from root of the repo):

  • go to src\libraries\System.Runtime\tests
  • run dotnet test /p:Outerloop=true /p:Coverage=true
  • after it's finished running somewhere in the bottom of the output you should see something along the lines of:
  2022-04-26T16:24:27: Writing report file 'd:\src\runtime\artifacts\bin\System.Runtime.Tests\Debug\net7.0-windows\TestResults\report\index.html'
  2022-04-26T16:24:28: Report generation took 8.5 seconds
  • open the path from the log, in my case it's d:\src\runtime\artifacts\bin\System.Runtime.Tests\Debug\net7.0-windows\TestResults\report\index.html
  • search for System.Array and click on link or alternatively directly open System.Private.CoreLib_Array.html from the same folder
  • search for method you'd like to increase coverage for (scroll to the bottom/search for or click on the method name on the right)
  • after you're done editing the test re-run the dotnet test .... command to re-generate report (might be a good idea to copy original report first for comparison) - make sure you've actually increased the coverage you planned

If you lack time I'm ok with merging this as is. Please let me know if you plan to further update the PR.

@DDolG
Copy link
Contributor Author

DDolG commented Apr 26, 2022

I was thinking of good way to check this PR and here are my conclusions:

  • this PR does improve coverage
  • there is still lots of room for improvement here: i.e. we never hit heap sort cases for large arrays

Here is how you can check what's covered and what's not locally (after running build.cmd -rc Release -s clr+libs at least once from root of the repo):

  • go to src\libraries\System.Runtime\tests
  • run dotnet test /p:Outerloop=true /p:Coverage=true
  • after it's finished running somewhere in the bottom of the output you should see something along the lines of:
  2022-04-26T16:24:27: Writing report file 'd:\src\runtime\artifacts\bin\System.Runtime.Tests\Debug\net7.0-windows\TestResults\report\index.html'
  2022-04-26T16:24:28: Report generation took 8.5 seconds
  • open the path from the log, in my case it's d:\src\runtime\artifacts\bin\System.Runtime.Tests\Debug\net7.0-windows\TestResults\report\index.html
  • search for System.Array and click on link or alternatively directly open System.Private.CoreLib_Array.html from the same folder
  • search for method you'd like to increase coverage for (scroll to the bottom/search for or click on the method name on the right)
  • after you're done editing the test re-run the dotnet test .... command to re-generate report (might be a good idea to copy original report first for comparison) - make sure you've actually increased the coverage you planned

If you lack time I'm ok with merging this as is. Please let me know if you plan to further update the PR.

I was thinking of good way to check this PR and here are my conclusions:

  • this PR does improve coverage
  • there is still lots of room for improvement here: i.e. we never hit heap sort cases for large arrays

Here is how you can check what's covered and what's not locally (after running build.cmd -rc Release -s clr+libs at least once from root of the repo):

  • go to src\libraries\System.Runtime\tests
  • run dotnet test /p:Outerloop=true /p:Coverage=true
  • after it's finished running somewhere in the bottom of the output you should see something along the lines of:
  2022-04-26T16:24:27: Writing report file 'd:\src\runtime\artifacts\bin\System.Runtime.Tests\Debug\net7.0-windows\TestResults\report\index.html'
  2022-04-26T16:24:28: Report generation took 8.5 seconds
  • open the path from the log, in my case it's d:\src\runtime\artifacts\bin\System.Runtime.Tests\Debug\net7.0-windows\TestResults\report\index.html
  • search for System.Array and click on link or alternatively directly open System.Private.CoreLib_Array.html from the same folder
  • search for method you'd like to increase coverage for (scroll to the bottom/search for or click on the method name on the right)
  • after you're done editing the test re-run the dotnet test .... command to re-generate report (might be a good idea to copy original report first for comparison) - make sure you've actually increased the coverage you planned

If you lack time I'm ok with merging this as is. Please let me know if you plan to further update the PR.

Krzysztof, you are absolutely right.
I'm confused by the moment that I can't see exactly how the sorting goes. I wanted to ask a question about how to check HeapSort. But I hesitated to ask a question. In my opinion, it is desirable to make maximum coverage with tests. I thought for a very long time how to write a test in order to check the HeapSort method. Didn't come up with anything. So I am very grateful to you for your help.

@DDolG
Copy link
Contributor Author

DDolG commented Apr 27, 2022

error create log 2
Unable to start testing with log generation.
I think to allocate sorting in a separate program to add logging there. And then form such a sequence that the HeapSort method is involved. Unfortunately, nothing better comes to mind.
Please tell me, if the sequence is large enough, will it need to be placed in another place?

@krwq
Copy link
Member

krwq commented Apr 27, 2022

@DDolG you;re seeing two issues there:

  • test failure - most likely caused by timeout (I cannot see the full log to tell which test) - it's possible this is preventing coverage report from being generated - I think this problem might be related to your local changes - try fixing it (or temporarily disabling failing test) and see if report gets generated before you try anything else
  • Html Logger Error - I'm not sure what that is but I think I've sometimes seen that locally and I believe it can be ignored

Can you save your local changes try doing git clean -fdx from the root of the repo, rebuild everything (build -rc Release -s clr+libs) and run test again with /p:Coverage=true and see if that still happens?

Please tell me, if the sequence is large enough, will it need to be placed in another place?

I'm not sure what sequence are you referring to. In general debugging through test might help you figure out how to hit specific place in the code (it might not be super trivial because of all of the if statements in the sorting code but it likely will be easier than guessing) - simply open project in VS and on the test explorer window search for test and right click and click Debug (make sure to put a breakpoint in the test first). Also if test is [Theory] you might want to comment out all cases but one since they run in parallel and that might make debugging much harder otherwise

@DDolG
Copy link
Contributor Author

DDolG commented Apr 28, 2022

Thank a lot. Awesome way to check test coverage.
Krzysztof I saw that there are methods that are not covered by tests.
I will try to cover these methods with tests.
Thank you very much for teaching me this technology.
image

@ghost
Copy link

ghost commented Apr 28, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes: #41376

*Added tests for sorting arrays

*Separated tests for integer from string

*Added comments for integers and strings

EDIT (@krwq): Added Fixes ...

Author: DDolG
Assignees: -
Labels:

area-System.Runtime, community-contribution

Milestone: -

@DDolG
Copy link
Contributor Author

DDolG commented Apr 29, 2022

Hello. Help me please. I have the impression that I'm not testing correctly.
I do testing according to the method written by Krzysztof. The output is a report. This report shows that the ArraySortHelper class is not covered by tests. Although if you separately debug each test, you can see that it enters the methods of this class.
image
System.Private.CoreLib_ArraySortHelper_1.zip

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Hello. Help me please. I have the impression that I'm not testing correctly.

Sorry we've not been able to jump back in and help here, @DDolG. Per @krwq's earlier comment, it's OK to merge this as-is without adding further coverage at this time though.

@jeffhandley jeffhandley merged commit 3c791e1 into dotnet:main Jun 24, 2022
@jeffhandley
Copy link
Member

Thanks for the contribution, @DDolG!

@DDolG
Copy link
Contributor Author

DDolG commented Jun 25, 2022

@jeffhandley thanks a lot. I am very grateful to you for the trust you have placed in me.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more Array.Sort test combinations, per #41234
5 participants