0% found this document useful (0 votes)
14 views

22bsit113 (Ass-1) Copy

The document contains a software testing assignment that includes various coding tasks in Python related to voting eligibility, loan eligibility, discount calculations, student results, electricity billing, and overtime payment calculations. Each task includes code snippets and test cases using Equivalence Partitioning (EP) and Boundary Value Analysis (BVA). Additionally, it addresses error handling for invalid inputs.

Uploaded by

dtbfsd8zjt
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)
14 views

22bsit113 (Ass-1) Copy

The document contains a software testing assignment that includes various coding tasks in Python related to voting eligibility, loan eligibility, discount calculations, student results, electricity billing, and overtime payment calculations. Each task includes code snippets and test cases using Equivalence Partitioning (EP) and Boundary Value Analysis (BVA). Additionally, it addresses error handling for invalid inputs.

Uploaded by

dtbfsd8zjt
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
You are on page 1/ 13

Software Testing

Assigment-1

22bsit113
1) Write a python code to input age and check for eligibility of voting and create various
test cases.

Code :-

def check_voting_eligibility(age):

"""Function to check voting eligibility based on age."""

if age < 0:

return "Invalid age. Age cannot be negative."

elif age < 18:

return "Not eligible to vote."

else:

return "Eligible to vote."

# Taking user input

try:

user_age = int(input("Enter your age: "))

print(check_voting_eligibility(user_age))

except ValueError:

print("Invalid input. Please enter a valid number.")

Testcase-Id AGE RESULT

TC001 10 NO

TC002 19 YES

TC003 40 YES

TC004 -9 INVALID

TC005 78 YES
Software Testing
Assigment-1

22bsit113
TC006 4 NO

TC007 14 NO

2) Take a company scenario.

A company offers a discount on bulk purchases of an item based on the number

of units purchased:

 0-9 units → No discount

 10-49 units → 5% discount

 50-99 units → 10% discount

 100+ units → 15% discount

Write test cases using Equivalence Partitioning (EP) and Boundary Value

Analysis (BVA) for this scenario.


Software Testing
Assigment-1

22bsit113

3) Banking System - Loan Eligibility

A bank offers personal loans based on the credit score and monthly salary of an

applicant.

- Credit Score ≥ 750 and Salary ≥ 50,000 → Loan Approved


Software Testing
Assigment-1

22bsit113
- Credit Score 600 - 749 and Salary 30,000 - 49,999 → Loan Partially

Approved

- Credit Score < 600 or Salary < 30,000 → Loan Rejected

Write test cases using Equivalence Partitioning (EP) and Boundary Value

Analysis (BVA).

Code :-

def check_loan_eligibility(credit_score, salary):

"""Function to check loan eligibility based on credit score and salary."""

if credit_score >= 750 and salary >= 50000:

return "Loan Approved"

elif 600 <= credit_score < 750 and 30000 <= salary < 50000:

return "Loan Partially Approved"

else:

return "Loan Rejected"

# Taking user input and displaying the result

try:

credit_score = int(input("Enter your credit score: "))

salary = int(input("Enter your monthly salary: "))

print(check_loan_eligibility(credit_score, salary))

except ValueError:

print("Invalid input. Please enter numeric values.")

TESTCASE-ID SALARY CREDIT-SCORE OUTPUT

TC001 30000 500 Loan Rejected


Software Testing
Assigment-1

22bsit113
TC002 100000 800 Loan Approved

TC003 25000 1000 Loan Rejected

TC004 ERT 3000 INVALID INPUT

TC005 UIO INVALID INPUT

TC006 9000 -90 Loan Rejected

TC007 -0978 -0987 Loan Rejected

4) An e-commerce website provides the following discount rules based on cart value

and membership:

 Cart Value < ₹1,000 → No Discount

 Cart Value ₹1,000 - ₹4,999 → 5% Discount

 Cart Value ₹5,000 - ₹9,999 → 10% Discount

 Cart Value ₹10,000+ (and membership = ‘Prime’) → 20% Discount

Write test cases using Equivalence Partitioning (EP) and Boundary Value

Analysis (BVA).

Code:-

def calculate_discount(cart_value, membership):

"""Function to determine the discount based on cart value and membership."""

if cart_value < 1000:

return 0 # No Discount

elif 1000 <= cart_value < 5000:

return 5 # 5% Discount

elif 5000 <= cart_value < 10000:

return 10 # 10% Discount


Software Testing
Assigment-1

22bsit113
elif cart_value >= 10000 and membership.lower() == 'prime':

return 20 # 20% Discount

else:

return 10 # Default to 10% if non-prime at 10,000+

# Taking user input and displaying the result

try:

cart_value = int(input("Enter your cart value: "))

membership = input("Enter your membership type (Prime/Non-Prime): ")

discount = calculate_discount(cart_value, membership)

print(f"Discount Applied: {discount}%")

except ValueError:

print("Invalid input. Please enter numeric values for cart value.")

TESTCASE-ID CART_VALUE Prime/Not Prime EXCEPTED OUTPUT

TC001 1000 NON 5% DISCOUNT

TC002 5000 PRIME 10% DISCOUNT

TC003 10000 NON 10% DISCOUNT

TC004 -1999 OK INVALID

TC005 12000 NON 10% DISCOUNT

TC006 20000 PRIME 20% DISCOUNT

TC007 -20000 PRIME 0% DISCOUNT


Software Testing
Assigment-1

22bsit113

5)Write a Python code that takes a student’s marks in different subjects, calculates

the total, percentage, and grade, and then determines whether the student has

passed or failed. Create test cases for Equivalence Partitioning (EP) and Boundary Value

