add test files

This commit is contained in:
Valk Richard Li 2021-03-03 01:09:57 +08:00
parent a421470715
commit 19b590f3bb
4 changed files with 40 additions and 7 deletions

View File

@ -128,6 +128,7 @@ var curve5=func()
return; return;
} }
trans_ttf("just for test"); trans_ttf("just for test");
trans_ttf("ValKmjolnir");
curve1(); curve1();
curve2(); curve2();
curve3(); curve3();

View File

@ -20,7 +20,7 @@ var prt=func()
s~=map[i][j]; s~=map[i][j];
s~='\n'; s~='\n';
} }
print(s); print(s,'\n');
} }
var bfs=func(begin,end) var bfs=func(begin,end)
@ -50,7 +50,7 @@ var bfs=func(begin,end)
} }
prt(); prt();
} }
print("cannot reach."); print("cannot reach.\n");
return; return;
} }

View File

@ -127,7 +127,7 @@ var backward=func(x)
var cnt=0; var cnt=0;
var show=0; var show=0;
var error=1e8; var error=1e8;
while(error>0.01) while(error>0.0005)
{ {
error=0; error=0;
for(var i=0;i<4;i+=1) for(var i=0;i<4;i+=1)
@ -138,13 +138,13 @@ while(error>0.01)
} }
cnt+=1; cnt+=1;
show+=1; show+=1;
if(show==100) if(show==200)
{ {
show=0; show=0;
print('epoch ',cnt,':',error); print('epoch ',cnt,':',error,'\r');
} }
} }
print('\afinished.'); print('finished after ',cnt,' epoch.\n');
var vec=[ var vec=[
[0,0], [0,0],
[0,1], [0,1],
@ -154,5 +154,5 @@ var vec=[
foreach(var v;vec) foreach(var v;vec)
{ {
run(v); run(v);
print(v,': ',output[0].out); print(v,': ',output[0].out,'\n');
} }

32
test/leetcode1319.nas Normal file
View File

@ -0,0 +1,32 @@
import("lib.nas");
# 并查集
var n=4;
var input=[[0,1],[0,2],[1,2]];
var find_root=func(x,parent)
{
while(parent[x]!=nil)
x=parent[x];
return x;
}
var union_root=func(x,y,parent)
{
var x_root=find_root(x,parent);
var y_root=find_root(y,parent);
if(x_root==y_root) return 0;
else parent[x_root]=y_root;
return 1;
}
var makeConnect=func(n,connections)
{
if(size(connections)<n-1) return -1;
var cnt=n-1;
var parent=[];
setsize(parent,n);
for(var i=0;i<size(connections);i+=1)
if(union_root(connections[i][0],connections[i][1],parent))
cnt-=1;
return cnt;
}
print(makeConnect(n,input));