Download presentation

Presentation is loading. Please wait.

Published bySyed Woodhead Modified about 1 year ago

1
1 ECE 453 – CS 447 – SE 465 Software Testing & Quality Assurance Instructor Kostas Kontogiannis

2
2 Overview Discrete Mathematics for Testers Set Theory Functions Relations Probability Graphs –Representation –Paths –Directed Graphs –Graphs for Testing

3
3 Set Definition Format Explicit enumeration: –Example: Y = {10, 20, 30, 40} Using decision rules: –Examples: Y = {item_number | 80 < item_number < 100} Y = {item_number : 80 < item_number <100} Y = {x | x is positive integer} Y = {x | PI(x)} Empty set: A set with no elements Y = {year : 2012 < year < 1812} = {} = O

4
4 Venn Diagrams Diagrams that illustrate diferent set relationships or illustrate a set with respect to the domain (U) Set operations: –Union : A U B = { x : x in A or x in B} –Intersection: A ∩ B = {x : x in A and x in B} –Complement: A* = {x : x not in A} –Relative complement: A – B = {x : x in A and x not in B} –Symmetric difference: A B = {x: x in A x in B} = = (A U B) – (A ∩ B) + +

5
5 Set Relations and Partitions A Subset B: a in A a in B A Proper Subset B: A subset B and (B – A) ≠ O Equal sets: A = B iff A subset B and B subset A Given a set B and a set of subsets A 1, A 2, A n of B, the subsets are a partition of B iff 1.A 1 U A 2 U.. A n = B 2.For i ≠ j Ai ∩Aj = O

6
6 Functions, Domains, Ranges Given two sets A and B, a function f :A B is a subset of the product A X B such that for any of a i, a j in A, there exist b i, b j in B such that f(a i ) = b i, and f(a j ) = b j. The set A is called the domain of f and B is called the range of f. The function f can be represented as a set of pairs.

7
7 Function Types Functions are further described by the particulars of the mapping e.g. f(A) = {b i in B : b i = f(a i ) for some a i in A} This set is sometimes called the image of A under f Types of functions that relate the image and the range are: Function f is a function of A onto B iff f(A) = B Function f is a function of A into B iff f(A) proper subset B Function f is a one-to-one function from A to B iff for all a i, a j in A, s.t. a i ≠a j implies that f(a i ) ≠ f(a j )

8
8 Function Composition Suppose we have sets and functions such that the range of one is the domain of the next: –f: A B –g: B C –h: C D We can define a new function w:A D such that w(a) = (h o g o f) (a) = h(g(f(a))) So, if f(a) = b, and g(b) = c, and h(c) = d then w(a) = h(g(f(a))) = h(g(b)) = h(c) = d

9
9 Application Snapshot Causal Flow Non-Causal Flow a f b g c a f g c b b b B

10
10 Relations Given two sets A, B a relation R is a subset of the Cartesian product A X B Functions are a special case of a relation: –Both are subsets of some Cartesian product –Functions have the additional requirement that a domain element can not be associated with more than one range element. When a relation is not a function then is also called a mapping. A relation has a property called cardinality

11
11 Relations among Sets Given two sets A, B, and a relation R among these sets, the cardinality of R is: –one-to-one iff R is a one-to-one function from A to B –many-to-one: iff R is a many-to-one function from A to B –one-to-many: iff at least one element a in A is in two ordered pairs in R, that is (a, b i ) in R and (a, b j ) in R. –many-to-many: iff at least one element a in A is in two ordered pairs in R, that is (a, b i ) in R and (a, b j ) in R and one element b in B is in two ordered pairs in R, that is (a k, b) in R and (a n, b) in R

12
12 Participation of a Relation Let R be a relation s.t. R is a subset of A X B The participation of the relation R can be: –total participation: iff every element of A is in some ordered pair in R –partial participation: iff some element of A is not in any ordered pair in R –onto participation: iff every element of B is in some ordered pair in R –into participation: iff some element of B is not in some element in R

13
13 Relations on a Single Set Let R be a relation defined in the same set A X A A relation R is: –reflexive: iff for all a in A in R –symmetric: iff in R then in R –anti-symmetric: if in R and in R then it implies that a=b –transitive: iff in R and in R then in R Such a relation R is an ordering relation if it is reflexive, anti-symmetric and, transitive. Similarly, R is an equivalence relation if it is reflexive, symmetric, and transitive.

