Skip to content

Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.

License

Notifications You must be signed in to change notification settings

CeciTerena/Leetcode

 
 

Repository files navigation

SEP-assignment-1

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

Screenshot 2024-06-27 at 19 17 45

Coverage measurement

Existing tool

Tool used: Jacoco

Code

./gradlew test jacocoTestReport

cd build/reports/jacoco/test/html

open index.html

Screenshot 2024-06-27 at 19 19 16

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

Screenshot 2024-06-27 at 19 19 54 Screenshot 2024-06-27 at 19 20 09

Function 2

  • divide in _29.java

  • Coverage: 43%, 3/7 branches

Screenshot 2024-06-27 at 19 20 49 Screenshot 2024-06-27 at 19 21 11

Ava

Function 1

  • swapPairs in file _24.java

  • Coverage: 66%, ⅔ branches

Screenshot 2024-06-27 at 19 22 40 Screenshot 2024-06-27 at 19 22 51

Function 2

  • maxArea in file _11.java

  • Coverage: 66%, ⅔ branches

Screenshot 2024-06-27 at 19 23 39 Screenshot 2024-06-27 at 19 23 54

Cecilia

Function 1

  • lengthOfLastWord in file _58.java

  • Coverage: 50%, ½ branches

Screenshot 2024-06-27 at 19 24 44 Screenshot 2024-06-27 at 19 24 57

Function 2

  • findMaxConsecutiveOnes in file _487.java

  • Coverage: 50%, 2/4 branches

Screenshot 2024-06-27 at 19 25 37 Screenshot 2024-06-27 at 19 25 53

Irina

Function 1

  • searchRange in file _34.java

  • Coverage: 22%, 2/9 branches

Screenshot 2024-06-27 at 19 26 53 Screenshot 2024-06-27 at 19 27 05

Function 2

  • lengthOfLongestSubstring in file _3.java

  • Coverage: 50%, ½ branches

Screenshot 2024-06-27 at 19 27 59 Screenshot 2024-06-27 at 19 28 09

Coverage improvement

Individual tests

Masha

Function 1

  • maxOperations in file _3038.java
Screenshot 2024-06-27 at 19 28 51
  • 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
Screenshot 2024-06-27 at 19 29 47
  • 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
Screenshot 2024-06-27 at 19 30 38

Function 2

  • maxArea in file _11Test.java
Screenshot 2024-06-27 at 19 32 00

Cecilia

Function 1:

  • lengthOfLastWord in file _58.java
Screenshot 2024-06-27 at 19 32 50

Function 2:

  • findMaxConsecutiveOnes in file _487.java
Screenshot 2024-06-27 at 19 33 45
  • 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
Screenshot 2024-06-27 at 19 36 19
  • 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
Screenshot 2024-06-27 at 19 37 07

Overall

Old coverage

  • Branches in total have 10% coverage, 18,517 branches missed
Screenshot 2024-06-27 at 19 37 55

New coverage

  • Branches in total have 11% coverage, 18,494 branches missed
Screenshot 2024-06-27 at 19 38 22

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%.

About

Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.4%
  • Other 0.6%