0% found this document useful (0 votes)
49 views51 pages

ELEC1005-Wk11 - Advanced Technology

The program will result in a divide by zero error when x = 1 and y = 0. When the arguments are passed as 1 and 0: 1. x will be initialized to 1 2. y will be initialized to 0 3. The while condition (x != y) will be true as 1 != 0 4. The if condition (x > y) will be true as 1 > 0 5. x = x - y will result in 1 - 0, which is division by 0. To fix this, we need to add a check before the subtraction to avoid division by zero: ``` if(y == 0) return; if (x > y

Uploaded by

Destrious
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views51 pages

ELEC1005-Wk11 - Advanced Technology

The program will result in a divide by zero error when x = 1 and y = 0. When the arguments are passed as 1 and 0: 1. x will be initialized to 1 2. y will be initialized to 0 3. The while condition (x != y) will be true as 1 != 0 4. The if condition (x > y) will be true as 1 > 0 5. x = x - y will result in 1 - 0, which is division by 0. To fix this, we need to add a check before the subtraction to avoid division by zero: ``` if(y == 0) return; if (x > y

Uploaded by

Destrious
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

ELEC1005

WEEK 11

Advanced Technology

Prepared & Presented by


Dr. Charles Z. Liu

The University of Sydney Page 1


Path Coverage

To cover all the path, there


are 4 paths in total, including:
● abcef,
● adef,
● abcg,
● adg.

Linear Independent Paths


● adg, abcg, adef

The University of Sydney Page 2


Path Representation with Linear Independent Path

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

Linear Independent Path adg, abcg, adef

The University of Sydney Page 3


Linear Independent Path Coverage v.s. Full Path Coverage

● It can be seen that when full path coverage cannot be achieved


due to "path explosion", statement and decision coverage can be
achieved with very few use cases through linearly independent
path coverage.

● Linearly independent path coverage is a good criterion.

● In actual logic analysis, some specific paths may be of particular


interest, and these paths are not included in the set of linearly
independent paths. At this point, supplementary use case
generation can be performed on the specified path.

The University of Sydney Page 4


Data Flow Testing

● Data flow testing is a type of structural testing.


● It is a method to find the test path of the program according to
the definition and use position of the variables in the program.

● It involves:
○ A statement where a variable receives a value,
○ Statements that use or refer to these values.

The University of Sydney Page 5


Data Flow Testing

● To illustrate the approach of data flow testing, assume that each


statement in the program assigned a unique statement.

● 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

The University of Sydney Page 6


Example

1. read x, y; 1. Please draw the Corresponding CFG


2. if(x>y)
3. a = x+1
4. else a = y-1
5. print a;

The University of Sydney Page 7


Example
2. Please write the variables and where they
were defined and used in this program
1. read x, y; according to the CFG
2. if(x>y)
3. a = x+1
4. else a = y-1
5. print a;

Variable Defined at node Used at node


x 1 2, 3

y 1 2, 4

a 3, 4 5

The University of Sydney Page 8


Branch Coverage

● The branch coverage is used to


cover all branches of the
control flow graph.
● It covers at least all possible
outcomes (true and false) of
each condition of the decision
point.
● The branch coverage technique
is a white-box testing
technique that ensures that
every branch at every decision
point must be executed.

The University of Sydney Page 9


Example

The number of paths of a branch is used to calculate branch


coverage.
This a code structure that takes two variables, X and
Read X Y, and two conditions.
The function is to judge if the sum of X and Y is
Read Y greater than 100.
IF X+Y > 100 THEN
Print "Large"
If the first condition is true, print "Large",
ENDIF if false, go to the next condition.
If X + Y<100 THEN If the second condition is true, print "Small".
Print "Small"
This function can be also performed by IF THEN
ENDIF ELSE structure

The University of Sydney Page 10


Example
Please draw the CFG corresponding to the code

Read X
Read Y
IF X+Y > 100 THEN
Print "Large"
ENDIF
If X + Y<100 THEN
Print "Small"
ENDIF

The University of Sydney Page 11


Example

Please draw the CFG corresponding to the code below

public static boolean isPrime(int n) {


A) int i = 2;
B) while (i < n) {
C) if (n % i == 0) {
D) return false
}
E) i++;
}
F) return true;
}

The University of Sydney Page 12


Example

Please Calculate the Cyclomatic Complexity

public static boolean isPrime(int n) {


A) int i = 2;
B) while (i < n) {
C) if (n % i == 0) {
D) return false
}
E) i++;
}
F) return true;
}

The University of Sydney Page 13


Example

Please list out all the LIPs according to the CFG

public static boolean isPrime(int n) {


A) int i = 2;
B) while (i < n) {
C) if (n % i == 0) {
D) return false
}
E) i++;
}
F) return true;
}

The University of Sydney Page 14


Exercise

Please draw the CFG corresponding to the code below


