Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* LSE_FILE_HEADER */
- include "lutil.intmap.gs"
- static class Test_LIntMap_Static
- {
- public string[] Words = Str.Tokens("ball,bat,bed,book,boy,bun,can,cake,cap,car,cat,cow,cub,cup,dad,day,dog,doll,dust,fan,feet,girl,gun,hall,hat,hen,jar,kite,man,map,"
- + "men,mom,pan,pet,pie,pig,pot,rat,son,sun,toe,tub,van,apple,arm,banana,bike,bird,book,chin,clam,class,clover,club,corn,crayon,crow,crown,crowd,crib,"
- + "desk,dime,dirt,dress,fang,field,flag,flower,fog,game,heat,hill,home,horn,hose,joke,juice,kite,lake,maid,mask,mice,milk,mint,meal,meat,moon,mother,morning,name,nest,"
- + "nose,pear,pen,pencil,plant,rain,river,road,rock,room,rose,seed,shape,shoe,shop,show,sink,snail,snake,snow,soda,sofa,star,step,stew,stove,straw,string,summer,swing,"
- + "table,tank,team,tent,test,toes,tree,vest,water,wing,winter,woman,women,alarm,animal,aunt,bait,balloon,bath,bead,beam,bean,bedroom,boot,bread,brick,brother,camp,chicken,children,"
- + "crook,deer,dock,doctor,downtown,drum,dust,eye,family,father,fight,flesh,food,frog,goose,grade,grandfather,grandmother,grape,grass,hook,horse,jail,jam,kiss,kitten,light,loaf,lock,lunch,"
- + "lunchroom,meal,mother,notebook,owl,pail,parent,park,plot,rabbit,rake,robin,sack,sail,scale,sea,sister,soap,song,spark,space,spoon,spot,spy,summer,tiger,toad,town,trail,tramp,"
- + "tray,trick,trip,uncle,vase,winter,water,week,wheel,wish,wool,yard,zebra,actor,airplane,airport,army,baseball,beef,birthday,boy,brush,bushes,butter,cast,cave,cent,cherries,cherry,"
- + "cobweb,coil,cracker,dinner,eggnog,elbow,face,fireman,flavor,gate,glove,glue,goldfish,goose,grain,hair,haircut,hobbies,holiday,hot,jellyfish,ladybug,mailbox,number,oatmeal,pail,pancake,pear,pest,popcorn,"
- + "queen,quicksand,quiet,quilt,rainstorm,scarecrow,scarf,stream,street,sugar,throne,toothpaste,twig,volleyball,wood,wrench,advice,anger,answer,apple,arithmetic,badge,basket,basketball,battle,beast,beetle,beggar,brain,"
- + "branch,bubble,bucket,cactus,cannon,cattle,celery,cellar,cloth,coach,coast,crate,cream,daughter,donkey,drug,earthquake,feast,fifth,finger,flock,frame,furniture,geese,ghost,giraffe,governor,honey,"
- + "hope,hydrant,icicle,income,island,jeans,judge,lace,lamp,lettuce,marble,month,north,ocean,patch,plane,playground,poison,riddle,rifle,scale,seashore,sheet,sidewalk,skate,slave,sleet,smoke,stage,"
- + "station,thrill,throat,throne,title,toothbrush,turkey,underwear,vacation,vegetable,visitor,voyage,year,able,achieve,acoustics,action,activity,aftermath,afternoon,afterthought,apparel,appliance,beginner,believe,bomb,border,boundary,"
- + "breakfast,cabbage,cable,calculator,calendar,caption,carpenter,cemetery,channel,circle,creator,creature,education,faucet,feather,friction,fruit,fuel,galley,guide,guitar,health,heart,idea,kitten,laborer,language,lawyer,linen,locket,lumber,magic,"
- + "minister,mitten,money,mountain,music,partner,passenger,pickle,picture,plantation,plastic,pleasure,pocket,police,pollution,railway,recess,reward,route,scene,scent,squirrel,stranger,suit,sweater,temper,territory,texture,thread,treatment,veil,vein"
- + "volcano,wealth,weather,wilderness,wren,wrist,writer", ",");
- public LIntMap CreateFilled()
- {
- LIntMap map = LCons.CreateIntMap();
- int i, count = words.size();
- for (i = 0; i < count; ++i)
- map.Set(words[i], LHash.Calculate(words[i]));
- return map;
- }
- };
- class Test_LIntMap_GetSet isclass LTestCase
- {
- string[] words = Test_LIntMap_Static.Words;
- public void Run(LTestContext test)
- {
- LIntMap map = Test_LIntMap_Static.CreateFilled();
- test.Log(map.GetLogString());
- for (i = 0; i < count; ++i)
- test.Assert(map.TryGet(words[i]) and map.LastValue == LHash.Calculate(words[i]));
- test.Success();
- }
- };
- class Test_LIntMap_ToSoup isclass LTestCase
- {
- string[] words = Test_LIntMap_Static.Words;
- public void Run(LTestContext test)
- {
- LIntMap map = Test_LIntMap_Static.CreateFilled();
- Soup sp = map.ToSoup();
- LIntMap mapFromSoup = LCons.CreateIntMap(sp);
- for (i = 0; i < count; ++i) {
- test.Assert(LData.GetInt(sp, words[i], -1) == LHash.Calculate(words[i]), "soup has missing values");
- test.Assert(mapFromSoup.TryGet(words[i]) == LHash.Calculate(words[i]), "map created from soup has missing values");
- }
- test.Assert(sp.CountTags() == count, "soup has additional tags");
- test.Assert(mapFromSoup.Count() == count, "map created from soup has additional tags");
- test.Success();
- }
- };
- class Test_LIntMap_Remove isclass LTestCase
- {
- string[] words = Test_LIntMap_Static.Words;
- bool IsRemoved(int index) { return index % 4 == 0; }
- public void Run(LTestContext test)
- {
- LIntMap map = Test_LIntMap_Static.CreateFilled();
- for (i = 0; i < count; ++i)
- if (IsRemoved(i))
- map.Remove(words[i]);
- for (i = 0; i < count; ++i) {
- bool contains = map.TryGet(words[i]);
- test.Assert(IsRemoved(words[i]) == contains);
- }
- test.Success();
- }
- };
- static class Tests_LIntMap isclass LTestSuit
- {
- public void Run(LTestEngine e)
- {
- e.RunCase(new Test_LIntMap_GetSet());
- e.RunCase(new Test_LIntMap_ToSoup());
- e.RunCase(new Test_LIntMap_Remove());
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement