Assignment 3
Part – 1
1. Description of the tool used and the types of coverage it provides
There are various types of code coverage tools available in the market, one among them
is the [Link] tool which I used for part -1 in identifying the code coverage for the
python source code used in the Homework1. This tool helps in monitoring and
determining which part of the code had been executed by test cases created by testers and
which part of the code has not been tested. This tool also helps in providing information
such as the line numbers of the uncovered code by the test cases.
Below are the types of coverage it gives us:
1. Line (Statement) coverage
2. Function coverage
3. Branch coverage
4. Conditions coverage etc.
2. Source listing of your code
def binary_search(arr, x):
low = 0
high = len(arr) - 1
mid = 0
while low <= high:
mid = (high + low) // 2
if arr[mid] < x:
low = mid + 1
elif arr[mid] > x:
high = mid - 1
else:
return mid
return -1
3. Test Cases:
Set – 1
import unittest
import BinarySearchAlgorithim
class BinarySearchAlgorithimTesting([Link]):
def test_BinarySearchAlgorithim_test1(self):
print("test 1, Given number exist")
[Link](BinarySearchAlgorithim.binary_search([5,6,7,8,9],7),2)
def test_BinarySearchAlgorithim_test2(self):
print("test 2, Given number doesn't exist")
[Link](BinarySearchAlgorithim.binary_search([5,6,7,8,9],10),-1)
if __name__=='__main__':
[Link]() #pragma: no cover
Set - 2
import unittest
import BinarySearchAlgorithim
class BinarySearchAlgorithimTesting([Link]):
def test_BinarySearchAlgorithim_test1(self):
print("test 1, Empty list provided")
[Link](BinarySearchAlgorithim.binary_search([],10),-1)
def test_BinarySearchAlgorithim_test2(self):
print("test 2, Given number exist in 0th index")
[Link](BinarySearchAlgorithim.binary_search([5,6,7,8,9],5),0)
def test_BinarySearchAlgorithim_test3(self):
print("test 3, combination of postive and negative numbers")
[Link](BinarySearchAlgorithim.binary_search([-6,-5,7,8,9],9),4)
def test_BinarySearchAlgorithim_test4(self):
print("test 4, Negative Numbers")
[Link](BinarySearchAlgorithim.binary_search([-9, -8, -7, -6, -5],-9),0)
if __name__=='__main__':
[Link]() #pragma: no cover
4. A printout or screenshot showing the coverage achieved for each test case.
Below are the Screenshots for the First set
Code coverage screenshot for test1
Code coverage screenshot for test2
Code coverage screenshot for both test cases in a single run of First Set
Below are the Screenshots for the Second set
Code coverage screenshot for test1
Code coverage screenshot for test2
Code coverage screenshot for test3
Code coverage screenshot for test4
Code coverage screenshot for all test cases in a single run of Second Set
We can observe from the screenshots above that the code coverage has improved in the second set
compared to the first set due to an increase in the number of test cases and test cases covering all
the lines of code in the [Link].
5. Evaluation of the tool’s usefulness
This tool is used for monitoring the percentage of the code covered by the test cases created for
the application. This tool provides additional information such as the lines which are uncovered
by the test cases so that it can be easy for the testers to create a new test case for covering the
missing code coverage and boost the percentage of the code coverage. The tool also provides code
coverage in different formats such as console-based output, HTML and XML, etc.
Part – 2
1. Description of the tool used and the types of analysis it provides
Pylint is one of the available source code analysis tools for python in the market. It helps in
identifying the industry-level coding standard, helps in refactoring such as variables, method
names, class names, detecting duplicate or unused code, Warnings, Errors, and Bug detection.
It is fully customizable through a file called .pylintrc which helps in choosing the relevant
issues in our code. It can also be used for generating the UML diagrams using pyreverse. Each
problem reported by this tool will be in the format of ID and Message object which are
described below
a. C - Convention
b. R – Refactor
c. W – Warning
d. E – Error
e. F – Fatal
2. Source listing of your code
Code after introducing the two different data flow anomalies which can be caught in a static
analysis tool
import NumPy
def binary_search(arr, x):
low = 0
high = len(arr) - 1
mid = 0
while low <= high:
mid = (high + low) // 2
if arr[mid] < x:
low = mid + 1
elif arr[mid] > x:
high = mid - 1
else:
return mid
return -1
3. A printout or screenshot showing the analysis performed
The data flow anomalies typically caught by a static analysis tool are of type (Convention ) C and
Warning (W) unused import, the improper naming convention as per the above screenshot
reported by pylint.
a. Invalid-name
b. Unused-import
c. Missing-function-docstring
4. Evaluation of the tool’s usefulness
This tool basically helps in finding the code smells such as checking the developer coding
standards with industry level standards, refactoring the variables, simplifying complex code into
simpler code, and identifying the warnings and unnecessary multiple lines of code.
References
1. [Link]
2. [Link]
3. [Link]
4. Python Static Analysis Tools - Blog | luminousmen