0% found this document useful (0 votes)
7 views6 pages

Aoop 2

Aoop

Uploaded by

Sweety Avala
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)
7 views6 pages

Aoop 2

Aoop

Uploaded by

Sweety Avala
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/ 6

He-lab 21cc030025

aVa
stualons wheve endlre
CXample o a Situatlon uwhere TpD ull not wov (Huvde Thnk of
pr cduchor code is Peajulved before shurling 1 festiry phase)
Sol
When Not fo Se TDD
est-driven clevelopmerI is rot occeptan ce tegtirq: You are foly twall piecea ol ode, bd nd

e eneal applicadhao behuviov. for to, yeu Can rely on audorvole d bo lg auch as Cicumber
Ov oryVO. Acceptane lestiwq an be inkgraded wfh cdogst c TDD, and rt on erve as an

exlenaton ofP it.


2. when you dost krao wH AT to lest; Sormetimes you art even dbcoyering Te inlerface and yeaytuireme&
wih os approach you an howe
of youy appladten, for od case H Can be beter to code firgb,
eaS, ond just getftng ind to tlo w an help 9o u to donty Thivgs.

3 Yau ave doirg 9PTkE ding When you're just deslig a new AD er tryy o ncs integration
al a tes-of- proh masp e iH's not the fime fo do TDD p t in Tat phase, pu're trydrg

ditferend arql es n d malke mustake ore nadutol, alter kn0 w'ihe clear rejureners and
inderloce, Phon TDD a0 help move
Vieud tegtirg :Creativ a vicual Teature can be verq arti ve and intudive Coork moybe you
oa

don't krou te inlefoce until it dene AlHey Hrishrg t, pu Con fhinlk obot hauw fe taf n
utome, u tyi to fet iH fhe con bek yoe Cresive mindeet .

2-(ompmve TDD wh Trodlieral Testirg


TDD Ve TRaclttoral lestiry 1DD is a
specitication tchnioyue. tDDhelps enSule hat fe Sourte.
tode of Ve gltoave is tested horcqhly at ihe val dadina tevel.
To tadfioroul degihg, a sutcegstaly eyecfed tegf discoers One ov mare Tan tnebugs Te
Cowo? is in TDD. when a test couse taulS, There s Seme devoopmett or
pregress as ue kreco
hat e problem ras o be radved.
TDD Naet Sure o t e systen meefs al e Speeihed rayauiromerks. T+ helos bea ld and
heost Conticlence in o sytem.
code thot determineS t To feshirq will be Su Ccegshud net. uhile
>TDD empho I 2esproduet or

fradHlo nal tegBirg bcuseg on te deseung of feg Cases, an d also N te fegf will eeate

pvopevy V et to meef the Specki ed yearurement.


Coveog o+ e
fesing is achieve.d.Uulke
traditiovou fegfiny, in TDD we
To TDD, Corvplere
4est Cach Gne of Yho code.
TDP and todltonal fesfirg, when corebines, exploun uly tke festh ng of He syffem is

So impotan
Should hove a peeMic ptrmom e We shbuld be auuare of
SIn cqale modelling,the tegtvg
uhy ae are festirg and te leyel of he feshirg

In-Lob
4- Write a Jova Pregrom 1or caleulator by pa SS i nq al fest cases

: pockoqe source
pubue closS Coleulator

pckage Appl ests ;


import org Junit.Asset;
imPort org junit Tesf
Im powt Cource. Caleulator;

public cla Ss Addi rq Nurmbers Tes fs


new Cl culotorC),
privote Calculator myCaleuloto r
resf
publc void addTuwo Positive Numbers (o

im ex pected ResuH 80
int AcfuoRealh= myCalculatov Add (10,20);
Agsevt asert Eayuals (he Sum of two pasHve numbers Cerre ct" expected Resu l
ActuolResat );

Tesf
pubic void oddTooegutive ANurnbers ()

nt eupecledResuat3o
ind AclualResul- myaleulator.Add (-10, -20);
Agsert acSert toyuals (*The um of fwo hegative humbexsis corr ecd " e peefed Reaah

AectalResu H);

pachage Courte
publuic class altubtor
pubkc ivd Ad d vt number 1, int number 2)

eturn 0

3
Pockage Sourte
puble clasS Caloulator f
publed
Pubke Add ird rumber1, int number
reurnDum ber 1f humber 2)

