Report for Assignment 1
Group 2
Ava Frohna, Masha Micevska, Cecilia Terena, Irina Popovikj
Name: Leetcode
URL: https://github.com/fishercoder1534/Leetcode
Programming language: Java
Number of lines of code and the tool used to count it:
-
Lizard
-
87,519 lines

Coverage measurement
Existing tool
Tool used: Jacoco
Code
./gradlew test jacocoTestReport
cd build/reports/jacoco/test/html
open index.html

Branches in total have 10% coverage, 18,517 branches missed
Your own coverage tool
Masha
Function 1
-
maxOperations in file _3038.java
-
Coverage: 50%, 2/4 branches


- https://github.com/fishercoder1534/Leetcode/commit/415665a7479c258483cd44cf8cb72b153d1a9aa5
Function 2
-
divide in _29.java
-
Coverage: 43%, 3/7 branches


- https://github.com/fishercoder1534/Leetcode/commit/937ec78a2a4bca38cb63ebde10723838ab55c8c5
Ava
Function 1
-
swapPairs in file _24.java
-
Coverage: 66%, ⅔ branches


- https://github.com/fishercoder1534/Leetcode/commit/8da8f07239f26b5f02786062e781946c8926d29d
Function 2
-
maxArea in file _11.java
-
Coverage: 66%, ⅔ branches


- https://github.com/fishercoder1534/Leetcode/commit/877563fa16b08f393c33f6379b5a03172d14a309
Cecilia
Function 1
-
lengthOfLastWord in file _58.java
-
Coverage: 50%, ½ branches


- https://github.com/fishercoder1534/Leetcode/commit/2b5eb376bae41c3a13ecca52ded87bd424bc4517
Function 2
-
findMaxConsecutiveOnes in file _487.java
-
Coverage: 50%, 2/4 branches


- https://github.com/fishercoder1534/Leetcode/commit/77bdc0599994aa2668781505c3660270ef2bda15
Irina
Function 1
-
searchRange in file _34.java
-
Coverage: 22%, 2/9 branches


Function 2
-
lengthOfLongestSubstring in file _3.java
-
Coverage: 50%, ½ branches


Coverage improvement
Individual tests
Masha
Function 1
- maxOperations in file _3038.java

-
https://github.com/fishercoder1534/Leetcode/commit/38d599fd9f3fb7e724e9be7efa4396786d345ee7
-
The coverage improved from 50% (2/4 branches) to 100% (4/4) branches. The first test which was already written only covered branches 2 and 4 as it considered cases where the array length was at least 3 and the case where the sum of the pair did not equal the initial sum. The second test which I added covers the situation where nums is null and the third test where nums.length is less than 2. Tests 4, 5, and 6 cover multiple branches, where first pairs have equal sums and the second does not, where both pairs have equal sums, and where all pairs have equal sums, respectively.
Function 2
- divide in file _29.java

-
https://github.com/fishercoder1534/Leetcode/commit/ad04c750e9b34b4f0c253af956df5101c1db1ef3
-
The branch coverage improved from 43% to 100% with the addition of 6 tests. The first test covered branches 3, 5, and 6, as they covered cases where both the divided and the divisor are positive. The second test checks for a special overflow case, covering branch 1. The third test covers cases where both dividend and divisor are positive just like test 1. Test 4 checks the case where the dividend is negative but the divisor is positive, covering branches 2, 5, 6, and 7. Test 5 covers cases where the dividend is positive but the divisor is negative, covering branches 3, 4, 6, and 7. Test 6 covers cases where both numbers are negative (branches 2, 4, and 6). Test 7 covers branches 2, 5, 6, and 7 with a negative divided and positive divisor, where multiple loop iterations are required. And finally test 8 covers the case where the dividend is 0, covering branches 3 and 5.
Ava
Function 1
- swapPairs in file _24Test.java

-
https://github.com/fishercoder1534/Leetcode/commit/26abc5dac82e73ffc3948aa6d762f74de1dc007c
-
I added test 3 which during the third iteration, the head points to the last node. When head.next is set it is null since there is not another node. This causes the code to enter the if loop if (second == null) which covers the only flag that was not hit. The test has an odd number of nodes which means the last iteration of the loop will have second == null.
Function 2
- maxArea in file _11Test.java

