IN3329 Software Testing Assignment 1

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

IN3329 Software Testing Assignment 1

Due Date: 24:00 09th Apr

This assignment is designed to test your understanding and application of key concepts in software testing and exception handling. It aims to equip you with practical skills essential for ensuring the quality and reliability of software products.

Marching Scheme:

  • Your submission will be evaluated based on the following criteria:
  1. Code Correctness: Your code should correctly implement the specified requirements. It should function as expected without errors or issues.
  2. Coding Style: Your code should be well-formatted, readable, and well-commented. Good coding style includes proper indentation, meaningful variable names, and clear comments explaining the logic where necessary.
  3. Discussion and Analysis: For each question, a discussion or explanation is required. This should demonstrate your understanding of the concepts, your reasoning in the approach taken, and any considerations or trade-offs you made.
Specification To successfully complete this assignment, your submission should:
  • Be submitted in the specified format (e.g., .java or .py files for code, .docx, .pdf or .md for written parts).
  • Adhere to the given due date and time.
  • Fulfill all the requirements stated in each question.
  • Include a cover page with your name, student ID, and any other required information.
  • Be entirely your own work. Plagiarism will not be tolerated and will result in disciplinary action.

General Instructions:

  • Read each question carefully and ensure you understand the requirements before starting.
  • Test your code thoroughly to ensure it meets the specifications.
  • Write clear and concise answers in your discussions, focusing on the key points of the question.
  • Ensure your submission is organized, with code and discussions for each question clearly separated.
1. What is exception handling? Explain with example. [5 marks]
2. Explain the Rationale Behind Writing Software Testing Code Prior to the Implementation of the Actual
Code [5 marks]
3. For the robust implementation in different programming languages, your task is to create a method or function in both Java and Python that calculates the area of a triangle. Focus on making your code robust by implementing type checking, input validation, and error handling. Compare the differences in implementing these features in Java and Python. Provide a brief discussion on the steps you took to ensure robustness, and note any language-specific considerations or challenges you encountered. [15 marks]
(a).Java Code [2.5 marks]
b. Python Code [2.5 marks]
c. Steps used to ensure the robustness of the codes are: [5 marks]*
d. Testing Code [5 marks] Inside the main method of each implementation, write test cases to demonstrate the functionality of your method. Include scenarios that show normal operation, as well as cases that should trigger your error handling. This will help illustrate how your code behaves under
various conditions
// Java main method with test case
# Python main method with test case
4. Given below is a method readFileContent that reads and prints the contents of a file. Your task is to refactor this method to make it cleaner and more robust by incorporating appropriate exception handling. Specifically, ensure that it properly handles the FileNotFoundException and IOException. [10 marks]
public static void readFileContent(File file) {
FileInputStream fileInputStream = null;
BufferedReader reader = null;
try {
fileInputStream = new FileInputStream(file);assignment1 questions.md
reader = new BufferedReader(new InputStreamReader(fileInputStream));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Instructions:
  • Modify the method to specifically catch FileNotFoundException and IOException.
  • Improve the code structure for better readability and maintainability.
  • Ensure all resources are properly closed in case of an exception.
  • Write comments where necessary to explain your changes.
import java.io.*
public static void readFileContent(File file) {
// Refactored Java code
}
5. Implement test cases for an Array Element Counter: [10 marks]
public class ArrayElementCounter {
public int countOccurrences(int[] array, int element) {
int count = 0;
for (int i : array) {
if (i == element) {
count++;assignment1 questions.md
}
}
return count;
}
}
public class ArrayElementCounterTest {
ArrayElementCounter counter = new ArrayElementCounter();
// Test with an array containing the element
public void testCountOccurrencesNormal() {
}
// Continue with additional test cases
// ...
}
6. Write comprehensive test case of basic Calculator class for the subtract, multiply, and divide, methods of the Calculator class. The test cases should cover both normal and edge cases and for the divide method, include a test case for divison by zero. [15 marks]
7. Inventory Management System: You are tasked with developing a critical component of an inventory management system. This component is responsible for managing the stock of items in a warehouse. The system should be able to add items, remove items, and check the availability of items. [20 marks]
(a). The InventoryManager should be thread-safe as it will be used in a multi-threaded environment. [4 marks]

(b). Implement an InventoryManager class with the following functionalities: [8 marks] 


  • addItem(itemName, quantity): Adds the specified quantity of an item. If the item already exists, increase the quantity.
  • removeItem(itemName, quantity): Removes the specified quantity of an item. If the quantity to remove is greater than the available quantity, throw an InsufficientStockException.
  • checkAvailability(itemName): Returns the current quantity of the item.


import java.util.concurrent.ConcurrentHashMap;
public class InventoryManager {
// ...assignment1 questions.md
// Initialize InventaroyManager
public InventoryManager() {
// ...
}
//....
}
(c). Implement comprehensive test cases to test all functionalities of the InventoryManager, including edge cases. [8 marks]
8. Large Range Multiplication Method: Develop a method or function named extendedIntegerMultiplication that is capable of multiplying two integer values within a large range, specifically from -2^31^ to 2^31^ - 1, the standard range for 32-bit integers. When designing test cases for this method, ensure to cover both normal operations and edge cases, including scenarios that might lead to potential overflows or underflows. The objective is to ensure that the method accurately handles multiplication across the entire range of 32-bit integers [20 marks]

(a). Method / function implementation

(b). Test Strategy and Implementation

发表评论

电子邮件地址不会被公开。 必填项已用*标注