You may make a copy of a worksheet and complete this activity, or simply type your answers in any text editor.
You may work alone or with at most two other students in this course.
Consider the trashgraph class
// Modified from https://cs.gmu.edu/~offutt/softwaretest/java/TrashAndTakeOut.java
1. public class trashgraph
2. {
3. public static void trash(int x)
4. {
5. int m, n;
6. m = 0;
7. if (x > 0)
8. m = 4;
9. if (x > 5)
10. n = 3 * m;
11. else
12. n = 4 * m;
13. int o = takeOut(m, n);
14. System.out.println("o is: " + o);
15. }
16.
17. public static int takeOut(int a, int b)
18. {
19. int d, e;
20. d = 42 * a;
21. if (a > 0)
22. e = 2 * b + d;
23. else
24. e = b + d;
25. return(e);
26. }
27. }
Write them down as pairs of triplets.
Each triplet is a method name, variable name, and node.
The pair has the last-def on the left and a first-use on the right.
For example:
(method1(), var1, node1) —
(method2(), var2, node2)
where last-def of a variable var1 is
in method method1
at node node1 and
first-use of a variable var1 appears as a variable var2
in method method2 at node node2.
Note: in general, if a graph is unavailable or has not been created,
each triplet can be written as
(method1(), var1, line1) —
(method2(), var2, line2)
where last-def of a variable var1 is
in method method1
at line number line1 and
first-use of a variable var1 appears as a variable var2
in method method2 at line number line2.
[optional]
For more hands-on experience, take the test inputs you provided to satisfy All-Coupling-Uses,
construct a set of test cases, and then
automate your test set (in JUnit) and run it against the trashgraph class.
CC-BY-NC-SA 4.0 license.