Вы находитесь на странице: 1из 4

Universitatea Tehnică a Moldovei

Facultatea „Calculatoare, informatică și microelectronică”


Filiera anglofonă „Computer science”

RAPORT
Lucrarea de laborator nr.3
la Testarea și verificarea produselor program

Tema: Metode de testare a programelor. Metoda cutiei transparente de


testare a programelor

A efectuat: I. Ungureanu

Chișinău - 2017
A fair coin will be tossed until the first time it comes up heads. If this occurs on the jth toss
you are paid 2 to power j dollars. You are sure to win at least 2 dollars so you should be willing to
pay to play this game but how much? See if you can decide, by simulation, a reasonable amount
that you would be willing to pay, per game, if you will be allowed to make a large number of plays
of the game.

list_=[]
yaxis=[]
xaxis=[]
n=10000
purple='#8b475d'
profit1=0
def coin_game(nr_tosses):
list_=[]
counter=1
profit=0
for i in range(n):
while counter<nr_tosses:
profit=0
coin=random.randint(1,2)
if coin==1:
counter=counter+1
if coin==2: #heads
profit=2**counter
counter=1
break
list_.append(profit)
average_profit=sum(list_)/n
return average_profit

for i in range (1,101):


profit1=coin_game(i)
xaxis.append(i)
yaxis.append(profit1)
#print("for", i ,"plays, the average profit is",
format(profit1,'.3f'))
general_av=sum(yaxis)/100
print("Average profit:", format(general_av,'.2f'),"$")

plt.plot(xaxis,yaxis,'.-', color='purple')
plt.xlabel("Number of tosses")
plt.ylabel("Average profit")
plt.grid(True)
plt.show
plt.savefig('problem1.png')
Input data:
nr_tosses – represents the number of tosses that will be simulated by the function
Output data:
average_profit – represents the sum of profits divided by the number of games
For simplicity n = 1

TC ID Input Path Result


1 nr_tosses = 0 1-2-3-4-12-13-14 0
nr_tosses = 1
2 1-2-3-4-12-13-14 2
(coin == 2)
nr_tosses = 1
3 1-2-3-4-12-13-14 0
(coin == 1)
nr_tosses = 2
1-2-3-(4-5-6-7-8)-
4 (coin == 1 and 0
2times – 12-13-14
coin == 1)
nr_tosses = 2 1-2-3-4-5-6-7-9-10-
5 2
(coin == 2) 11-12-13-14
nr_tosses = 2
1-2-3-4-5-6-7-8-4-5-
6 (coin == 1 and 4
6-7-9-10-11-12-13-14
coin == 2)
7 nr_tosses = a error error
8 nr_tosses = -1 1-2-3-4-12-13-14 0

C = vertices – nodes + 2 = 20 – 16 + 2 = 6

Conclusion:
During this laboratory work, I worked with white box techniques. After testing the code, I observed
a little mistake in the implementation: in the while condition there should be a smaller or equal
sign (≤) instead of a smaller sign (<). It is because, from the condition we understand that 1 toss
is also possible and the sign did not allow the program to simulate only one coin toss.

Вам также может понравиться