1
public class gcd {
public static void main(String[] args) { 2
float x = Float.valueOf(args[0]);
1
float y = Float.valueOf(args[1]);
3
while (x != y) { 2
if (x > y) 3
4 5
x = x - y; 4
else y = y - x; 5
} 6 6
System.out.println("GCD: " + x); 7
} 7
}
The University of Sydney Page 15
Exercise
Please Calculate the Cyclomatic Complexity

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

public class gcd { 1


public static void main(String[] args) {
F
float x = Float.valueOf(args[0]); 2
float y = Float.valueOf(args[1]); T
while (x != y) {
3
if (x > y) T F
x = x - y; 4 5
else y = y - x;
}
System.out.println("GCD: " + x); 6
} Test cases:
} 1. 1-2-7 x = 1, y = 1 7
2. 1-2-3-4-6-2-7 x = 2, y = 1
3. 1-2-3-5-6-2-7 x = 1, y = 2
The University of Sydney Page 18
Exercise
Design a test to find and discuss the flaw of the program below

public class gcd { 1


public static void main(String[] args) {
F
float x = Float.valueOf(args[0]); 2
float y = Float.valueOf(args[1]); T
while (x != y) {
3
if (x > y) T F
x = x - y; 4 5
else y = y - x;
}
System.out.println("GCD: " + x); 6
}
} 7
When x = 1, y = 0, The program will be stuck in an infinite loop:
Answer
1-2-3-4-6-2-3-4-6-2…
The University of Sydney Page 19
Exercise
Redesign the program to fix the bugs

public class gcd { public class gcd {


public static void main(String[] args) { public static void main(String[] args) {
float x = Float.valueOf(args[0]); float x = Float.valueOf(args[0]);
float y = Float.valueOf(args[1]); float y = Float.valueOf(args[1]);
while (x != y) { while (x != y && y!=0) {
if (x > y) if (x > y) Answer
x = x - y; x = x - y;
else y = y - x; else y = y - x;
} }
System.out.println("GCD: " + x); System.out.println("GCD: " + x);
} }
} }

The University of Sydney Page 20


Exercise
● Please calculate the Cyclomatic Complexity
● Please give the Linear Independent Paths
● Please discuss the flaws

V(G) = E - N + 2
E= 13, N = 11, V(G) = 2

Linearly independent path are


1 -> 2 -> 4 -> 6 -> 10
1 -> 2 -> 5 -> 6 -> 10

A path is independent if it has acyclic nodes.


These two paths above have acyclic nodes.
While other paths have looping nodes, such
as node 3, there are also paths that never
end because they loop over and over again.

The University of Sydney Page 21


Exercise
● Please fix the bugs

Answer

The University of Sydney Page 22


Example

Please Calculate the Cyclomatic Complexity


void sort(int * A)
{
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
}
} M=V(G) = 1x While + 1x While +1x if +1 = 4
The University of Sydney Page 23
Example
Please list all the Linear Independent Paths
1. 1-7
2. 1-2-3-4-5-2-6-1-7
void sort(int * A) 3. 1-2-6-7
{ 4. 1-2-3-5-2-6-1-7

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;
};

The University of Sydney Page 25


Cyclomatic Complexity Based Maintenance Estimation

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

The University of Sydney Page 26


Advanced Techology

The University of Sydney Page 27


NLP

The University of Sydney Page 28


NLP

The University of Sydney Page 29


NLP

The University of Sydney Page 30


NLP

The University of Sydney Page 31


ChatGPT

The University of Sydney Page 32


ChatGPT

The University of Sydney Page 33


ChatGPT

The University of Sydney Page 34


ChatGPT

The University of Sydney Page 35


ChatGPT

The University of Sydney Page 36


ChatGPT

The University of Sydney Page 37


The University of Sydney Page 38
The University of Sydney Page 39
ChatGPT

The University of Sydney Page 40


The University of Sydney Page 41
The University of Sydney Page 42
The University of Sydney Page 43
ChatGPT

The University of Sydney Page 44


ChatGPT

– Reinforcement Learning
– If reinforcement learning is under suitable conditions, it can
completely defeat humans and approach the limit of
perfection.

– Reinforcement learning is very similar to biological evolution. In


a given environment, the model is continuously fitted to a state
that is most suitable for the environment according to the
punishment and reward of the environment.

The University of Sydney Page 45


ChatGPT

NLP + Reinforcement Learning


– The reason why reinforcement learning can be easily applied
to Go and other board games is that for alpha Go, the
environment is Go, and the Go board is its entire world. The
model is to constantly adjust the strategy according to the state
of the chessboard and the winning or losing situation.

The University of Sydney Page 46


ChatGPT

The University of Sydney Page 47


ChatGPT

The University of Sydney Page 48


Core Technology

– Generative Pre-Trained Transformer (GPT)


– Reinforcement Learning from Human Feedback (RLHF)

The University of Sydney Page 49


Reinforcement Learning in CV

The University of Sydney Page 50


You reached the end of the lecture.
Thank you and see you next week.

The University of Sydney Page 51

You might also like