Analysis (BVA).

CODE :-

def calculate_result(marks):

"""Function to calculate total, percentage, grade, and pass/fail status."""

total_marks = sum(marks)

percentage = (total_marks / (len(marks) * 100)) * 100

if percentage >= 90:

grade = 'A'

elif percentage >= 75:

grade = 'B'

elif percentage >= 50:

grade = 'C'

else:

grade = 'F'

status = "Pass" if percentage >= 40 else "Fail"

return total_marks, percentage, grade, status


Software Testing
Assigment-1

22bsit113

# Taking user input and displaying the result

try:

num_subjects = int(input("Enter number of subjects: "))

marks = []

for i in range(num_subjects):

mark = int(input(f"Enter marks for subject {i+1}: "))

marks.append(mark)

total, percentage, grade, status = calculate_result(marks)

print(f"Total Marks: {total}")

print(f"Percentage: {percentage:.2f}%")

print(f"Grade: {grade}")

print(f"Status: {status}")

except ValueError:

print("Invalid input. Please enter numeric values for marks.")

TESTCAS-ID TOTAL SUBJECT PERCENTAGE GARDE-STATUS

TC001 5 50% C-PASS

TC002 4 90% A-PASS

TC003 4 INVALID
INPUT(BECAUSE I
HAVE PUT
INTEGER)

TC004 3 70% C-PASS


Software Testing
Assigment-1

22bsit113
TC005 4 35% F-FAIL

TC006 3 90% A-PASS

TC007 4 NOT INPUTED INVALID INPUT


NUMERIC

6)CODE:-

def calculate_bill(units):

"""Function to calculate electricity bill based on consumption units."""

if units <= 100:

amount = units * 0.75

elif units <= 300:

amount = 75 + (units - 100) * 1.00

elif units <= 500:

amount = 275 + (units - 300) * 1.50

else:

amount = 575 + (units - 500) * 1.75

return amount

# Taking user input and displaying the result

try:

customer_number = input("Enter customer number: ")


Software Testing
Assigment-1

22bsit113
units_consumed = int(input("Enter power consumed (in units): "))

bill_amount = calculate_bill(units_consumed)

print("\nElectricity Bill")

print("------------------------------")

print(f"Customer Number: {customer_number}")

print(f"Units Consumed: {units_consumed}")

print(f"Total Amount to be Paid: Rs. {bill_amount:.2f}")

print("------------------------------")

except ValueError:

print("Invalid input. Please enter numeric values for power consumption.")

TESTCASE-ID UNIT- TOTAL AMOUT OUTPUT ACTUAL OUPUT


CONSUMED
TO PAY

TC001 -09 -6.75 TO PAY INAVLID INPUT

TC002 1000 1450 TO PAY VALID OUTPUT

TC003 QBA - - INVALID INPUT

TC004 9.087 - - INVALID INPUT

TC005 QB35 - - INVALID INPUT

7) A library pays overtime to its staff as per the following schedule:

If the basic salary of a worker is less than Rs. 2,500/- per month, her overtime

allowance is Rs.10/- per hour for the first 10 hours and Rs. 7.50 per hour for hours

in excess of 10, up to a maximum of Rs. 750/-per month. If the basic salary is in


Software Testing
Assigment-1

22bsit113
excess of Rs. 2,500/- per month but less than 3,500/- per month, the overtime

allowance is Rs. 15/- per hour for the first 10 hours, and Rs. 10 per hour for hours

in excess of 10, up to a maximum of Rs. 1250/- per month. If the basic salary is in

excess of Rs. 3,500/- per month, the overtime allowance is Rs. 20/- per hour for the

first 10 hours and Rs. 15 per hour for hours in excess of 10, up to a maximum of

Rs. 1500/- per month.

CODE:-

def calculate_overtime(basic_salary, overtime_hours):

"""Function to calculate overtime pay based on salary and hours worked."""

if basic_salary < 2500:

rate_first_10 = 10

rate_excess = 7.50

max_overtime = 750

elif basic_salary < 3500:

rate_first_10 = 15

rate_excess = 10

max_overtime = 1250

else:

rate_first_10 = 20

rate_excess = 15

max_overtime = 1500

if overtime_hours <= 10:


Software Testing
Assigment-1

22bsit113
overtime_pay = overtime_hours * rate_first_10

else:

overtime_pay = (10 * rate_first_10) + ((overtime_hours - 10) * rate_excess)

overtime_pay = min(overtime_pay, max_overtime)

return overtime_pay

# Taking user input and displaying the result

try:

basic_salary = float(input("Enter basic salary: "))

overtime_hours = int(input("Enter overtime hours worked: "))

overtime_amount = calculate_overtime(basic_salary, overtime_hours)

print("\nOvertime Payment Calculation")

print("----------------------------------")

print(f"Basic Salary: Rs. {basic_salary:.2f}")

print(f"Overtime Hours: {overtime_hours}")

print(f"Overtime Pay: Rs. {overtime_amount:.2f}")

print("----------------------------------")

except ValueError:

print("Invalid input. Please enter numeric values.")

TESTCASE-ID ACTUAL OVER-TIME OVER-TIME ATCUAL EXPECTED


Software Testing
Assigment-1

22bsit113
SALARY HOURS PAY OUTPUT OUPUT

TC001 2500 -09 -135 PAID NEGATIVE

OUTPUT

TC002 10000 OK - INVALID INVALID


INPUT INPUT

TC003 500000 500000 1500 PAID MAX LIMIT

TC004 100 100 750 PAID MIN LIMIT

TC005 ABC - - - PELASE


ENTER
NUMERIC
VALUES

You might also like