From c21d40c4664797e82e50c3095b48ba1b3006efc6 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Wed, 3 Mar 2021 09:20:42 +0800 Subject: [PATCH] change test files --- test/NasNeuron.nas | 96 ------- test/ai.nas | 1 - test/ascii-art.nas | 6 +- test/bfs.nas | 8 +- test/choose.nas | 38 --- test/class.nas | 19 ++ test/first_pro.nas | 6 - test/func.nas | 10 - test/lexer.nas | 6 +- test/lib.nas | 90 +++---- test/loop.nas | 1 + test/main.nas | 382 --------------------------- test/{final2.nas => multiplayer.nas} | 0 test/neo4j.nas | 50 ++-- test/prop.nas | 246 ----------------- test/props.nas | 35 +-- test/queue.nas | 51 ++-- test/scalar.nas | 50 +++- test/scope.nas | 18 +- test/{final.nas => smartscreen.nas} | 0 test/string.nas | 5 - 21 files changed, 189 insertions(+), 929 deletions(-) delete mode 100644 test/NasNeuron.nas delete mode 100644 test/choose.nas create mode 100644 test/class.nas delete mode 100644 test/first_pro.nas delete mode 100644 test/func.nas delete mode 100644 test/main.nas rename test/{final2.nas => multiplayer.nas} (100%) delete mode 100644 test/prop.nas rename test/{final.nas => smartscreen.nas} (100%) delete mode 100644 test/string.nas diff --git a/test/NasNeuron.nas b/test/NasNeuron.nas deleted file mode 100644 index ae2a951..0000000 --- a/test/NasNeuron.nas +++ /dev/null @@ -1,96 +0,0 @@ -# NasNeuron lib written by ValKmjolnir - -# Basic Class NasMatrix -# NasMatGen : generate a new matrix -# NasMatAdd : add two matrixes -# NasMatSub : sub two matrixes -# NasMatMul : multiply two matrix -# NasMatTrans: transpose a matrix -# NasMatPrt : print a matrix -var NasMatrix= -{ - NasMatGen:func(row,col) - { - var GenMat={Row:row,Col:col,Elem:[]}; - for(var i=0;i=len) - print("read eof when generating string."); + print("read eof when generating string.\n"); ptr+=1; return tok_str; } @@ -178,6 +178,6 @@ while(ptr100) - me.health=100; - return nil; - }, - mood_change:func(x) - { - me.mood+=x; - if(me.mood<0) - me.mood=0; - elsif(me.mood>100) - me.mood=100; - return nil; - }, - satiety_change:func(x) - { - me.satiety+=x; - if(me.satiety<0) - me.satiety=0; - elsif(me.satiety>100) - me.satiety=100; - return nil; - }, - thirst_change:func(x) - { - me.thirst+=x; - if(me.thirst<0) - me.thirst=0; - elsif(me.thirst>100) - me.thirst=100; - return nil; - } -}; -var screen= -{ - picture:[], - info_below_left:[], - info_below_right:[], - clear:func() - { - me.picture=[]; - me.info_below_left=[]; - me.info_below_right=[]; - return; - }, - pic_addline:func(_str) - { - append(me.picture,_str); - return; - }, - left_add:func(_str) - { - append(me.info_below_left,_str); - return; - }, - right_add:func(_str) - { - append(me.info_below_right,_str); - return; - }, - prt_screen:func() - { - foreach(var i;me.picture) - print(i); - forindex(var i;me.info_below_left) - print(me.info_below_left[i]~me.info_below_right[i]); - return; - } -}; -var first_shown_info=func() -{ - system("cls"); - var str_list=[ - "+-----------------------------------------------+", - "| |", - "| |", - "| Let me tell you a story... |", - "| A story that really happened many years ago...|", - "| Nearly no one knows and cares about it... |", - "| But some children may still suffer from... |", - "| This kind of stories... |", - "| And this kind of stories never stop hurting...|", - "| People that are still alive... |", - "| |", - "| |", - "+-----------------------------------------------+" - ]; - foreach(var i;str_list) - print(i); - return; -} -var generate_role_property=func() -{ - screen.left_add("+-----------------------+"); - var str=""; - for(var i=10;i<=100;i+=10) - { - if(i<=role_property.health) - str~="="; - else - str~=" "; - } - screen.left_add("|[health ]:"~str~" |"); - str=""; - for(var i=10;i<=100;i+=10) - { - if(i<=role_property.mood) - str~="="; - else - str~=" "; - } - screen.left_add("|[mood ]:"~str~" |"); - str=""; - for(var i=10;i<=100;i+=10) - { - if(i<=role_property.satiety) - str~="="; - else - str~=" "; - } - screen.left_add("|[satiety]:"~str~" |"); - str=""; - for(var i=10;i<=100;i+=10) - { - if(i<=role_property.thirst) - str~="="; - else - str~=" "; - } - screen.left_add("|[thirst ]:"~str~" |"); - screen.left_add("+-----------------------+"); - return; -} -var generate_choose_list=func() -{ - var str_list=[ - "-----------------------+", - "[1]| next step |", - "[2]| restart |", - "[3]| store game |", - "[4]| exit |", - "-----------------------+" - ]; - foreach(var i;str_list) - screen.right_add(i); - return; -} -var next_step=func() -{ - role_property.health_change(-1); - role_property.mood_change(-1); - role_property.satiety_change(-1); - role_property.thirst_change(-10); - var str_list=[ - "+-----------------------------------------------+", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "+-----------------------------------------------+" - ]; - foreach(var i;str_list) - screen.pic_addline(i); - return; -} -var restart=func() -{ - role_property.health=100; - role_property.mood=100; - role_property.satiety=100; - role_property.thirst=100; - var str_list=[ - "+-----------------------------------------------+", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "| |", - "+-----------------------------------------------+" - ]; - foreach(var i;str_list) - screen.pic_addline(i); - return; -} -var generate_incorrect_choice_screen=func() -{ - var str_list=[ - "+-----------------------------------------------+", - "| |", - "| |", - "| |", - "| |", - "| |", - "| make a correct choice. |", - "| |", - "| |", - "| |", - "| |", - "| |", - "+-----------------------------------------------+" - ]; - foreach(var i;str_list) - screen.pic_addline(i); -} -var generate_goodbye_screen=func() -{ - var str_list=[ - "+-----------------------------------------------+", - "| |", - "| |", - "| |", - "| |", - "| |", - "| see you next life. |", - "| |", - "| |", - "| |", - "| |", - "| |", - "+-----------------------------------------------+" - ]; - foreach(var i;str_list) - screen.pic_addline(i); -} -var store_file=func() -{ - var str=role_property.health~'\n'~role_property.mood~'\n'~role_property.satiety~'\n'~role_property.thirst~'\n'; - io.fout("game-left-in-corner.glic",str); - var str_list=[ - "+-----------------------------------------------+", - "| |", - "| |", - "| |", - "| |", - "| |", - "| data stored. |", - "| |", - "| |", - "| |", - "| |", - "| |", - "+-----------------------------------------------+" - ]; - foreach(var i;str_list) - screen.pic_addline(i); - return; -} -var get_file=func() -{ - var str=io.fin("game-left-in-corner.glic"); - print(str); - return; -} -var game_main=func() -{ - first_shown_info(); - screen.clear(); - generate_role_property(); - generate_choose_list(); - screen.prt_screen(); - while(1) - { - screen.clear(); - print("|your choice[1|2|3|4]: |"); - var choice=input(); - if((choice!='1') and (choice!='2') and (choice!='3') and (choice!='4')) - generate_incorrect_choice_screen(); - elsif(choice=='1') - next_step(); - elsif(choice=='2') - restart(); - elsif(choice=='3') - store_file(); - elsif(choice=='4') - { - system("cls"); - screen.clear(); - generate_goodbye_screen(); - generate_role_property(); - generate_choose_list(); - screen.prt_screen(); - break; - } - system("cls"); - generate_role_property(); - generate_choose_list(); - screen.prt_screen(); - if(role_property.health==0 or role_property.mood==0 or role_property.satiety==0 or role_property.thirst==0) - { - print("|you died. |"); - print("+-----------------------------------------------+"); - system("pause"); - screen.clear(); - restart(); - system("cls"); - generate_role_property(); - generate_choose_list(); - screen.prt_screen(); - } - } - return; -} -game_main(); \ No newline at end of file diff --git a/test/final2.nas b/test/multiplayer.nas similarity index 100% rename from test/final2.nas rename to test/multiplayer.nas diff --git a/test/neo4j.nas b/test/neo4j.nas index e961253..91e7faa 100644 --- a/test/neo4j.nas +++ b/test/neo4j.nas @@ -13,16 +13,16 @@ var film_node=[]; for(var i=0;i<1000;i+=1) append(film_node,node("film")); var director_node=[]; -for(var i=0;i<400;i+=1) +for(var i=0;i<200;i+=1) append(director_node,node("direct")); var actor_node=[]; -for(var i=0;i<2000;i+=1) +for(var i=0;i<400;i+=1) append(actor_node,node("actor")); var writer_node=[]; -for(var i=0;i<300;i+=1) +for(var i=0;i<100;i+=1) append(writer_node,node("writer")); var type_node=[]; -for(var i=0;i<20;i+=1) +for(var i=0;i<40;i+=1) append(type_node,node("type")); var lang_node=[]; for(var i=0;i<120;i+=1) @@ -40,14 +40,14 @@ func() var lang_size=size(lang_node); var country_size=size(country_node); - var director_link=int(1+rand()*2); - var actor_link=int(1+rand()*10); - var writer_link=int(1+rand()); - var type_link=int(1+rand()*3); - var lang_link=int(1+rand()*4); - var country_link=int(1+rand()*2); foreach(var film;film_node) { + var director_link=int(1+rand()*2); + var actor_link=int(1+rand()*20); + var writer_link=int(1+rand()*2); + var type_link=int(1+rand()*5); + var lang_link=int(1+rand()*4); + var country_link=int(1+rand()*4); for(var i=0;i10?10:list_size; - for(var i=0;i=list_size) - die("choose a correct index"); - var label_list=film_node[num(choose)].next; + var label_list=film_list[index].next; film_list=[]; count_list=[]; foreach(var label;label_list) @@ -140,7 +131,7 @@ while(1) if(film_list[i].name==film.name) { has=1; - count_list[i]+=rand(); + count_list[i]+=1; break; } if(has==0) @@ -150,6 +141,21 @@ while(1) } } sort_list(0,size(film_list)); + return; +} + +while(1) +{ + var list_size=size(film_list); + list_size=list_size>10?10:list_size; + for(var i=1;i=list_size) + die("choose a correct index"); + get_next(num(choose)); } foreach(var film;film_node) diff --git a/test/prop.nas b/test/prop.nas deleted file mode 100644 index d4536b7..0000000 --- a/test/prop.nas +++ /dev/null @@ -1,246 +0,0 @@ -import("lib.nas"); - -var property_tree= -{ - accelerations: - { - 'n-z-cg-fps_sec':0, - ned: - { - 'down-accel-fps_sec':0, - 'east-accel-fps_sec':0, - 'north-accel-fps_sec':0, - }, - nlf:0, - pilot: - { - 'x-accel-fps_sec':0, - 'y-accel-fps_sec':0, - 'z-accel-fps_sec':0, - }, - 'pilot-g':1, - 'pilot-gdamped':1 - }, - ai: - { - models: - { - carrier: - { - callsign:'', - controls:{}, - environment:{}, - id:2, - name:'Nimitz', - navaids:{}, - orientation:{}, - position:{}, - radar:{}, - sign:'CVN-68', - sim:{}, - subID:0, - submodels: - { - path:'', - serviceable:1 - }, - 'surface-positions':{}, - type:'AI', - valid:1, - velocities:{}, - waypoint:{} - }, - 'carrier[1]': - { - callsign:'', - controls:{}, - environment:{}, - id:3, - name:'Eisenhower', - navaids:{}, - orientation:{}, - position:{}, - radar:{}, - sign:'CVN-69', - sim:{}, - subID:0, - submodels: - { - path:'', - serviceable:0 - }, - 'surface-positions':{}, - type:'AI', - valid:1, - velocities:{}, - waypoint:{} - }, - count:2, - 'model-added':'/ai[0]/models[0]/carrier[1]', - 'model-removed':nil, - 'num-players':0 - }, - submodels: - { - contrails:0 - }, - }, - aircraft: - { - icao: - { - equipment:'SDFGY', - surveillance:'S', - type:'ZZZZ', - 'wake-turbulence-category':'L' - }, - performance: - { - approach: - { - 'airspeed-knots':150, - }, - climb:'\n\t\t\t\n\t\t\t', - cruise: - { - 'airspeed-knots':1000, - 'altitude-ft':4500, - }, - descent:'\n\t\t\t\n\t\t\t', - maximum:'\n\t\t\t\n\t\t\t', - minimum:'\n\t\t\t\n\t\t\t', - }, - settings: - { - fuel_persistent:0, - ground_services_persistent:0, - radio_persistent:0, - tooltips:1, - weight_persistent:0 - } - }, - autopilot: - { - internal:{}, - locks:{}, - 'route-manager':{}, - settings:{}, - 'target-tracking':{}, - }, - canvas: - { - 'by-index': - { - texture: - { - background:'rgba(0,0,0,0)', - group:{}, - name:'Tooltip', - placement:{}, - size:600, - 'size[1]':200, - status:0, - 'status-msg':'OK', - view:300, - 'view[1]':100 - }, - 'texture[1]': - { - background:'rgba(0,0,0,0)', - group:{}, - mipmapping:1, - name:'SymbolCache1024x1024', - placement:{}, - size:1024, - 'size[1]':1024, - status:0, - 'status-msg':'OK', - view:1024, - 'view[1]':1024 - }, - 'texture[2]': - { - background:'rgba(0,0,0,0)', - group:{}, - mipmapping:1, - name:'SymbolCache1024x1024', - placement:{}, - size:1024, - 'size[1]':1024, - status:0, - 'status-msg':'OK', - view:1024, - 'view[1]':1024 - }, - } - }, - command:{}, - consumables:{}, - controls:{}, - cursor:'Aircraft/ufo/Models/cursor.ac', - devices:{}, - earthview:{}, - engines:{}, - environment:{}, - ephemeris:{}, - fdm:{}, - gear:{}, - hazards:{}, - input:{}, - instrumentation:{}, - 'local-weather':{}, - logging:{}, - models:{}, - nasal:{}, - orientation:{}, - position:{}, - rendering:{}, - scenery:{}, - sim:{}, - source:'Models', - 'surface-positions':{}, - systems:{}, - velocities:{}, -}; - -var setprop=func(prop,value) -{ - if(type(prop)!="string") - die("setprop: prop is not a string"); - var path=split('/',prop); - var tmp=property_tree; - var path_size=size(path); - for(var i=0;i0? x:0;})(12); -(func{print("hello world");})(); +(func{println("hello world");})(); (((func(x){return 1.0/math.exp(x);})))(0); # flexible definition & assignment @@ -123,4 +124,29 @@ nil and 1+7*8; (number_1 or number_2) and (number_3 or number_4-number_4*1); [0,1,4,3,2][4]*2-4+1*2*2*2*2*2/8; {num:0}.num or {what_is_the_secret_of_universe:42}["what_is_the_secret_of_universe"]; -"123"~"456"-123456*2/2; \ No newline at end of file +"123"~"456"-123456*2/2; + +var hash={str:'hello',f:func{return me.str;}}; +var tmp_f=hash.f; +hash=1; +print(tmp_f()); +# undefined symbol 'me' +# this means that +# when generating local_scope for function f, +# nasal_gc will not count 'me' as one reference of this hash + +var h1={str:'hello',f:func{return me.str;}}; +var h2={str:'world',f:func{return nil;}}; +h2.f=h1.f; +print(h2.f()); +# print 'world' +# this means that 'me' in hash's functions +# only points to the hash this function belongs to + +var f1=func(){print(1);return 1;} +var f2=func(){print(2);return 0;} +f1() or f2(); +# print '1' +# this means that when using 'or' or 'and', +# if the result is clear when calculating, +# objects behind will not be calculated \ No newline at end of file diff --git a/test/scope.nas b/test/scope.nas index e38f016..aa734c4 100644 --- a/test/scope.nas +++ b/test/scope.nas @@ -1,3 +1,4 @@ +import("lib.nas"); var global_value=0; var global_hash= { @@ -5,16 +6,16 @@ var global_hash= var2:2, var3:func(){return me.var2;} }; -print(global_value); -print(global_hash.var3()); +println(global_value); +println(global_hash.var3()); var func1=func() { global_value=1; - print(global_value); + println(global_value); var closure_value=1; var temp_value=1; - print(temp_value); + println(temp_value); return func{return closure_value;}; } @@ -23,10 +24,9 @@ var func2=func() for(var temp_value=0;temp_value<100;temp_value+=1) { if(temp_value<10) - print(temp_value,"< 10"); + println(temp_value,"< 10"); elsif(10<=temp_value and temp_value<50) - print(temp_value,"< 50"); - temp_value=10; + println(temp_value,"< 50"); } return; } @@ -41,9 +41,9 @@ var func3=func() }; } -func1()(); +println(func1()()); func2(); -func3()(); +println(func3()()); if(!global_value) { diff --git a/test/final.nas b/test/smartscreen.nas similarity index 100% rename from test/final.nas rename to test/smartscreen.nas diff --git a/test/string.nas b/test/string.nas deleted file mode 100644 index 32de8b9..0000000 --- a/test/string.nas +++ /dev/null @@ -1,5 +0,0 @@ -import("lib.nas"); -var filename=""; - -filename=input(); -print(filename[0]); \ No newline at end of file