A code hat
Sinple Scerariai As a developer wnt fo Implement so
prins te numbers
rom to too .
Gaiven an Inpu of numbers frem 1 to6
ohen
A numbev S a
Multide o3 uyo"Fzz"
A Numbey is o1 5 yedurn Bu Zz'
A number ic Ootfooth 3 and 's' retun "
Fizz Butz"
A rumber is not dvisible b3 or Fse lf.
s return he numbe
Then Pint "Fizz", "Buzz", "Fizz Buzz" or he number acordirqy.
Expeded odpuh 1, 2, tizz, 4, Bu22, IL4, Fi2z Bu2z, 16,

Sol. pachage p
importjava util Scanner;
pubuc class fizz Buzz

pubic void Hestmultipeof 8C)

Sydem-eut Println ('Fizz );

pubic vold izzbuzz (tnt num)

for int ount = ( coWnt c num Coun 44) 5


if (ceunt 3 = o)

Hest-muHipleof 3();

pubhc voi d tes_mu tiple of s C)

Suderm-out print In(" Bu?z")


3
eublic Voi d tzeBu2z (it num)s
fov (nt Cowtz () Courct éa num; cour! +-4)

f Ccoant S-= o)
test. mutti ple otaC);
3

Publit void test mudiple of 3 ands ()


Suelem-ou pri ndfo (Frzz buiz)
pudic void hz bu 22int nuon)
for Gnt unt , count cr num, tound ) t
if Ccund Ls - -
o)
test mulpleot 3And sC))

Sypbern-oud printnnunf

puhi'c sadic void maln (hring ] ovgt)


Scanner sC new Scannev (susfem in)
Fi2euzz fe rew Fzz Buz2 ();
int ounte so nautIntC),
for Gnt idr l) idxes count; ldy t)f
=

fFizzbuzz (idx),
F. fauzz (idp);
hazbez Gx)
scclasec);

o acept e pacsuaoy d
when Te krgfh of H
Developmendt progfa
Driven
3. Wvwife a Test vlidador)
s fo 1o darocters
("Pa.sutv d
sheuld be bekoeen
Jnpu
flb cl23

Output:
uer d :acep ted
olid pa
Sol pachage Prac
teirg.Ast dt;
impet org. ferdrg.anndotions, "es
impov+ ovq-
aublic clas TestPasseuDrd
{
Tegd
publc veid
Test Passuerd
O
pubbic ed Test Pacsubvd levgth

paSuoerel Valbidiovbr pve new Pastuerd Validador()


Asserf aRserEryp.als (trat, pe Is Valid (Akci22)

pockag praPassaerd
C; aledodbyf
clais
pubke
pubhc peckean lalid (siniy Passuwbvd
H(pacs
uow d. Ength0) >- 5 £2 Phasuoer d. Ergth )e~ to)
return rue
elte
relarn alse

Post Lab:
N I a java prooram to heck uhether R glven number is odd or even an d do un it fery

inJUnit
Sol pubuc claus vena Oddf
publkc sfadic Gir eyen or odd Gnt number )
retu number 2 =
o? 'ven :
"

odd'

toport avg junt.Test


mpoy+ Static ovq junut. Assert. asert Eayuals
impart ovgunu. runnes JUnt
pubic class EenOrodd Test s
res
publh c void fest Even OrO dd ) f
EvenOrOdd eoo new Even OrO dd ():
a s e t t o n n a l k ( e o o .even oy odd (o), " Even"

aCcert pak (eeo. eyen or ods (a), odd

2. Wvite a JUht test asauming you have too shingkuffer referen Ces name d gbone and s6Tua
0vd u n t o pols N he tuo releven ces
you
point To 1ke Same ShirgBuler ebfel

papkage. SthgEutfevJ 0hi


pubbie cas r ufferUhif
puble shdhe void raln (tig[Jorg#)4

pubhc boslcon) Striny BuPH_ (sthing Butter, skont, Sting Buter sbTuwo) f
Sblwo Sbohe
(sblwb -c bohe )
return fvue
else
rearo ale
package Strivg Butter JUnt;

impoY toch'e org jundt. Asserd-.*,

imPort org9 junit. Tex;


publ c dass JUnit String Bulfer
Teg
pubtc veid feut C) 5

StrivoBAFer okone neo ShingBurferC"hello)


Si noBu fer/ he la")
Shing Butler sblwo neo

Shvivg Butley Uhi Butfer- ntw Sn'ng Buffer ChiC);


boelean hel- st Bulfv.StvirgBuft (fh one tbfuo),
aa.sertEuoals (true, hel);

You might also like