The Program Development Process
Imagine that a neighborhood store launches a new checkout system on its computer and, on the very first day, it overcharges Doña Rosa by $\$30$ on a purchase. No program is born finished or works on the first try. Between the idea and a reliable program there is a process with stages that repeat. At the end of the page you will see how that overcharge could have been avoided.
The Development Cycle
A bug is an error in the program. Debugging is finding the cause of that bug and fixing it. For example, if an ATM program subtracts the amount of a withdrawal twice, the user will see double the amount taken out: that is a bug with real consequences.
These phases of program development are out of order: (a) testing the program with different data, (b) editing the source code, (c) debugging found errors, (d) running…
These phases of program development are out of order: (a) testing the program with different data, (b) editing the source code, (c) debugging found errors, (d) running the program. Put them in a logical order and explain what is done in each phase, taking into account that testing may require going back a step.
Explain what a bug in a program is and what debugging means. Give a simple example of an error that an ATM program could have and what consequence it would have for the…
Explain what a bug in a program is and what debugging means. Give a simple example of an error that an ATM program could have and what consequence it would have for the user.
The figure shows the software development workflow cycle, but one of its stages is covered with a question mark, as shown in the figure. State which stage is missing…
The figure shows the software development workflow cycle, but one of its stages is covered with a question mark, as shown in the figure.
State which stage is missing from the cycle, what it consists of, and why the "no" arrow sends the work back to editing the code.
Types of Errors
Errors are also distinguished by when they appear. A compile-time error is detected before running (the program does not even start; for example, a parenthesis is missing). A runtime error appears when the program is already running, sometimes only with certain data (for example, dividing by 0).
Distinguish between a compile-time error (the program does not even start) and a runtime error (it starts but fails with certain data), giving an example of each type.
Distinguish between a compile-time error (the program does not even start) and a runtime error (it starts but fails with certain data), giving an example of each type.
Explain the difference between a syntax error and a logic error, giving an example of each in a program that calculates the mean of three marks. Which of the two types…
Explain the difference between a syntax error and a logic error, giving an example of each in a program that calculates the mean of three marks. Which of the two types prevents the program from running, and which allows it to run but produces incorrect results?
Designing Test Cases
For example, for a program that adds two numbers: a normal case is $3 + 4$ with expected result $7$; a special one is $0 + 0$ with result $0$, or a negative number such as $-5 + 5 = 0$.
A test plan can be organized in a table. Example for a division:
| Case | Input (a, b) | Expected result |
|---|---|---|
| Normal | (10, 2) | 5 |
| Normal with decimals | (7, 2) | 3.5 |
| Boundary | (0, 5) | 0 |
| Negative | (-9, 3) | -3 |
| Invalid | (8, 0) | Message: "cannot divide by 0" |
| Invalid | ("x", 2) | Message: "invalid input" |
Explain what a test case is and write two test cases for a program that adds two numbers: one with normal values and one with a special value, stating the input and…
Explain what a test case is and write two test cases for a program that adds two numbers: one with normal values and one with a special value, stating the input and expected result for each.
A program that divides two numbers works fine in almost all tests, but fails when the divisor is 0. Explain what boundary values or edge cases are in testing, why they…
A program that divides two numbers works fine in almost all tests, but fails when the divisor is 0. Explain what boundary values or edge cases are in testing, why they must always be tested, and state two other values with which you would test this program.
To test a program that applies a discount to people aged 65 or over, define three test cases: one with a normal value, one with the exact boundary value, and one with an…
To test a program that applies a discount to people aged 65 or over, define three test cases: one with a normal value, one with the exact boundary value, and one with an invalid value (negative or impossible age), with the expected result for each. Justify your choices.
A team member shows you the following C++ function to calculate the final price including VAT and apply a discount if the customer is a member, claiming: "If it compiles…
A team member shows you the following C++ function to calculate the final price including VAT and apply a discount if the customer is a member, claiming: "If it compiles without errors or warnings, it's impossible for it to fail at runtime; there's no need to test it":
float calcularPrecioFinal(float base, bool esSocio) {
float total = base;
if (esSocio = true) {
total = total * 0.90f;
}
total = total * 1.21f;
return total;
}
-
Reasonably predict the output of the function for a non-member customer (
esSocio = false) with a base price of 100.00 pesos. Does it match the expected behavior? Explain why the compiler does not reject it as an error. -
Justify, based on this example, the difference between what syntactic verification by the compiler guarantees and what dynamic software testing proves.
-
Propose the code fix and write a specific test case that demonstrates the bug if the fix were not applied.
Design a test plan for a program that asks for two numbers and displays their division: create a table with at least six test cases (pairs of input values, including…
Design a test plan for a program that asks for two numbers and displays their division: create a table with at least six test cases (pairs of input values, including normal, boundary, and invalid values), the expected result for each, and what the program should do if the input is invalid. Justify the choice of each case.
The school's intranet implements an authentication module with the following requirements: Username: 4 to 12 alphanumeric characters, case-insensitive. Password: between…
The school's intranet implements an authentication module with the following requirements:
-
Username: 4 to 12 alphanumeric characters, case-insensitive.
-
Password: between 8 and 16 characters, case-sensitive, with at least one digit and one special character.
-
Security: temporary account lockout for 15 minutes after three consecutive failed attempts.
Design a rigorous test plan using a table with at least six test cases designed by you. For each case, you must specify: identifier, input values (username and password), previous system state, expected result, and what specific logic, boundary, or security risk you are validating.
A programmer argues that "a one-line function does not need testing because it is self-evident" and presents this function written in C++: 1. Predict the function's…
A programmer argues that "a one-line function does not need testing because it is self-evident" and presents this function written in C++:
bool esImpar(int n) {
return (n % 2 == 1);
}
-
Predict the function's output for
n = 7,n = 0, andn = -7. Explain technically why an unexpected result occurs in one of them based on how the modulo operator (%) handles negative operands in this language. -
Fix the expression so that the function is mathematically correct for any integer.
-
Based on this case, refute the idea of dispensing with unit tests in short or seemingly trivial algorithms using two technical arguments.
Debugging Techniques
Some errors are nondeterministic: they fail only sometimes (for example, because of random numbers or responses from an online service) and do not repeat when you run step by step. To study them, it is a good idea to save logs of every run, fix the seed of the random generator, and simulate the service's responses, so that the failure can be reproduced at will.
To analyze data from a system that fails, compare what was expected with what was obtained in each record and look for what the failing cases have in common. If the total comes out wrong only when there is a discount and a surcharge, or when there is a refund (negative amount), the hypothesis points to how those items are processed.
Explain what a trace or log message is in a program and how it helps to find an error (it allows you to see which path the program took and with what values).
Explain what a trace or log message is in a program and how it helps to find an error (it allows you to see which path the program took and with what values).
A loop in a program never stops. Explain where you would place temporary print statements to diagnose it (inside the loop, displaying the control variable in each…
A loop in a program never stops. Explain where you would place temporary print statements to diagnose it (inside the loop, displaying the control variable in each iteration) and what you would look for in those statements to find the cause.
In the billing system of a school cooperative, it has been detected that when issuing the monthly invoice, the total amount payable for some members is incorrect. You…
In the billing system of a school cooperative, it has been detected that when issuing the monthly invoice, the total amount payable for some members is incorrect. You have the following system logs available:
-
Member 101: 2 purchases of 15.00 pesos -> Total billed: 30.00 pesos (expected: 30.00 pesos).
-
Member 102: 1 purchase of 50.00 pesos with a 10 % promotional discount (5.00 pesos) and a 3.00 pesos management fee surcharge -> Total billed: 47.50 pesos (expected: 48.00 pesos).
-
Member 103: 1 purchase of 20.00 pesos and 1 item return of 5.00 pesos (-5.00 pesos) -> Total billed: 25.00 pesos (expected: 15.00 pesos).
-
Formulate a justified hypothesis about the logic or order-of-operations bug that explains the error for Member 102 and Member 103.
-
Design the debugging strategy to confirm your hypotheses: indicate what minimum test data you would input to isolate the bug, at what points in the execution flow you would place breakpoints, and what specific variables you should inspect step by step.
A weather simulation script fails in approximately one out of twenty executions by throwing an unexpected exception, but when running it manually step by step, the…
A weather simulation script fails in approximately one out of twenty executions by throwing an unexpected exception, but when running it manually step by step, the failure is never reproduced (the program uses real-time API requests and a random number generation function).
-
Justify why this error is classified as non-deterministic (heisenbug) and identify the two sources of variability that prevent it from being reproduced at will.
-
Design a technical action plan to force the controlled reproduction of the bug without passively waiting for it to occur randomly (explain how you would handle the pseudorandom number generator and how you would decouple external network calls).
-
Once the defect is located and fixed, what testing procedure would you apply to certify that the error has completely disappeared and was not simply a statistical coincidence?
Modularizing, Refactoring, and Documenting
Two typical refactorings:
-
Renaming variables: changing
x,y2, andzzztoprice,tax, andtotal. The code explains itself and fewer mistakes are made. -
Extracting a function: if the same VAT calculation ($16\,\%$) appears in five places, it is written once as
calculate_vat(price)and called whenever needed.
Documenting also helps: explaining at least what the program does and how it is used. Without documentation, when a team member leaves, nobody understands the code well and the program "ages" poorly.
And it is a good idea to save versions (1.0, 1.1, 2.0…) of the code: if the new version works worse than the previous one, you can go back to the previous one and compare what changed.
Programs have versions (1.0, 1.1, 2.0, etc.). Explain the purpose of keeping versions of code and what you can do if the latest version performs worse than the previous…
Programs have versions (1.0, 1.1, 2.0, etc.). Explain the purpose of keeping versions of code and what you can do if the latest version performs worse than the previous one.
Documentation accompanies a program. Explain at least two things it should cover (what the program does and how to use it) and why undocumented software degrades poorly…
Documentation accompanies a program. Explain at least two things it should cover (what the program does and how to use it) and why undocumented software degrades poorly over time when a team works on it.
Explain what modularisation of a program is (dividing it into functions or modules) and analyse two advantages it offers when development is carried out by a team of…
Explain what modularisation of a program is (dividing it into functions or modules) and analyse two advantages it offers when development is carried out by a team of several people: think about division of work, testing, and error localization.
Explain what refactoring is (improving code without changing its external behavior) and describe two typical refactorings (renaming variables with clear names,…
Explain what refactoring is (improving code without changing its external behavior) and describe two typical refactorings (renaming variables with clear names, extracting a function from repeated code), with an example of each.
A code snippet uses the variables x, y2, and zzz to store the price, VAT, and total. Rewrite these names meaningfully and explain why choosing descriptive names helps…
A code snippet uses the variables x, y2, and zzz to store the price, VAT, and total. Rewrite these names meaningfully and explain why choosing descriptive names helps prevent errors (making the code self-documenting).
Two members of a team edit the same project file at the same time and, when merging changes, a conflict arises. Explain what a merge conflict is, how it is resolved…
Two members of a team edit the same project file at the same time and, when merging changes, a conflict arises. Explain what a merge conflict is, how it is resolved (reviewing both versions and deciding), and which two team habits prevent it (dividing work by modules, integrating changes frequently).
The monitoring system for a greenhouse has been programmed in a single file within a single 400-line function. The code sequentially reads three analog soil moisture…
The monitoring system for a greenhouse has been programmed in a single file within a single 400-line function. The code sequentially reads three analog soil moisture sensors, calculates the average, evaluates thresholds, triggers a solenoid valve via a digital pin, logs the historical record into a text file, and sends an alert email if the moisture drops below 30 %.
-
Justify in detail three serious technical problems that this architecture creates when debugging an intermittent failure or performing automated unit tests.
-
Design a modular refactoring of the program: break the function down into at least four independent functions. For each one, define its name, typed input parameters, return value, and its single responsibility.
-
Explain how your design would allow testing the irrigation decision algorithm through data simulation, without having the physical sensors connected to the board.
Application: Testing an Internet of Things System
Everything above applies to the programs that live inside connected objects. The Internet of Things (IoT) connects physical objects to the network: sensors that measure the world, communications that carry the data, and applications that turn it into decisions. Think of a humidity sensor in a cornfield that tells a farmer's cell phone when to water.
A communication protocol is the set of rules by which two devices understand each other. They can be classified by their wireless range: short (Bluetooth, Zigbee), medium (Wi-Fi), and long (4G/5G cellular networks, LoRa). A lightweight messaging protocol widely used in IoT is MQTT.
Testing a system like this is harder than testing a program on your computer, because failures can be in any of the four elements:
-
Test cases: besides normal humidity, test the boundary values (for example, the exact watering threshold) and the invalid ones (a disconnected sensor that sends $-999$).
-
Traces: record the reading, the time, and whether the message arrived. That way you can tell a sensor that measures wrong from a network that loses data.
-
Modularization: separate reading, sending, and deciding, so you can test the decision without needing real sensors.
-
Security: access credentials should not be written inside the code that you share with the team.
A group of three students is going to develop an attendance tracking application for the school over ten weeks. To avoid delays and last-minute failed deliveries, you…
A group of three students is going to develop an attendance tracking application for the school over ten weeks. To avoid delays and last-minute failed deliveries, you must structure the team's working methodology:
-
Design a schedule organized into four verifiable milestones or deliverables, explaining what objective criteria must be met before authorizing the transition to the next milestone.
-
Define a formal peer review protocol (code review): establish who reviews whose code, what minimum quality checklist must be passed before accepting any changes, and how disagreements are managed.
-
Establish and justify a "code freeze" policy: in which week it must be activated, what type of modifications are strictly prohibited from that moment on, and what exclusive tasks the team must undertake until the final delivery.
Go back to the beginning: the overcharge to Doña Rosa would have been detected by testing the system with normal, boundary, and invalid cases before using it in the store.