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

Unit tests for Utils.concat() #7918

Merged
merged 6 commits into from
Jun 30, 2022
Merged

Unit tests for Utils.concat() #7918

merged 6 commits into from
Jun 30, 2022

Conversation

orlicohen
Copy link
Contributor

Fixes #7916. Data providers and unit tests for the various overloads of Utils.concat()

@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Merging #7918 (7c5025c) into master (e81a361) will increase coverage by 0.101%.
The diff coverage is 84.615%.

@@               Coverage Diff               @@
##              master     #7918       +/-   ##
===============================================
+ Coverage     86.981%   87.082%   +0.101%     
+ Complexity     36962     36961        -1     
===============================================
  Files           2221      2215        -6     
  Lines         173894    173717      -177     
  Branches       18785     18778        -7     
===============================================
+ Hits          151254    151276       +22     
+ Misses         15998     15816      -182     
+ Partials        6642      6625       -17     
Impacted Files Coverage Δ
...broadinstitute/hellbender/utils/UtilsUnitTest.java 93.151% <84.615%> (-0.458%) ⬇️
...on/MultisampleMultidimensionalKernelSegmenter.java 89.375% <0.000%> (-4.375%) ⬇️
...lkers/vqsr/VariantRecalibratorIntegrationTest.java 98.315% <0.000%> (-0.481%) ⬇️
...s/copynumber/models/AlleleFractionLikelihoods.java 100.000% <0.000%> (ø)
...s/solver/SynchronizedUnivariateSolverUnitTest.java
...bender/utils/solver/RobustBrentSolverUnitTest.java
...ute/hellbender/utils/solver/RobustBrentSolver.java
...r/utils/solver/UnivariateSolverSpecifications.java
...der/utils/solver/SynchronizedUnivariateSolver.java
...r/utils/solver/UnivariateSolverJobDescription.java
... and 22 more

Copy link
Contributor

@droazen droazen left a comment

Choose a reason for hiding this comment

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

@orlicohen Looks good, just a few minor changes needed

new Object[]{ new byte[] {100, 100}, new byte[] {100, 100}, new byte[] { } },
new Object[]{ ArrayUtils.EMPTY_BYTE_ARRAY, new byte[] { }, new byte[] { } },
new Object[]{ new byte[] {100, 100, 100, 100}, new byte[] {100, 100}, new byte[] {100, 100} },
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments on the test cases for the varargs version of concat():

  • Calling concat() with 2 byte arrays actually calls the two-arg specialization of concat(), not the varargs version, so none of your test cases here should have 2 input arrays. Call concat() with 0, 1, or 3+ arrays to test the varargs version.
  • The values inside your arrays should not all be the same (100), otherwise you are not actually testing whether the method is preserving the original order of the values correctly during concatenation.

new Object[]{ new byte[] { }, new byte[] { }, ArrayUtils.EMPTY_BYTE_ARRAY },
new Object[]{ new byte[] {100, 100}, new byte[] { }, new byte[] {100, 100} },
new Object[]{ new byte[] { }, new byte[] {100, 100}, new byte[] {100, 100} },
new Object[]{ new byte[] {100, 100}, new byte[] {100, 100}, new byte[] {100, 100, 100, 100} },
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments on the test cases for the two-arg version of concat():

  • As above, the values inside your arrays should not all be the same (100), otherwise you are not actually testing whether the method is preserving the original order of the values correctly during concatenation.
  • Include at least one additional test case involving an array of length 1, as that is a common edge case for methods like this.

new Integer[] {4, 5, 6} },
new Object[]{ new Integer[] {1, 2, 3}, new Integer[] {4, 5, 6}, (IntFunction<Integer[]>)Integer[]::new,
new Integer[] {1, 2, 3, 4, 5, 6} },
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments on the test cases for the generic version of concat():

  • Include an additional test case with { 4, 5, 6 } and { 1, 2, 3 } passed in the reverse order, giving { 4, 5, 6, 1, 2, 3 }. This will demonstrate that the method is preserving input order correctly and not doing something silly like sorting the values during concatenation.


@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "concatAnyTypeWithNullArrayData")
public void testConcatAnyTypeWithNullArray(Integer[] arr1, Integer[] arr2, IntFunction<Integer[]> constructor){
Utils.concat(arr1, arr2, constructor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Null tests look good 👍

@@ -28,7 +30,8 @@
* Testing framework for general purpose utilities class.
*
*/
public final class UtilsUnitTest extends GATKBaseTest {
public final class
UtilsUnitTest extends GATKBaseTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Class name should be on the same line as the declaration

@droazen droazen assigned orlicohen and unassigned droazen Jun 28, 2022
@orlicohen orlicohen requested a review from droazen June 28, 2022 18:10
Copy link
Contributor

@droazen droazen left a comment

Choose a reason for hiding this comment

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

@orlicohen Two quick remaining comments, then this should be good to go

new Object[]{ new byte[] {100, 100}, new byte[] {100, 100} },
new Object[]{ new byte[] {100, 100, 10, 10}, new byte[] {100, 100}, new byte[] { }, new byte[] {10,10} },
new Object[]{ ArrayUtils.EMPTY_BYTE_ARRAY, new byte[] { }, new byte[] { }, new byte[] { } },
new Object[]{ new byte[] {10, 10, 15, 15, 20, 20}, new byte[] {10, 10}, new byte[] {15, 15}, new byte[] {20, 20} },
Copy link
Contributor

Choose a reason for hiding this comment

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

This test case checks that the method is preserving the relative ordering of the separate byte arrays, but does not test whether the ordering within each array is also preserved. You can fix this by having the values within one of the arrays differ as well, and ideally not be sorted -- for example, changing the first array to { 12, 10 }

new Object[]{ new byte[] {10, 10}, new byte[] { }, new byte[] {10, 10} },
new Object[]{ new byte[] { }, new byte[] {10, 10}, new byte[] {10, 10} },
new Object[]{ new byte[] {10}, new byte[] {15, 15}, new byte[] {10, 15, 15} },
new Object[]{ new byte[] {10, 10}, new byte[] {15, 15}, new byte[] {10, 10, 15, 15} },
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here: change the first array to something like { 12, 10 } to demonstrate that ordering within each input array is being preserved.

@droazen droazen merged commit c40187a into master Jun 30, 2022
@droazen droazen deleted the oc_fixes7916_concatunittests branch June 30, 2022 18:40
orlicohen added a commit that referenced this pull request Jul 18, 2022
Added comprehensive unit tests for the various overloads of Utils.concat(), which were not previously covered by tests.

Resolves #7916
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The Utils.concat() methods need unit tests
2 participants