ELEC1005-Wk11 - Advanced Technology
ELEC1005-Wk11 - Advanced Technology
WEEK 11
Advanced Technology
path a b c d e f g
Path 1 (adg) 1 0 0 1 0 0 1
Path 2 (abcg) 1 1 1 0 0 0 1
Path 3 (adef) 1 0 0 1 1 1 0
number of edge
3 1 1 2 1 1 2
covers
Path 4 abcef 1 1 1 0 1 1 0
● It involves:
○ A statement where a variable receives a value,
○ Statements that use or refer to these values.
● For a statement S
● DEF(S) = {X | statement S contains the definition of X}
● USE(S) = {X | statement S contains the use of X}
Anomalous Detection
● A variable is defined but not used or referenced,
● A variable is used but never defined,
● A variable is defined twice before it is used
y 1 2, 4
a 3, 4 5
Read X
Read Y
IF X+Y > 100 THEN
Print "Large"
ENDIF
If X + Y<100 THEN
Print "Small"
ENDIF
1
public class gcd {
public static void main(String[] args) { 2
float x = Float.valueOf(args[0]);
float y = Float.valueOf(args[1]);
3
while (x != y) {
if (x > y)
4 5
x = x - y;
else y = y - x;
} 6
System.out.println("GCD: " + x);
} 7
Cyclomatic Complexity = 3
}
The University of Sydney Page 16
Exercise
Please List LIPs
1
public class gcd {
public static void main(String[] args) { 2
float x = Float.valueOf(args[0]);
float y = Float.valueOf(args[1]);
3
while (x != y) {
if (x > y)
4 5
x = x - y;
else y = y - x;
} 6
System.out.println("GCD: " + x);
} 1. 1-2-7 7
} 2. 1-2-3-4-6-2-7
3. 1-2-3-5-6-2-7
The University of Sydney Page 17
Exercise
Please Design The Test Cases
V(G) = E - N + 2
E= 13, N = 11, V(G) = 2
Answer
int i=0;
int n=4; 1
int j = 0;
while(i < n-1) 2
{
j = i +1 3
while(j < n) 4
{
if (A[i] < A[j]) 5
swap(A[i], A[j]); 6
}
i=i+1 7
}
}
The University of Sydney Page 24
def find (string match){
for(auto var : list)
{
if(var == match && from != INVALID_U32) return INVALID_U32;
}
//match step1
if(session == getName() && key == getKey())
{
Please Calculate the Cyclomatic Complexity
for (auto& kv : Map)
{
if (kv.second == last && match == kv.first) M= V(G) =
{ 1(for) + 2(if) + 2(if) + 1(for) +
return last;
} 2(if) + 2(if) + 1(for) + 2(if) + 1=
} 14
}
//match step2 e.g.,
auto var = Map.find(match); if(var == match
if(var != Map.end()&& (from != var->second)) return var->second; && from != INVALID_U32)
//match step3
for(auto var: Map) Thus, 2(if), which refers to a if with two
{ conditions
if((var.first, match) && from != var.second)
{
return var.second;
}
}
return INVALID_U32;
};
Cyclomatic maintenance
Complexity code status Testability cost
1-10 clear and high Low
structured
10-20 complex middle middle
20-30 very Low high
complicated
>30 unreadable unfathomable very high
– Reinforcement Learning
– If reinforcement learning is under suitable conditions, it can
completely defeat humans and approach the limit of
perfection.