Advertisement
agmike

test.lutil.intmap.gs

Aug 12th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.84 KB | None | 0 0
  1. /* LSE_FILE_HEADER */
  2.  
  3. include "lutil.intmap.gs"
  4.  
  5.  
  6. static class Test_LIntMap_Static
  7. {
  8.     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,"
  9.                                      + "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,"
  10.                                      + "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,"
  11.                                      + "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,"
  12.                                      + "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,"
  13.                                      + "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,"
  14.                                      + "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,"
  15.                                      + "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,"
  16.                                      + "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,"
  17.                                      + "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,"
  18.                                      + "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,"
  19.                                      + "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,"
  20.                                      + "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,"
  21.                                      + "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,"
  22.                                      + "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"
  23.                                      + "volcano,wealth,weather,wilderness,wren,wrist,writer", ",");
  24.    
  25.     public LIntMap CreateFilled()
  26.     {
  27.         LIntMap map = LCons.CreateIntMap();
  28.         int i, count = words.size();
  29.         for (i = 0; i < count; ++i)
  30.             map.Set(words[i], LHash.Calculate(words[i]));
  31.         return map;
  32.     }
  33. };
  34.  
  35.  
  36. class Test_LIntMap_GetSet isclass LTestCase
  37. {
  38.     string[] words = Test_LIntMap_Static.Words;
  39.  
  40.     public void Run(LTestContext test)
  41.     {
  42.         LIntMap map = Test_LIntMap_Static.CreateFilled();
  43.         test.Log(map.GetLogString());
  44.         for (i = 0; i < count; ++i)
  45.             test.Assert(map.TryGet(words[i]) and map.LastValue == LHash.Calculate(words[i]));
  46.         test.Success();
  47.     }
  48. };
  49.  
  50. class Test_LIntMap_ToSoup isclass LTestCase
  51. {
  52.     string[] words = Test_LIntMap_Static.Words;
  53.  
  54.     public void Run(LTestContext test)
  55.     {
  56.         LIntMap map = Test_LIntMap_Static.CreateFilled();
  57.         Soup sp = map.ToSoup();
  58.         LIntMap mapFromSoup = LCons.CreateIntMap(sp);
  59.         for (i = 0; i < count; ++i) {
  60.             test.Assert(LData.GetInt(sp, words[i], -1) == LHash.Calculate(words[i]), "soup has missing values");
  61.             test.Assert(mapFromSoup.TryGet(words[i]) == LHash.Calculate(words[i]), "map created from soup has missing values");
  62.         }
  63.         test.Assert(sp.CountTags() == count, "soup has additional tags");
  64.         test.Assert(mapFromSoup.Count() == count, "map created from soup has additional tags");
  65.         test.Success();
  66.     }
  67. };
  68.  
  69. class Test_LIntMap_Remove isclass LTestCase
  70. {
  71.     string[] words = Test_LIntMap_Static.Words;
  72.  
  73.     bool IsRemoved(int index) { return index % 4 == 0; }
  74.  
  75.     public void Run(LTestContext test)
  76.     {
  77.         LIntMap map = Test_LIntMap_Static.CreateFilled();
  78.         for (i = 0; i < count; ++i)
  79.             if (IsRemoved(i))
  80.                 map.Remove(words[i]);
  81.        
  82.         for (i = 0; i < count; ++i) {
  83.             bool contains = map.TryGet(words[i]);
  84.             test.Assert(IsRemoved(words[i]) == contains);
  85.         }
  86.        
  87.         test.Success();
  88.     }
  89. };
  90.  
  91.  
  92. static class Tests_LIntMap isclass LTestSuit
  93. {
  94.     public void Run(LTestEngine e)
  95.     {
  96.         e.RunCase(new Test_LIntMap_GetSet());
  97.         e.RunCase(new Test_LIntMap_ToSoup());
  98.         e.RunCase(new Test_LIntMap_Remove());
  99.     }
  100. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement