— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet113/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   109   110   111   112   113   114   115   116   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Extreme Programming (XP)
 prep code test code
real code
test code


102
 
chapter 5
Writing test code for the SimpleDotCom class


METHOD 
String checkYourself(String userGuess)
GET 
the user guess as a String parameter
CONVERT 
the user guess to an 
int
REPEAT 
with each of the location cells in the 
int 
array 
// 
COMPARE 
the user guess to the location cell 
IF 
the user guess matches
INCREMENT 
the number of hits
// FIND OUT
if it was the last location cell:
IF
number of hits is 3, 
RETURN 
“Kill” as the result
ELSE
it was not a kill, so 
RETURN
“Hit”
END IF
ELSE 
the user guess did not match, so 
RETURN 
“Miss”
END IF
END REPEAT
END METHOD
We need to write test code that can make a SimpleDotCom object 
and run its methods. For the SimpleDotCom class, we really 
care about only the checkYourself() method, although we will have 
to implement the setLocationCells() method in order to get the 
checkYourself() method to run correctly.
Take a good look at the prepcode below for the checkYourself() 
method (the setLocationCells() method is a no-brainer setter method, 
so we’re not worried about it, but in a ‘real’ application we might 
want a more robust ‘setter’ method, which we would want to test).
Then ask yourself, “If the checkYourself() method were 
implemented, what test code could I write that would prove to me 
the method is working correctly?”
1. Instantiate a SimpleDotCom object.
2. Assign it a location (an array of 3 ints, like 
{2,3,4}).
3. Create a String to represent a user guess 
(“2”, “0”, etc.).
4. Invoke the checkYourself() method pass-
ing it the fake user guess.
5. Print out the result to see if it’s correct 
(“passed” or “failed”).
Based
on this
prepcode:
Here’s what we should test:

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   109   110   111   112   113   114   115   116   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish