Guest User

typeof testing

a guest
May 16th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.11 KB | None | 0 0
  1.         let succ = 0;
  2.         let failed = 0;
  3.         let total = 0;
  4.        
  5.         let failids = [];
  6.         let succids = [];
  7.        
  8.        
  9.         let div ="------------------------------------";
  10.         let warn="   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   ";
  11.        
  12.         function test(v, expected){
  13.             total++;
  14.             let type = typeof(v);
  15.             if(type!=expected){
  16.                 failed++; failids=failids~[total];
  17.                 WriteLog(div);
  18.                 WriteLog("Test No."~itoa(total));
  19.                 WriteLog("Test input:       "~ToString(v));
  20.                 WriteLog("Test output:      "~TypeToString(type));
  21.                 WriteLog("Expected out:     "~TypeToString(expected));
  22.                 // if(type!=expected){ WriteLog(warn); }
  23.             }else{
  24.                 succ++; succids=succids~[total];
  25.             }
  26.         }
  27.        
  28.        
  29.         let known = [9,10,12,14,18,22,23,31,34,36];
  30.        
  31.         //Test ID starts at 1 on next line
  32.         test(123,               TYPE_REAL);    
  33.         test("123",             TYPE_STRING);  
  34.         test("2-2",             TYPE_STRING);  
  35.         test(12.3,              TYPE_REAL);    
  36.         test(true,              TYPE_BOOL);    
  37.         test(false,             TYPE_BOOL);    
  38.         test('1',               TYPE_CHAR);    
  39.         test('f',               TYPE_CHAR);    
  40.         test("8",               TYPE_STRING);    // !
  41.         test("F",               TYPE_STRING);    // !
  42.         test("foo",             TYPE_STRING);    
  43.         test("true",            TYPE_STRING);    // !
  44.         test("123-",            TYPE_STRING);    
  45.         test("-1.000000",       TYPE_STRING);    // !
  46.         test("--5",             TYPE_STRING);    
  47.         test(0.0000000001,      TYPE_REAL);      
  48.         test(NULL,              TYPE_REAL);      
  49.         test([],                TYPE_ARRAY);     // !  
  50.         test("",                TYPE_STRING);    //.
  51.         test([0],               TYPE_ARRAY);    
  52.         test([0,1],             TYPE_ARRAY);    
  53.         test(['a','b'],         TYPE_ARRAY);     // !
  54.         test(['1','2'],         TYPE_ARRAY);     // !
  55.         test([[0],[1]],         TYPE_ARRAY);    
  56.         test([[[]]],            TYPE_ARRAY);
  57.         test(1/0,               TYPE_UNDEFINED);
  58.         test(0/0,               TYPE_UNDEFINED);
  59.         test(-(0/0),            TYPE_UNDEFINED);
  60.         test("[]",              TYPE_STRING);
  61.         test("[ [ ]",           TYPE_STRING);
  62.         test("[ [ dsad ] ]",    TYPE_STRING);    // !
  63.         test('[',               TYPE_CHAR);
  64.         test("[,]",             TYPE_STRING);
  65.         test(["a","[",","],     TYPE_ARRAY);     // !!
  66.         test(["a","[","a]b"],   TYPE_ARRAY);    
  67.         test(["a",  "[","a[]b"],TYPE_ARRAY);     // !!
  68.  
  69.  
  70.         WriteLog(div);
  71.         if(failed>0){WriteLog(warn);}else{loop(3){WriteLog(div);}}
  72.         WriteLog("TESTS FAILED: "~itoa(failed)~" OF "~itoa(total));
  73.        
  74.         ascent(i in 0..length(known)){ascent(j in 0..length(failids)){
  75.             if(known[i]==failids[j]){failids=erase(failids,j);break;}
  76.         }}
  77.         let tmp=succids; let kf;
  78.         descent(j in 0..length(succids)){kf=false;ascent(i in 0..length(known)){
  79.             if(known[i]==succids[j]){kf=true;}}  if(!kf){tmp=erase(tmp,j);}
  80.         }succids=tmp;
  81.         if(length(failids)>0){
  82.             let s="[ "; ascent(i in 0..length(failids)){s=s~tost(failids[i])~" ";} s=s~"]";
  83.             WriteLog(itoa(length(failids))~" unexpected failures: "~s);
  84.         }else{ WriteLog("No unexpected failures"); }
  85.         if(length(succids)>0){
  86.             let s="[ "; ascent(i in 0..length(succids)){s=s~tost(succids[i])~" ";} s=s~"]";
  87.             WriteLog(itoa(length(succids))~" unexpected successes: "~s);
  88.         }else{ WriteLog("No unexpected successes"); }
  89.         if(failed>0){WriteLog(warn);}
  90.         else{WriteLog("ALL "~itoa(total)~" TESTS PASSED");loop(3){WriteLog(div);}}
Advertisement
Add Comment
Please, Sign In to add comment