Unit Test Exam 1
Unit Test Exam 1
For each statement below, input the letter of the term that is best described. Note that you can click each word (cell) to mark it
minutes remaining
Kamilla is creating a new social network software together with their co-workers. Each of the functions
written by Kamilla works as expected, but when put together with the other functions implemented by
Q1.1:
Kamilla’s co-workers, the entire system does not work. Kamilla plans to test the entire software, with
both Kamilla's functions and functions written by other people.
Engineers at Boomit use a tool, called DetectBugs, to find potential bugs and runtime errors in Boomit's
Q1.2:
codebase. In particular, the DetectBugs tool does not run Boomit's code.
Kameron wants to test some functionality of their code. The code involves using a method foo that takes
Q1.3: a very long time to run. To speed up the testing, Kameron uses a way to replace foo with another
implementation bar which takes significantly less time to run.
To manage their new project, Daphne decides to execute the following steps in order: (1) gathering
Q1.4: requirements of the software they want to develop, (2) designing and implementing the code, and (3)
testing the system and fixing bugs.
The software engineers at Bioplex have a day-long meeting to go over their codebase together and
Q1.5:
discuss potential bugs and security risks.
There may be potential problems and unfortunate events that may compromise the success of projects.
Q1.6: Experienced project leads will create strategies to mitigate such potential problems and control
unfortunate event outcomes.
Before Kookle launches the brand new maps to their adventure video game, they send a version of the
Q1.7:
maps to some end-users for their feedback.
90% of the unit tests currently failed. However, after changing an `or` sign (||) to an `and` sign (&&), all
Q1.8:
the unit tests for the codebase passed.
After Paulina finishes their code for a new feature, they must get the changes looked over by another
Q1.10: engineer before the changes are merged to BuzzyFuzzy’s codebase. The other engineer could look at the
changes offline, without having to meet with Paulina synchronously.
Three concurrent threads, A, B, and C, access the same shared variable v without locking: all of them
Q1.11: read the value of v, and thread A also writes to v. Depending how the threads interleave with each other,
thread B may read a different value of v when the program is executed multiple times.
Kyle is a manager for a team of software engineers. To ensure that the team stays on track, Kyle sets an
Q1.12: internal deadline to have 75% of the features completed for their prototype. This will not be seen by
customers.
Dave and Ariel are classmates working on a coding project together. They find that when Dave types the
Q1.13: code, and Ariel simultaneously watches to identify bugs and make suggestions, they are more effective
than individually coding without synchronized communication with each other.
99 Gogozoom calculates their engineers’ year-end bonuses by the number of lines of code the engineers
minutes remaining Q1.14:
write. This leads to engineers writing more lines of code that may be unnecessary and/or unreadable.
Hide Time
Manual Save
Question 2. Code Coverage (19 points)
Navigation
You are given the following functions. Assume that statement coverage applies only to statements marked STMT_#, and we
Question 1
consider all statements marked STMT_# in the entire program when calculating coverage. That is, even if the program
Question 2
execution starts from one particular method, we consider coverage with respect to the contents of all methods shown.
Question 3
Similarly, even if some methods are not executed during the program execution, we consider coverage with respect to the
Question 4
contents of all methods shown. Finally, we assume every argument of string type has at least one character; in other words,
Question 5
we do not consider NULL or empty strings as input to functions in this program.
Question 6
Extra Credit
Pledge & Submit
1 void maang(str a, str b) {
2 STMT_1
3 if (a[0] == b[0]) {
4 jelly_bean(strlen(a), strlen(b))
5 }
6 STMT_2
7 }
8
9 void jelly_bean(int x, int y) {
10 STMT_3
11 if (x < y) {
12 STMT_4
13 polar_bear(y)
14 } else {
15 STMT_5
16 x = 0
17 polar_bear(x)
18 }
19 }
20
21 void polar_bear(int z) {
22 while (z > 5) { // line 22
23 STMT_6
24 z--
25 }
26 if (z <= 2) { // line 26
27 STMT_7
28 }
29 STMT_8
30 }
31
(a) (3 points)
Provide 1 input (i.e., both arguments) to maang(str a, str b) such that the statement coverage under this input is 75%.
Write your test input in the form such as maang(hello, world), if it is possible to achieve the given statement coverage. If it
is not possible, enter "not possible".
In the context of this question, you have to pick inputs from the following seven strings: { av, att, meta, apple, amazon,
nvidia, netflix }.
(b) (3 points) True / False: there exists a test suite (with at least one test input) such that the test suite obtains 100%
statement coverage. (We only consider statements marked STMT_# when computing statement coverage in this question. And
we consider all statements marked STMT_#.) Furthermore, in this question you can use any test inputs, not necessarily only
those strings from the previous question.
True
False
(c) (3 points) What is the maximum branch coverage achievable by one and only one (i.e., exactly one) input to maang(str a,
str b)? Note that, the polar_bear function has a while loop in it – similar to if-then-else, this while loop also introduces two
branches: one branch that enters the loop body and the other branch exits the loop.
Your answer here.
99 (d) (3 points) What would be the maximum statement coverage achievable by exactly one input if the "while" condition on line
22 were replaced with z > 2?
minutes remaining
Manual Save (e) (4 points) What is the minimum number of test cases to reach 100% branch coverage? Provide the test cases with their
input in the form maang(a, b). For a and b, please use string values from only the following seven strings: { av, att,
Navigation
meta, apple, amazon, nvidia, netflix }. For example, one test case could be maang(att, att). Another example test
Question 1 case is maang(att, meta). Please write each test case on a separate line.
Question 2
Question 3 Your answer here.
Question 4
Question 5
Question 6
Extra Credit
Pledge & Submit
(f) (3 points) In 4 sentences or less, describe a scenario in which 100% statement coverage might miss a bug in a program.
(a) (5 points)
Suppose you are interviewing at company Corp481, and you get the following technical question:
Given an array of strings called strs, group the anagrams together. Here, an "anagram" is a word or phrase formed by
rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, “ate” and
“eat” are anagrams.
What are three questions you may want to ask -- e.g., to help clarify the question, or to help you better understand the task, or
to convince the interviewer that you understand relevant software engineering concepts -- before you start typing any code for
this question?
(b) (5 points)
After looking through the history of commits, you realized that each individual code change is quite large. You decided to
encourage developers on your team to keep each individual change small going forward.
How would you justify this decision of breaking larger changes into a series of smaller changes? Feel free to cite what you
learned from the lecture slides and/or readings to back up your justifications. Please use at most five sentences.
(c) (5 points)
When developing a large project, different components in the project may take different amounts of time to be implemented.
You find that programmers who finish their work early are oftentimes blocked by the work of other programmers. For
example, programmer A cannot proceed to test her function because it requires the output of the function which programmer
B is currently still working on.
In order to improve the overall efficiency of the entire team, what single Software Engineering method can you apply and why
is it a good choice? Please use at most five sentences and include at least two reasons why your method is a good choice.
99
minutes remaining
Hide Time
(d) (5 points)
Manual Save
Suppose you are managing a team of software engineers at company Corp481.
Navigation
In order to improve productivity, you plan to base developer end-of-year cash bonuses on the following metrics:
Question 1
Question 2 a. The number of words of documentation written.
Question 3 b. The number of code changes accepted during code reviews.
Question 4
Question 5 Evaluate the pros and cons of each of these two metrics. Use less than 2 sentences for pros and less than 2 sentences for cons.
Question 6
Extra Credit Your answer here.
Pledge & Submit
You need to decide whether or not to employ pair programming (i.e., two programmers code up the task together) for a series
of tasks. You will only opt in for pair programming if it leads to an overall lower cost ($$). Otherwise, you would choose to use
individual programming (i.e., one developer programs the entire task alone).
Suppose for ALL tasks, pair programming makes coding 20% slower but results in 60% fewer defects. For example, a task —
that takes one programmer 10 hours to complete — would take a pair of two programmers 12 hours to complete (i.e., two
programmers are pair programming together for the entire 12 hours). On the other hand, given a task, suppose one
programmer writes a program to solve this task that has 10 bugs. If two programmers pair programs together, they would
write a program that solves the same task and that has 4 bugs.
In the context of this question, when pair programming, we allow two programmers to write the program together, however,
when fixing bugs/defects, each programmer will do it individually. In other words, in terms of fixing defects, there is no
difference between pair programming and individual programming: a defect is always fixed by one programmer.
The hourly rate for each programmer would be $50. That is, if a task takes one individual programmer 10 hours to code up,
the cost is $500 (i.e., we need to pay the programmer $500). On the other hand, if two programmers pair program for 10
hours, the total cost would be $1,000 (i.e., each programmer gets paid $500). As for fixing defects, if a defect takes one
programmer 1 hour to fix, the programmer would get paid $50.
The following tables detail the specifications for each task. In particular, for each task, it gives:
a. Program Size (LOC): the total lines of code (LOC). Note that, for the purpose of this question, pair programming and
individual programming will produce programs of the same size.
b. Coding Speed (LOC / hour): the number of lines of code per hour that one programmer can write for the task.
c. Defect Rate (#defects / KLOC): the number of defects produced per one thousand lines of code, assuming one
programmer is working on the task alone.
d. Defect Fixing Rate (#hours / defect): the number of hours for one programmer to fix one defect.
(e) (5 points)
Program Size (LOC) Coding Speed (LOC / hour) Defect Rate (#defects / KLOC) Defect Fixing Rate (#hours / defect)
100,000 50 20 10
(f) (5 points)
Program Size (LOC) Coding Speed (LOC / hour) Defect Rate (#defects / KLOC) Defect Fixing Rate (#hours / defect)
100,000 100 10 2
99 analysis to identify inputs that cause these problems. Is this a good technique, or is there a better one for this scenario? In
addition, please indicate which dynamic analysis from the lecture or readings you think would be the 'best' fit for this situation.
minutes remaining Justify your answer. Limit your answer to no more than five sentences.
Hide Time
Your answer here.
Manual Save
Navigation
Question 1
Question 2 (h) (5 points) You are a software engineer at an app-based rideshare company with a very large codebase. Because of a recent
Question 3 high-profile hack at one of your competitors, you and your coworkers decide to systematically evaluate your codebase for
Question 4 security vulnerabilities. If your main concern is identifying whether a defect exists that would cause employee credentials to be
Question 5 leaked, what single method would you use to evaluate the quality of your codebase, and why? If you have multiple methods in
Question 6 mind, please explain a best one in your answer. Use no more than five sentences.
Extra Credit
Pledge & Submit Your answer here.
Consider the following python program that implements a standard binary search algorithm. Note that the '//' operator is the
floor division operator in python. For example, 9 // 2 gives you 4. We are interested in the two mutants that are created for
this python program — they are shown in the comments below. In particular, mutant 1 changes to “high = len(arr)” without
changing anything else. Mutant 2 changes only the “while” condition from using “<=” to using “<”.
(a) (4 points)
Your first task is to fill in the following table. In this table, you are given two test inputs. For example, in the first test input arr
= [1, 2, 3, 4] and x = 2 and in the second test input arr = [1, 2, 3, 4] and x = 1. Indicate in the table below whether or not each
of these test inputs would kill each mutant.
(b) (4 points) In a few sentences, discuss the pros and cons of using each of the two mutants to evaluate the each of the two
test inputs
Your answer here.
99
minutes remaining
Manual Save Consider the following code snippet that defines a function, called totallyUsefulFunction, which takes as input two non-
negative integers and one boolean value. In particular, the `apple` variable is a non-negative integer (i.e., positive or zero) that
Navigation
indicates the number of apples. Similarly, `banana` is the number of bananas (positive or zero, but not negative). Finally,
Question 1 `chocolate` variable is a boolean that is either True or False, meaning whether or not we have chocolate.
Question 2
Question 3 The function calculates a particular `foodScore`. Each apple contributes 1 point and each banana contributes 2 points. If
Question 4 chocolate is not present, the total `foodScore` is always 0.
Question 5
The function also calculates the `foodCount` – the total number of apples, bananas and chocolate (with True counting as one
Question 6
item and False as zero items).
Extra Credit
Pledge & Submit
1 totallyUsefulFunction(int apple, int banana, bool chocolate){
2
3 int foodScore = apple + banana * 2;
4 int foodCount = apple + banana + 1;
5
6 while (foodScore < 22){
7 apple ++;
8 foodScore ++;
9 foodCount ++;
10 }
11
12 // Can I have a little chocolate, as a treat?
13 if (chocolate == false){
14 foodScore = 0;
15 foodCount --;
16 print(‘sad’);
17 } else {
18 print(‘yum!’)
19 }
20
21 // Invariants Evaluated Here
22
23 }
24
(a) (8 points)
Consider the following four invariants generated by an oracle for totallyUsefulFunction. (The oracle here could be an
automated dynamic invariant generation tool like Daikon. Or it could be created manually by a human. How this oracle is
implemented is not important in this question. We just assume we’re given four invariants.)
The invariants are evaluated at the end of the function – as indicated at the end of the totallyUsefulFunction. For each
invariant, please first indicate either (1) the invariant is valid, or (2) the invariant is not valid.
Then, explain your reasoning. That if, for each invariant, if it is valid, please briefly explain why you believe it is valid. If invalid,
please describe a situation in which this invariant is violated. For example, you could specify the parameter values that make
the invariant invalid – please use the format like [apple = 0, banana = 0, chocolate = false].
Please provide your answer for each invariant in the box below. Each invariant is a new line. You can use the format like
INV_1: valid-or-invalid. your-reasoning.
Your answer here.
99
minutes remaining
Consider a live variable dataflow analysis for three variables, x, y, and z used in the control-flow graph below. We associate
Manual Save
with each variable a separate analysis fact: either the variable is (1) possibly read on a later path before it is overwritten (live),
Navigation or (2) it is not (dead). We track the set of live variables at each point: for example, if x and y are alive but z is not, we write {x,
y}. The special statement return reads, but does not write, its argument. In addition, if and while read, but do not write, all
Question 1
of the variables in their predicates. (You must determine if this is a forward or backward analysis.)
Question 2
Question 3
Question 4
Question 5
Question 6
Extra Credit
Pledge & Submit
(1 point each) For each basic block B1 through B11, write down the list of variables that are live right before the start of the
corresponding block in the control flow graph above. Please list only the variable names in lowercase without commas or other
spacing (e.g., use either ab or ba to indicate that a and b are alive before that block).
B1 B2 B3 B4
B5 B6 B7 B8
B9 B10 B11
Extra Credit
Each question below is for 1 point of extra credit unless noted otherwise. We are strict about giving points for these answers.
No partial credit.
(3) If you read any optional reading, identify it and demonstrate to us that you have read it critically. (2 points)
99
minutes remaining (5) In your own words, identify and explain any of the bonus psychology effects or ethical considerations presented in class on
the colored bordered slides or in a "long instructor post" on Piazza. (2 points)
Hide Time
Manual Save
Navigation
Question 1 Honor Pledge and Exam Submission
Question 2
Question 3 You must check the boxes below before you can submit your exam.
Question 4
Question 5 I have neither given nor received unauthorized aid on this exam.
Question 6
I am ready to submit my exam.
Extra Credit
Pledge & Submit
Submit My Exam
Once you submit, you will be able to leave the page without issue. Please don't try to mash the button.