Presentation is loading. Please wait.

Presentation is loading. Please wait.

Specificarea si verificarea sistemelor distribuite

Similar presentations


Presentation on theme: "Specificarea si verificarea sistemelor distribuite"— Presentation transcript:

1 Specificarea si verificarea sistemelor distribuite
Dorel Lucanu

2 Modele AsmL masini cu stari abstracte stari abstracte
caracterizate de valorile variabilelor pasi operationali distincti: tranzitii peste stari abstracte comportarea (executia): secventa de stari conectate prin tranzitii Dorel Lucanu SVSD

3 Evolutia variabilelor de stare
Dorel Lucanu SVSD

4 Exemplu: citirea din fisier
Main() initially F as File? = null initially FContents = "" initially Mode = "Initial" step until fixpoint if Mode = "Initial" then F := new Open("MyFile.txt") Mode := "Reading" if Mode = "Reading" and Length(FContents) = 0 then FContents := Read(F, 1) if Mode = "Reading" and Length(FContents) = 1 then FContents := FContents + Read(F, 1) if Mode = "Reading" and Length(FContents) > 1 then WriteLine(FContents) Mode := "Finished" Dorel Lucanu SVSD

5 Exemplu: citirea din fisier
Dorel Lucanu SVSD

6 Procese secventiale step [label] [stopping-condition] statement-block
until fixpoint until expr while expr Dorel Lucanu SVSD

7 Iteratia de punct fix enum EnumMode Initial Started Finished Main()
initially Mode = Initial initially Count = 0 step until fixpoint if Mode = Initial then Mode := Started Count := 1 if Mode = Started and Count < 10 then Count := Count + 1 if Mode = Started and Count >= 10 then Mode := Finished Dorel Lucanu SVSD

8 Iteratia de punct fix Mode = Initial Count = 0 Mode = Started
Mode = Finished Count = 10 Dorel Lucanu SVSD

9 Iteratia while Main() initially x = 1 step while x < 10
WriteLine(x) x := x + 1 Dorel Lucanu SVSD

10 Iteratia until Main() initially x = 1 step until x > 9 WriteLine(x)
x := x + 1 Dorel Lucanu SVSD

11 Iteratii peste colectii
step foreach ident1 in expr1, ident2 in expr2 ... statement-block exemplu: const myList = [1, 2, 3] Main() step foreach i in myList WriteLine(i) Dorel Lucanu SVSD

12 initially F as File? = null initially FContents = ""
Secventa de pasi Main() initially F as File? = null initially FContents = "" step 1: F := Open("MyFile.txt") step 2: FContents := Read(F, 1) step 3: FContents := FContents + Read(F,1) step 4: WriteLine(FContents) Dorel Lucanu SVSD

13 actualizari var x = 0 // initialize x var y = 1 // initialize y Main()
step WriteLine ("In the first step, x = " + x) // x is 0 WriteLine ("In the first step, y = " + y) // y is 1 x := 2 // update occurs here WriteLine ("In the second step, x = " + x) // x is 2 WriteLine ("In the second step, y = " + y) Dorel Lucanu SVSD

14 actualizari var x = 0 var y = 1 Main() step
WriteLine ("In the first step, x = " + x) WriteLine ("In the first step, y = " + y) x := 2 WriteLine ("In the second step, x = " + x) // x is still 0 Dorel Lucanu SVSD

15 Interschimbarea de valori
var x = 1 var y = 2 Main() step x := y y := x // updates not yet taken effect WriteLine ("In the first step, x = " + x) WriteLine ("In the first step, y = " + y) // updates have taken effect WriteLine ("In the second step, x = " + x) WriteLine ("In the second step, y = " + y) Dorel Lucanu SVSD