-
https://github.com/fishercoder1534/Leetcode/commit/d5c5709cf8f96d5ed360c518a1b088b4f5472459
-
I added test 2 which during the third iteration of the while loop, the left has a height of 4 and the right has a height of 3. Meaning height(left) > height(right) therefore it goes to the else branch hitting flag 3 making the coverage increase from 66% to 100%.
Cecilia
Function 1:
- lengthOfLastWord in file _58.java

-
https://github.com/fishercoder1534/Leetcode/commit/edb5e9d9cfd865921e498ee797ce673c6cc79604
-
The new test is made with a null string as the parameter passed to the lengthOfLastWord function. This means the condition of if (s = null || s.length() == 0) is satisfied and the branch is then entered.
Function 2:
- findMaxConsecutiveOnes in file _487.java

-
https://github.com/fishercoder1534/Leetcode/commit/ef93c348ca8946d8059044296b71685f7e96ed36
-
The code finds the maximum number of consecutive 1s in the array, with the allowance to flip at most one 0 into a 1. Through inspection, it is observed that flag 1 is always hit, for every iteration of the for loop. Flag 2 is hit only when num[right] == 0, which causes a decrease in the parameter k. Flag 3 is hit only when k is negative, triggering the inner while loop. Flag 4 is in a branch nested in the inner while loop, which only triggers when nums[left] == 0 and it results in k being incremented by one. The sequence 1, 0, 0, 1, 1, 0, 1 is a sequence that is able to trigger all flags. The execution is as follows:
-
For loop: 1st iteration.
- Right = 0. Left = 0. Nums[right] = 1. K = 1. Flag1 is hit and all other flags are not hit. Ans = 1
-
For loop: 2nd iteration.
- Right = 1. Left = 0. Nums[right] = 0. K = 0. Flag1 and 2 are hit, the others are not. Ans = 2
-
For loop: 3rd iteration.
- Right = 2. Nums[right] = 0. K = -1. Flag1, 2 are hit
- While 1st iteration:
- Nums[left] = 1 Flag 3 is hit, flag 4 is not. Left = 1
- While 2st iteration:
- Nums[left] = 0 Flag 3 is hit, flag 4 is hit. K = 0. Left = 2
- Ans = 2
-
From there onwards the for loop continues until right = 6 ( as when right = 7 the condition is not satisfied).By the end of the execution Ans = 4, which is the max number of consecutives ones if a 0 can be flipped into a 1 in the specified test array. This sample of the execution shows how all flags are hit.
Irina
Function 1
- searchRange in file _34.java

-
https://github.com/CeciTerena/Leetcode/commit/5efbbb2a7eb0b4a7042d65a0792ca0ec55f3af6d
-
Due to the large amount of flags that needed to be hit, I added four tests. The first test covers the scenario where the target is less than the smallest element in the array. It hits flag2. The next test covers the scenario where the target is greater than the largest element in the array. It hits flag3. The third test covers the scenario where the target is found and spans multiple elements. It hits flag4, flag5, flag6, and flag7. The last test I added covers the scenario where the target is not found but is within the range of the array. It hits flag4, flag8, and flag9.
Function 2
- lengthOfLongestSubstring in file _3.java

-
https://github.com/CeciTerena/Leetcode/commit/6711711e0a42abc3ee7c12006effd140cf3fd285
-
I added one test to hit flag1 which verifies that the method handles edge cases where the input string is empty and confirms that the method returns the correct output (0).
Overall
Old coverage
- Branches in total have 10% coverage, 18,517 branches missed

New coverage
- Branches in total have 11% coverage, 18,494 branches missed

Statement of individual contributions
Ava
- I contributed to this group project by checking the lines of code with the lizard function and running the overall coverage with the Jacoco tool. I also chose two functions, added flags to check the coverage of individual functions, and then added tests to ensure all flags were hit during the testing run. I was able to take both my functions which started at 66% to 100%.
Masha
- I contributed to this project by inspecting two functions, adding flags to calculate the branch coverage, and then adding tests to each function in order to improve the coverage of the functions. Both functions had branch coverage below 50% and the additional tests improved the coverage to 100%.
Cecilia
- I contributed by finding a suitable repository. In addition, I inspected two functions, adding flags to check their coverage, as well as added tests to improve the coverage of these two functions which took their coverage from 50% each to 100%.
Irina
- I contributed to the project by inspecting two functions and adding appropriate flags to calculate their branch coverage. I then added tests to the functions to increase their coverage from 22% and 50% to 100%.