14
14 Propositional Logic Propositions are sentences specified in propositional logic notation that can be evaluated to True or False. A simple proposition (e.g. p, q, r) is a valid sentence Valid sentences can be constructed by other sentences using logical operators (and, or, not, implies, exclusive_or) Two proposition logic sentences are equivalent iff their truth tables are identical (e.g. S= p q) is equivalent with the sentence W = ~p or q) A proposition is a tautology if it is always true (e.g. S = a or ~a) A proposition is a contradiction if it is always false (e.g. S = a and ~a)

15
15 Probability Theory Events: things that happen Universe of Discourse: all events that can possibly happen, and is denoted by U. Let p is a proposition about elements in U: –The truth set of a proposition p, written T(p), is the set of all elements in U for which p is true (note T(p) U T(~p) = U) –The probability that a proposition p is true is defined as Pr(p) = |T(p)| / |U| The definition of U is crucial on determining the value of Pr(p) Facts: –Pr(~p) = 1 – P(p) –Pr(p and q) = Pr(p) * Pr(q) –Pr(p or q) = Pr(p) + Pr(q) – Pr(p and q)

16
16 Graph Theory for Testers A graph G = (V, E) is composed of a finite and non empty set V = {n 1, n 2, n m ) of nodes and a set E = {e 1, e 2, e p } of edges, where each edge e k = {n i, n j }, for some nodes n i, n j in V.

17
17 Example e1 e2 e3 e4 e5 n1 n3 n6 n4 n5 n2 n7 V = {n1, n2, n3, n4, n5, n6, n7} E = {e1, 2, e3, e4, e5} = {{n1, n2}, {n1, n4}, {n3, n4}, {n2, n5}, {n4, n6}} Degree of a node: the number of edges that have the node as an endpoint. Example: deg(n1) = 2, deg(n7) = 0, deg(n4) = 3.

18
18 Incidence Matrices An incidence matrix of a graph G = (V, E) with m nodes and n edges is an m X n matrix where the elements in row i, and column j is 1 iff node i is an endpoint of edge j, otherwise is 0. e1e2e3e4e5 n n n n n n n700000

19
19 Adjacency matrix The adjacency matrix of a graph G = (V, E) with m nodes, and n edges, is an m X m matrix, where the elements in row i and column j is 1 iff there is an edge between node i and node j, otherwise is 0. n1n2n3n4n5n6n7 n n n n n n n

20
20 Paths A path is a sequence of edges such that, for any adjacent pair of edges e i, e j in the sequence, the edges share a common node as an endpoint. Paths can be described either as a sequence of edges, or as a sequence of nodes. Paths are defined between a source node and a target node.

21
21 Example Paths Path (from-to)Node sequenceEdge sequence n1 – n5n1, n2, n5e1, e4 n6 – n5n6, n4, n1, n2, n5e5, e2, e1, e4 n3 – n2n3, n4, n1, n2e3, e2, e1

22
22 Connectedness Nodes n i, n j are connected iff there is a path from node n i to node n j “Connectedness” is an equivalence relation on the node set of a graph “Connectedness” defines a partition on the node set of a graph. A component of a graph is a maximal set of connected nodes Example: Two components in the sample graph C1 = {n1, n2, n3, n4, n5, n6}, and C2 = :n7}

23
23 Condensation Graphs Given a graph G = (V, E), its condensation graph is formed by replacing each component by a condensing node. C1 n7

24
24 Complexity of a Graph A measure of the complexity of a graph is its cyclomatic complexity measure. The cyclomatic complexity of a graph G, is a number V(G) = e – n + 2, where e is the number of edges in the graph, and n is the number of vertices (nodes) in the graph.

25
25 Directed Graphs A directed graph (or digraph) D = (V, E), consists of a finite set of vertices V = {n 1, n 2, … n m }, and a set of edges E = {e 1, e 2, e p }, where each edge e k = is an ordered pair of nodes in V.

26
26 Example Directed Graph e1 e2 e3 e4 e5 n1 n3 n6 n4 n5 n2 n7 V = {n1, n2, n3, n4, n5, n6, n7} E = {e1, 2, e3, e4, e5} = {,,,, }

27
27 Properties of Directed Graphs The indegree (or fan-in) of a node in a directed graph is the number of distinct edges that have the node as a terminal node (target node). Example: indeg(n1) = 0, indeg(n4) = 2 The outdegree (or fan-out) of a node in a directed graph is the number of distinct edges that have the node as a start node (source node). Example: outdeg(n1) = 2, outdeg(n6) = 0 A node with in indegree = 0 is called a source node (n1, n3, n7) A node with outdegree = 0 is called a sink node (n5, n6, n7) A node with indegree ≠ 0 and outdeg ≠ 0 is called a transfer node (n2, n4) A node that is both a source and a sink is an isolated node The source and sink nodes in a graph constitute the external boundary of the graph

