update test/md5compare.nas & optimize test/md5.nas

This commit is contained in:
ValKmjolnir 2022-03-31 19:31:00 +08:00
parent 41b5304712
commit 83a8632e8e
3 changed files with 33 additions and 14 deletions

View File

@ -214,7 +214,7 @@ nasal_ref builtin_setsize(nasal_ref* local,nasal_gc& gc)
return builtin_err("setsize","\"vector\" must be vector");
if(size.type!=vm_num)
return builtin_err("setsize","\"size\" is not a number");
int num=(int)size.num();
int64_t num=(int64_t)size.num();
if(num<0)
return builtin_err("setsize","\"size\" must be greater than -1");
vec.vec().elems.resize(num,nil);

View File

@ -194,13 +194,12 @@ var _md5=func(s){
# because using double to discribe number
# this may only work when string's length is under 1<<51
tmp=[];
setsize(tmp,size(res)/4);
for(var i=0;i<size(res);i+=4){
append(tmp,
res[i+3]*math.pow(2,24)+
tmp[i/4]=res[i+3]*math.pow(2,24)+
res[i+2]*math.pow(2,16)+
res[i+1]*math.pow(2,8)+
res[i]
);
res[i];
}
res=tmp;

View File

@ -14,7 +14,7 @@ var compare=func(total){
for(var i=1;i<=total;i+=1){
var s="";
for(var j=0;j<i;j+=1){
s~=ch[int(rand()*size(ch))];
s~=ch[rand()*size(ch)];
}
if(cmp(md5(s),_md5(s))){
die("error: "~str(i));
@ -39,6 +39,14 @@ var filechecksum=func(){
return substr(s,0,i);
}
var filewithoututf8=[
"./stl/file.nas ",
"./stl/lib.nas ",
"./stl/list.nas ",
"./stl/module.nas ",
"./stl/queue.nas ",
"./stl/result.nas ",
"./stl/sort.nas ",
"./stl/stack.nas ",
"./test/auto_crash.nas ",
"./test/bf.nas ",
"./test/bfcolored.nas ",
@ -72,7 +80,24 @@ var filechecksum=func(){
"./test/scalar.nas ",
"./test/trait.nas ",
"./test/turingmachine.nas",
"./test/ycombinator.nas "
"./test/ycombinator.nas ",
"LICENSE ",
"main.cpp ",
"makefile ",
#"nasal_ast.h ",
#"nasal_builtin.h ",
"nasal_codegen.h ",
"nasal_dbg.h ",
"nasal_err.h ",
"nasal_gc.h ",
"nasal_import.h ",
"nasal_lexer.h ",
"nasal_opt.h ",
"nasal_parse.h ",
"nasal_vm.h ",
"nasal.ebnf ",
"nasal.h ",
"README.md "
];
foreach(var i;filewithoututf8){
var f=io.fin(getname(i));
@ -82,13 +107,8 @@ var filechecksum=func(){
}
var randomchecksum=func(){
for(var i=0;i<8;i+=1)
compare(512);
for(var i=0;i<4;i+=1)
compare(1024);
for(var i=0;i<2;i+=1)
compare(2048);
compare(4096);
for(var i=128;i<8192;i*=2)
compare(i);
}
filechecksum();