0% found this document useful (0 votes)
3 views7 pages

ST Assignment Python

The document outlines the implementation of software testing for programming scenarios using Python, focusing on both normal and exceptional cases. It emphasizes the importance of testing in ensuring code correctness, enhancing software quality, and preventing financial losses. The document includes examples of matrix multiplication with test cases demonstrating expected behaviors and error handling for various scenarios.

Uploaded by

mohitpitliya1636
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

ST Assignment Python

The document outlines the implementation of software testing for programming scenarios using Python, focusing on both normal and exceptional cases. It emphasizes the importance of testing in ensuring code correctness, enhancing software quality, and preventing financial losses. The document includes examples of matrix multiplication with test cases demonstrating expected behaviors and error handling for various scenarios.

Uploaded by

mohitpitliya1636
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Implementing Software Testing for Programming Scenarios using Python Programming

Aim
The goal of this assignment is to implement software testing for various programming scenarios, specifically
focusing on normal and exceptional scenarios.

Significance of Computer program Testing in Programming


Computer program testing may be a basic component of the program advancement life cycle
(SDLC) and plays an basic part in guaranteeing the quality, usefulness, and unwavering quality
of a computer program item.
Guarantees Rightness of Code
• Avoids Bugs: Computer program testing makes a difference recognize abandons or bugs
within the code some time recently the computer program is discharged. Bugs can lead to
off base behavior, framework crashes, or inaccurate yield. By identifying these bugs early
within the improvement cycle, you'll be able dodge potential issues in generation.
• Confirms Usefulness: Testing guarantees that the computer program performs the
expecting operations and meets the prerequisites of the clients or partners.

Upgrades Computer program Quality


• Quality Confirmation: Computer program testing ensures that the program product
functions as anticipated beneath distinctive conditions. It too approves in case the
program meets the desired details and quality guidelines.
• Client Involvement: A well-tested application progresses client encounter (UX) by
minimizing crashes, blunders, and unforeseen behaviors, driving to more prominent
fulfillment.

Anticipates Budgetary Misfortune


• Cost-Effective: Distinguishing and settling bugs amid the early stages of improvement is
faraway cheaper than managing with issues once the computer program is conveyed.
Testing makes a difference relieve the hazard of money related misfortune by
guaranteeing that the program is solid some time recently it goes live.
• Notoriety Security: In the long run, ineffectively tried program can harm a company's
notoriety, driving to misfortune of clients and revenue. Compelling testing shields the
company's brand and believe with clients.
Encourages Program Support
• Less demanding Investigating: With the increasing complexity of computer program,
testing ensures that designers can track and find issues quicker amid upkeep. It too makes
it less demanding to refactor the code within the future, as you've got the test cases to
affirm in case changes affect other parts of the framework.
• Relapse Testing: When modern highlights are included or code is changed, relapse tests
guarantee that already working functionalities proceed to work accurately, avoiding the
presentation of unused bugs.

Guarantees Security
• Distinguishing Vulnerabilities: Program testing, particularly security testing, makes a
difference recognize vulnerabilities within the application some time recently they can be
abused by pernicious on-screen characters. Testing for vulnerabilities (e.g., SQL infusion,
cross-site scripting) makes a difference anticipate security breaches.
• Privacy & Information Astuteness: With appropriate security testing, information
debasement or spillage can be dodged, guaranteeing that delicate information remains
secure.

Normal Scenarios
Typical scenarios are test cases where the computer program carries on as anticipated beneath
commonplace conditions. These are the substantial inputs or activities that clients will commonly
perform within the genuine world. These tests approve that the program works as expecting when
everything is working accurately and there are no unforeseen issues.
Cases:
Inputs: Matrix A (2x2), Matrix B (2x2).
Expected behavior: The frameworks duplicate accurately, and the result takes after the numerical
rules of lattice increase.
Example:
A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]]

Expected output:
[[19, 22], [43, 50]]

Exceptional Scenario (Edge Cases)


Exceptional scenarios are test cases that mimic circumstances where the computer program ought
to handle invalid inputs or unforeseen conditions. These are the edge cases or mistake conditions
that might happen due to off base or startling client behavior, framework disappointments, or
irregular inputs. These tests approve how well the computer program handles blunders,
guaranteeing it doesn't crash or carry on unusually.

