Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let succ = 0;
- let failed = 0;
- let total = 0;
- let failids = [];
- let succids = [];
- let div ="------------------------------------";
- let warn=" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ";
- function test(v, expected){
- total++;
- let type = typeof(v);
- if(type!=expected){
- failed++; failids=failids~[total];
- WriteLog(div);
- WriteLog("Test No."~itoa(total));
- WriteLog("Test input: "~ToString(v));
- WriteLog("Test output: "~TypeToString(type));
- WriteLog("Expected out: "~TypeToString(expected));
- // if(type!=expected){ WriteLog(warn); }
- }else{
- succ++; succids=succids~[total];
- }
- }
- let known = [9,10,12,14,18,22,23,31,34,36];
- //Test ID starts at 1 on next line
- test(123, TYPE_REAL);
- test("123", TYPE_STRING);
- test("2-2", TYPE_STRING);
- test(12.3, TYPE_REAL);
- test(true, TYPE_BOOL);
- test(false, TYPE_BOOL);
- test('1', TYPE_CHAR);
- test('f', TYPE_CHAR);
- test("8", TYPE_STRING); // !
- test("F", TYPE_STRING); // !
- test("foo", TYPE_STRING);
- test("true", TYPE_STRING); // !
- test("123-", TYPE_STRING);
- test("-1.000000", TYPE_STRING); // !
- test("--5", TYPE_STRING);
- test(0.0000000001, TYPE_REAL);
- test(NULL, TYPE_REAL);
- test([], TYPE_ARRAY); // !
- test("", TYPE_STRING); //.
- test([0], TYPE_ARRAY);
- test([0,1], TYPE_ARRAY);
- test(['a','b'], TYPE_ARRAY); // !
- test(['1','2'], TYPE_ARRAY); // !
- test([[0],[1]], TYPE_ARRAY);
- test([[[]]], TYPE_ARRAY);
- test(1/0, TYPE_UNDEFINED);
- test(0/0, TYPE_UNDEFINED);
- test(-(0/0), TYPE_UNDEFINED);
- test("[]", TYPE_STRING);
- test("[ [ ]", TYPE_STRING);
- test("[ [ dsad ] ]", TYPE_STRING); // !
- test('[', TYPE_CHAR);
- test("[,]", TYPE_STRING);
- test(["a","[",","], TYPE_ARRAY); // !!
- test(["a","[","a]b"], TYPE_ARRAY);
- test(["a", "[","a[]b"],TYPE_ARRAY); // !!
- WriteLog(div);
- if(failed>0){WriteLog(warn);}else{loop(3){WriteLog(div);}}
- WriteLog("TESTS FAILED: "~itoa(failed)~" OF "~itoa(total));
- ascent(i in 0..length(known)){ascent(j in 0..length(failids)){
- if(known[i]==failids[j]){failids=erase(failids,j);break;}
- }}
- let tmp=succids; let kf;
- descent(j in 0..length(succids)){kf=false;ascent(i in 0..length(known)){
- if(known[i]==succids[j]){kf=true;}} if(!kf){tmp=erase(tmp,j);}
- }succids=tmp;
- if(length(failids)>0){
- let s="[ "; ascent(i in 0..length(failids)){s=s~tost(failids[i])~" ";} s=s~"]";
- WriteLog(itoa(length(failids))~" unexpected failures: "~s);
- }else{ WriteLog("No unexpected failures"); }
- if(length(succids)>0){
- let s="[ "; ascent(i in 0..length(succids)){s=s~tost(succids[i])~" ";} s=s~"]";
- WriteLog(itoa(length(succids))~" unexpected successes: "~s);
- }else{ WriteLog("No unexpected successes"); }
- if(failed>0){WriteLog(warn);}
- else{WriteLog("ALL "~itoa(total)~" TESTS PASSED");loop(3){WriteLog(div);}}
Advertisement
Add Comment
Please, Sign In to add comment