16 Actualizarea de multimi
var Students as Set of String = {} Main() step WriteLine ("The initial roster is = " + Students) Students := {"Bill", "Carla", "Duncan", "Amy"} WriteLine ("The final roster is " + Dorel Lucanu SVSD

17 Actualizarea de multimi
var Students as Set of String = {} Main() step WriteLine ("The initial roster is = " + Students) add "Bill" to Students add "Carla" to Students add "Duncan" to Students add "Amy" to Students WriteLine ("The final roster is " + Dorel Lucanu SVSD

18 IsWord(i as Integer) as Boolean return (0 <= i and i <= 0xFFFF)
Metode name( parameter_1 as Type, ...parameter_n as Type ) as Type name este numele metodei ( parameter_1 as Type, ...parameter_n as Type ) este lista valorilor trimise metodei as Type este tipul valorii returnate de metoda (in cazul in care exista) IsWord(i as Integer) as Boolean return (0 <= i and i <= 0xFFFF) Main() step if IsWord(123) then WriteLine("123 is a word of memory.") Dorel Lucanu SVSD

19 Increment() // update procedure Count := Count + 1
Metode var Count = 0 Increment() // update procedure Count := Count + 1 CurrentCount() as Integer // function return Count Main() step Increment() WriteLine("x is " + CurrentCount()) Dorel Lucanu SVSD

20 Variabile locale Main() step mySet1 = {1, 2, 3}
WriteLine("mySet1 has " + Size(mySet1) + " elements.") mySet2 = mySet1 union {4} WriteLine("mySet2 has " + Size(mySet2) + Dorel Lucanu SVSD

21 Supraincarcarea metodelor
Max(i as Integer, j as Integer) as Integer return (if i > j then i else j) Max(s as Set of Integer) as Integer return (any m | m in S where not (exists n in S where n > m)) Main() step WriteLine("The largest number in the set is “ + Max(S)) step WriteLine("The larger of the two integers is “ + Max(2, 3)) Dorel Lucanu SVSD

22 Location(1, 4) este o valoare a structurii Location
structure Location base as Integer offset as Integer Location(1, 4) este o valoare a structurii Location Dorel Lucanu SVSD

23 IsTicketID(i as Integer) as Boolean require i > 0
Asertiuni AllTickets = { } IsTicketID(i as Integer) as Boolean require i > 0 return (i in AllTickets) ChooseAnyTicket() as Integer ensure IsTicketID(result) return (any t | t in AllTickets) Dorel Lucanu SVSD

24 Constante si variabile
x as Integer = 10 // constanta globala // cu tip explicit x = // constanta globala // cu tip implicit variabile: var x as Integer = 10 var x = 10 var greeting as String = "Hello" var y = [1..6] var menu = {"ham", "cheese", "blt"} Dorel Lucanu SVSD

25 var p1 = new Person("William", 40) var p2 = new Person("Amy", 20)
Clase class Person var name as String var age as Integer var p1 = new Person("William", 40) var p2 = new Person("Amy", 20) Main() step p1.name := "Bill" WriteLine("Name of p1 is " + p1.name) WriteLine("Name of p2 is " + p2.name) Dorel Lucanu SVSD

26 RenamePerson(p as Person, newName as String) p.name := newName Main()
Instante ca referinte class Person var name as String var age as Integer RenamePerson(p as Person, newName as String) p.name := newName Main() var p1 = new Person("William", 40) step RenamePerson(p1, "Bill") WriteLine("Name of p1 is " + p1.name) Dorel Lucanu SVSD

27 var Bob = new Person(30, "Jones") var Amy = new Person (20, "Smith")
Clase ca referinte class Person var age as Integer var LastName as String Main() var Bob = new Person(30, "Jones") var Amy = new Person (20, "Smith") var BobsFriend = Amy step BobsFriend.age := 21 WriteLine("Amy's age is " + Amy.age) Dorel Lucanu SVSD

28 return(length * width * height) class FragileBox extends BasicBox
Clase derivate class BasicBox var length as Double var width as Double var height as Double Volume() as Double return(length * width * height) class FragileBox extends BasicBox return(0.85 * length * width * height) Dorel Lucanu SVSD

29 Structuri alternative
structure InputEvent case KeyInput key as Char case SwitcherInput toggle as Boolean case CoinInput coin as Integer case CoinReturn // no data needed HandleInput(e as InputEvent) match e KeyInput(k): WriteLine("Key was pressed: " + k) SwitcherInput(t): WriteLine("Switch flipped: " + t) CoinInput(c): WriteLine("Coin inserted: " + c) CoinReturn(): WriteLine("Coin return pressed.") Dorel Lucanu SVSD

30 C = {(i, j) | i in A where i < 4, j in A where j < i}
Multimi A = {1..5} C = {(i, j) | i in A where i < 4, j in A where j < i} Main() step WriteLine (C) Dorel Lucanu SVSD

31 Evaluare paralela class Person var age as Integer Amy = new Person(20)
Bob = new Person(16) Duncan = new Person(40) People = {Amy, Bob, Duncan} GrowOlder() forall p in People p.age := p.age + 1 var year = 2000 Main() step while year < 2010 WriteLine("Amy's age is " + Amy.age + " in " + year) WriteLine("Bob's age is " + Bob.age + " in " + year) WriteLine("Duncan's age is " + Duncan.age + " in " + year) year := year + 1 Dorel Lucanu SVSD

32 Evaluare paralela Dorel Lucanu SVSD

33 Iteratie secventiala peste o colectie
class Person var age as Integer var Amy = new Person (20) var Bob = new Person (16) var Duncan = new Person (40) People = {Amy, Bob, Duncan} GrowOlder() step foreach p in People p.age := p.age + 1 var year = 2000 Main() step while year < 2010 WriteLine("Amy's age is " + Amy.age + " in " + year) WriteLine("Bob's age is " + Bob.age + " in " + year) WriteLine("Duncan's age is " + Duncan.age + " in " + year) year := year + 1 Dorel Lucanu SVSD

34 Iteratie secventiala peste o colectie
Dorel Lucanu SVSD


Download ppt "Specificarea si verificarea sistemelor distribuite"

Similar presentations


Ads by Google