Case:
Inputs: Matrix A (2x2), Matrix B (3x2). This results in a dimension mismatch for multiplication.

Expected behavior: The software should raise an appropriate error (e.g., ValueError) indicating the
dimension mismatch.

Example:

A = [[1, 2], [3, 4]]

B = [[1, 2], [3, 4], [5, 6]]

Expected Output: Error

Programming Scenario:
Matrix Multiplication

Code:
import random import
time

# Matrix Multiplication Function with Error Handling def


matrix_multiply(A, B): if not (isinstance(A, list)
and isinstance(B, list)):
raise ValueError("Both A and B must be matrices (lists of lists)")

if not A or not B:
raise ValueError("Matrices cannot be empty")
if not all(isinstance(row, list) for row in A + B):
raise ValueError("Each matrix must be a list of lists")
num_cols_A =
len(A[0]) num_rows_B =
len(B)
if any(len(row) != num_cols_A for row in
A):
raise ValueError("All rows in Matrix A must have the same number
of columns") if any(len(row) != len(B[0]) for row in B):
raise ValueError("All rows in Matrix B must have the same number
of columns")
if num_cols_A !=
num_rows_B:
raise ValueError("Number of columns in A must equal number of rows
in B") result = [] for i in range(len(A)):
row_result = []
for j in range(len(B[0])):
sum_product = sum(A[i][k] * B[k][j] for k in
range(num_cols_A)) row_result.append(sum_product)
[Link](row_result) return result

# Normal Test Cases def run_test_case(title, A, B,


expected_output=None):
print(f"\nTest Case: {title}")
try:
result = matrix_multiply(A, B)
print("Multiplication Successful!")
print("Result:", result) if
expected_output is not None:
print("Expected:", expected_output)
if result == expected_output:
print("Test Passed!")
else:
print("Test Failed!")
else:
print("No expected output to compare.")
return True except Exception as e:

print(" Error:", e)
return False

results = []
print("Running Normal
Scenarios")
# Test Case 1: 2x2 * 2x2 result1 =
run_test_case("2x2 × 2x2",
[[1, 2], [3, 4]],
[[5, 6], [7, 8]],
[[19, 22], [43, 50]]) [Link](("2x2 ×
2x2", result1))

# Test Case 2: 2x3 * 3x2 result2 =


run_test_case("2x3 × 3x2",
[[1, 2, 3], [4, 5, 6]],
[[7, 8], [9, 10], [11, 12]],
[[58, 64], [139, 154]]) [Link](("2x3 × 3x2",
result2))

# Test Case 3: Identity matrix result3 =


run_test_case("Identity Matrix Multiplication",
[[1, 0], [0, 1]],
[[9, 8], [7, 6]],
[[9, 8], [7, 6]]) [Link](("Identity
Matrix", result3))

# Exceptional Test Cases print("\nRunning


Exceptional Scenarios")

# Case 1: Mismatched dimensions result4 =


run_test_case("Mismatched Dimensions",
[[1, 2]],
[[1, 2], [3, 4], [5, 6]])
[Link](("Mismatched Dimensions", result4))

# Case 2: Empty matrices result5 =


run_test_case("Empty Matrices", [], [])
[Link](("Empty Matrices", result5))

# Case 3: Inconsistent rows


result6 = run_test_case("Inconsistent Rows in A",
[[1, 2], [3]],
[[1, 2], [3, 4]]) [Link](("Inconsistent
Rows in A", result6))

# Case 4: Non-numeric elements result7 =


run_test_case("Non-Numeric Elements",
[[1, "a"], [3, 4]],
[[5, 6], [7, 8]]) [Link](("Non-Numeric
Elements", result7))
# Case 5: Not a matrix result8 = run_test_case("Not a
Matrix (string input)",
"not a matrix",
[[1, 2], [3, 4]]) [Link](("Not a
Matrix", result8))

# Final Results Documentation print("\


nTest Results Summary:") for test_case,
passed in results: status = "Pass" if
passed else "Fail"
print(f"{test_case}: {status}")

Output:

Above is the output of both the scenarios, Normal and Exceptional scenario with test cases.
Above is the Summary of all the test cases with Pass and Fail, where in normal scenario all the
cases are Pass and in Exceptional scenario, all cases fail.

You might also like