hw2

docx

School

San Jose State University *

*We aren’t endorsed by this school

Course

287

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

docx

Pages

10

Uploaded by CaptainOryx4068

Report
Vishnu Vardhan Reddy Ireddy 016816176 Homework – 2 CMPE 287
Question #1: Basis Path Software Testing A. N1: void selectionSort(int arr[], int n){ N2: int i, j, min_idx; N3: for (i = 0; i < n - 1; i++) { N4: min_idx = i; N5: for (j = i + 1; j < n; j++) { N6: if (arr[j] < arr[min_idx]) N7: min_idx = j; } N8: if (min_idx != i) N9: swap(arr[min_idx], arr[i]); } }
B. Cyclomatic Number can be calculated in three different methods (CN) 1. Using regions CN = Number of Regions in Flow Diagram = 5 2. CN = E(edges) - N(nodes) + 2 = 15 - 12 + 2 = 5 3. Predicate nodes CN = P + 1 = 4 + 1 = 5 C. A B C D E F G H I J K L A 0 1 0 0 0 0 0 0 0 0 0 0 1-1=0 B 0 0 1 0 0 0 0 0 0 0 0 0 1-1=0 C 0 0 0 1 0 0 0 0 0 0 0 1 2-1=1 D 0 0 0 0 1 0 0 0 0 0 0 0 1-1=0 E 0 0 0 0 0 1 0 0 1 0 0 0 2-1=1 F 0 0 0 0 0 0 1 1 0 0 0 0 2-1=1 G 0 0 0 0 0 0 0 1 0 0 0 0 1-1=0 H 0 0 0 0 1 0 0 0 0 0 0 0 1-1=0 I 0 0 0 0 0 0 0 0 0 1 1 0 2-1=1 J 0 0 0 0 0 0 0 0 0 0 1 0 1-1=0 K 0 0 0 0 0 0 0 0 0 0 0 0 0 L 0 0 1 0 0 0 0 0 0 0 0 0 1-1=0 Sum=4 Cyclomatic Number = 4+1 = 5 D. 1. N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 -> N5 -> N6 -> N8 -> N9 -> N3 -> End (Covering the true paths for N3, N5, N6, and N8) 2.N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N8 -> N9 -> N3 -> End (Covering the true paths for N3, N5, and N8 but false for N6) 3. N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 -> N5 -> N6 -> N8 -> N3 -> End (Covering the true paths for N3 and N6 but false for N5 and N8) 4. N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N8 -> N3 -> End (Covering the true path for N3 but false for N5, N6, and N8) 5. N1 -> N2 -> N3 -> End (Covering the false path for N3)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
E. 1. Path: N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 -> N5 -> N6 -> N8 -> N9 -> N3 -> End Test Input: An array where the smallest element is not in the first position, and there are at least two elements that need swapping. Example: [3, 1, 2] Expected Output: [1, 2, 3] 2. Path: N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N8 -> N9 -> N3 -> End Test Input: An array where the smallest element is already in the first position, but other elements need swapping. Example: [1, 3, 2] Expected Output: [1, 2, 3] 3. Path: N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 -> N5 -> N6 -> N8 -> N3 -> End Test Input: An array where the smallest element is not in the first position, but after swapping once, the next smallest element is already in its correct position. Example: [3, 2, 1] Expected Output: [1, 2, 3] 4. Path: N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N8 -> N3 -> End Test Input: An array where the smallest element is already in the first position, and the next smallest element is in the second position. Example: [1, 2, 3] Expected Output: [1, 2, 3] 5. Path: N1 -> N2 -> N3 -> End Test Input: An array with only one element or an empty array. Example: [1] or [] Expected Output: [1] or []
Question #2: Branch-Based Software Testing A. Predicate Node Branch Condition True Branch False Branch Path Taken for True Branch Path Taken for False Branch N3 if(i < n-1) N4 End N1 -> N2 -> N3 -> N4 N1 -> N2 -> N3 -> End N5 if(j < n) N6 N8 N1 -> N2 -> N3 -> N4 -> N5 -> N6 N1 -> N2 -> N3 -> N4 -> N5 -> N8 N6 if(arr[j] < arr[min_idx]) N7 H N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> Increment j N8 if(min_idx != i) N9 K N1 -> N2 -> N3 -> N4 -> N5 -> N8 -> N9 N1 -> N2 -> N3 -> N4 -> N5 -> N8 -> Increment i B. Path for N3 True Branch: N1 -> N2 -> N3 -> N4 Path for N3 False Branch: N1 -> N2 -> N3 -> End Path for N5 True Branch: N1 -> N2 -> N3 -> N4 -> N5 -> N6 Path for N5 False Branch: N1 -> N2 -> N3 -> N4 -> N5 -> N8 Path for N6 True Branch: N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 Path for N6 False Branch: N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> Increment j Path for N8 True Branch: N1 -> N2 -> N3 -> N4 -> N5 -> N8 -> N9 Path for N8 False Branch: N1 -> N2 -> N3 -> N4 -> N5 -> N8 -> Increment i C.
Test Case # Test Path Condition Example Input Expected Output 1 N1 -> N2 -> N3 -> N4 if(i < n-1) [2, 3] [2, 3] 2 N1 -> N2 -> N3 -> End if(i >= n-1) [2] or [] [2] or [] 3 N1 -> N2 -> N3 -> N4 -> N5 -> N6 if(j < n) [2, 3, 1] [1, 2, 3] 4 N1 -> N2 -> N3 -> N4 -> N5 -> N8 if(j >= n) [2, 1] [1, 2] 5 N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N7 if(arr[j] < arr[min_idx]) [3, 1, 2] [1, 2, 3] 6 N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> Increment i if(arr[j] >= arr[min_idx]) [1, 3, 2] [1, 2, 3] 7 N1 -> N2 -> N3 -> N4 -> N5 -> N8 -> N9 if(min_idx != i) [3, 1, 2] [1, 2, 3] 8 N1 -> N2 -> N3 -> N4 -> N5 -> N8 -> Increment j if(min_idx == i) [1, 3, 2] [1, 2, 3] Question #3 Questions about Software State-based Testing
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
a. b. level 1: idle -> probe_send -> disconnected idle -> probe_send -> probe_sent level 2:” idle -> probe_send -> disconnected -> probe_reset -> idle idle -> probe_send -> probe_sent -> probe_reset -> idle idle -> probe_send -> probe_sent -> handoff_init -> handoff idle -> probe_send -> probe_sent -> probe_ack -> probed idle -> probe_send -> probe_sent -> probe_ack -> probe_fail
level 3: idle -> probe_send -> probe_sent -> probe_ack -> probed -> handoff_init -> handoff idle -> probe_send -> probe_sent -> probe_ack -> probed -> probed_reset -> idle idle -> probe_send -> probe_sent -> probe_ack -> probe_fail -> probe_reset -> idle idle -> probe_send -> probe_sent -> probe_ack -> probe_fail -> handoff_init -> handoff c. List of state testing paths from idle to handoff: Path1: idle -> probe_send -> probe_sent -> handoff_init -> handoff Path2: idle -> probe_send -> probe_sent -> probe_ack -> probed -> handoff_init -> handoff Path3: idle -> probe_send -> probe_sent -> probe_ack -> probe_fail -> handoff_init -> handoff Question 4:
a) Road Context Model for a 4-way Intersection with Traffic Lights and Cross-walking with Meters: 1. Geographical Context : Intersection Type: 4-way Road Type: Could be main roads, arterials, or minor streets intersecting. Terrain: Flat, elevated, or sloped. 2. Traffic Infrastructure : Traffic Lights: Separate lanes for turning (right, left, straight). Pedestrian Crosswalk: Present on all four sides, possibly with pedestrian countdown timers. Meters: Parking meters adjacent to the intersection or meters for other purposes. 3. Traffic Participants : Vehicles: Cars, buses, bicycles, motorcycles, and trucks. Pedestrians: People waiting to cross, already crossing, or walking along the sidewalk. Non-motorized vehicles: Bicycles, skateboards, scooters. 4. Traffic Behavior : Vehicle Behavior: Vehicles stopping at red lights, turning, accelerating from a stop, yielding to pedestrians. Pedestrian Behavior: Starting to cross, waiting for the signal, walking at varying speeds. b) Road Context Model for Diverse Road Hazards: 1. Physical Hazards : Potholes: Varying sizes and depths. Debris: Branches, litter, or other objects on the roadway. Water Puddles: Could cause hydroplaning. 2. Dynamic Hazards : Animals: Crossing roads unexpectedly (e.g., deer, dogs). Broken Vehicles: Vehicles stopped due to mechanical issues. Lost Cargo: Objects fallen from a truck or moving vehicle.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
3. Visual Hazards : Glare: Sunlight or headlights causing reduced visibility. Fog: Reduced visibility conditions. Poor Lighting: Areas with inadequate or malfunctioning street lights. c) Road Context Model for People Crossing Street Scenarios: 1. Crosswalk Crossings : Signalized: Pedestrians crossing with the aid of traffic signals. Unsignalized: Crossings without any traffic lights or signals. 2. Mid-block Crossings : Jaywalking: Pedestrians crossing away from designated crosswalks. Between parked cars: Reduced visibility for oncoming traffic. 3. Special Populations : Children: Possibly unpredictable movement patterns. Elderly: Possibly slower movement speeds. Disabled: Wheelchair users, people with crutches, etc. d) Road Context Model for a School Bus Scenario: 1. Bus Context : Stopped with Flashing Lights: Indicating children are entering or exiting. Moving: Normal transit without stops. 2. Traffic Behavior Around Bus : Vehicles: Stopping behind or opposite the bus when lights are flashing. Overtaking: Vehicles attempting to bypass the bus. 3. Pedestrian Behavior : Children: Entering/exiting the bus, possibly crossing the road. Guardians/Parents: Waiting near the bus stop, possibly escorting children. 4. Infrastructure : Bus Stop Signage: Indicating designated areas for bus stops. Road Markings: Indicating where vehicles should stop when the bus is loading/unloading.