28
28 Adjacency Matrix of a Directed Graph The adjacency matrix of a directed graph D = (V, E) with m nodes is an m X m matrix which in row i and column j there is an entry equal to 1 iff there is an edge from node i to node j, otherwise the entry is equal to 0 The sum of a row is the outdegree of a node The sum of a column is the indegree of a node

29
29 Paths and Semi-Paths A directed path is a sequence of edges such that, for any adjacent set of edges e i, e j in the sequence, the terminal node of e i is the initial node of e j A cycle is a directed path that begins and ends in the same node A directed semi-path is a sequence of edges such that, for at least one adjacent pair of edges e i, e j in the sequence, the initial node of the first edge is the initial node of the second edge or the terminal node of the first edge is the terminal node of the second edge Directed paths are also called chains Example: There is a path from n1 to n6, There is a semi-path between n1 and n3 There is a semi-path between n2 and n4 There is a semi-path between n5 and n6

30
30 Reachability Matrix The reachability matrix of a directed graph D = (V, E) with m nodes is an m X m matrix R = (r(i, j)), where the entry r(i, j) = 1 iff there is a path from node i to node j, otherwise the entry is equal to 0 The reachability matrix R can be computed as R= I + A + A 2 + … + A k where k is the length of the longest path in D n1n2n3n4n5n6n7 n n n n n n n

31
31 N-Connectedness Two nodes n i and n j in a directed graph are: –0-connected: iff there is no path from n i to n j –1-connected: iff there is a semi-path but no path between n i, n j –2-connected: iff there is a path between n i, n j –3-connected: iff there is a path from n i to n j and a path from n j to n i A strong component of a directed graph is the maximal set of 3-connected nodes

32
32 Example e1 e2 e3 e4 e5 n1 n3 n6 n4 n5 n2 n7 e6 n1 and n7 are 0-connected n2 and n6 are 1-connected n1 and n6 are 2-connected n3 and n6 are 3-connected

33
33 Condensation Graph of a DiGraph A condensation graph is a a graph D'=(V',E') based on the directed graph D=(V,E) where each vertex in V' corresponds to a strongly connected component in D and edge (u,v) is in E' if and only if there exists an edge in E connecting any of the vertices in the component of u to any of the vertices in the component of v.

34
34 Example Condensation DiGraph e1 e2 e4 n1 C1 n5 n2 n7

35
35 Example Condensation Graph Condensation Graph

36
36 Program Graphs Given a program written in an imperative programming language, its program graph is a directed graph in which: –Nodes are program statements (or statement fragments), and edges represent flow of control Control flow of imperative programs is defined by sequencing, iteration, and choice constructs

37
37 Digraphs of the Structured Programming Constructs s1 s2 s1 s2 s1 s2 s1 s2 s1 s2 s1 s2 Sequence if-then-else case if-then loop-pre-test loop-post-test

38
38 Finite State Machines A Finite State Machine (FSM) is a directed graph (S, T, Ev, Act, Guard), in which S is a set of nodes, T is a set of edges, and Ev, Act, Guard are sets of events, actions, and guards associated with the transitions in T.

39
39 Example FSM (with events, actions and guards) SellingSelling UnhappyUnhappy HappyHappy bid /sell bid [(value >= 100) & (value < 200)] /sell bid /sell bid [value >= 200] /sell bid /reject bid [value < 100] /reject

40
40 Petri-Nets A Petri-Net is a bipartite graph (P, T, In, Out), in which P, T are disjoint sets of nodes and In and Out are sets of edges, where In is a subset of P X T, and out is a subset of T X P A marked Petri-Net is a 5-tuple (P, T, In, Out, M) in which (P, T, In, Out) is a Petri-Net and M is a set of mappings of places to positive integers (number of tokens in a Place) A transition in a Petri-Net is enabled when there is at least one token in each input place When an enabled transition fires one token is removed from each of its input places and is added in each of the output places

41
41 Example p1 p5 p2 p3 p4 t1 t3 t2 P = {p1, p2, p3, p4, p5} T = {t1, t2, t3} In = {,,,, } Out = {,, } M =

42
42 Example Petri Net

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google