Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Added test coverage for stdlib expanding-int-array
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Jul 7, 2021
1 parent b1b713c commit 55b00db
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ACBUILDDIR = $(ARTIFACTDIR)/builtin
ARBOS = $(ARBOSDIR)/arbos.mexe

TEMPLATES = $(ARBOSDIR)/contractTemplates.mini
TESTFILES = $(BUILTINDIR)/kvstest.mexe $(STDDIR)/queuetest.mexe $(BUILTINDIR)/arraytest.mexe $(BUILTINDIR)/globaltest.mexe $(STDDIR)/priorityqtest.mexe $(STDDIR)/bytearraytest.mexe $(STDDIR)/keccaktest.mexe $(STDDIR)/biguinttest.mexe $(STDDIR)/rlptest.mexe $(STDDIR)/storageMapTest.mexe $(BUILTINDIR)/maptest.mexe $(STDDIR)/sha256test.mexe $(STDDIR)/ripemd160test.mexe minitests/codeloadtest.mexe $(STDDIR)/fixedpointtest.mexe $(STDDIR)/blstest.mexe
TESTFILES = $(BUILTINDIR)/kvstest.mexe $(STDDIR)/queuetest.mexe $(BUILTINDIR)/arraytest.mexe $(BUILTINDIR)/globaltest.mexe $(STDDIR)/priorityqtest.mexe $(STDDIR)/bytearraytest.mexe $(STDDIR)/keccaktest.mexe $(STDDIR)/biguinttest.mexe $(STDDIR)/rlptest.mexe $(STDDIR)/storageMapTest.mexe $(BUILTINDIR)/maptest.mexe $(STDDIR)/sha256test.mexe $(STDDIR)/ripemd160test.mexe minitests/codeloadtest.mexe $(STDDIR)/fixedpointtest.mexe $(STDDIR)/blstest.mexe $(STDDIR)/expandingIntArrayTest.mexe
TESTCONTRACTSPURE = $(TCBUILDDIR)/Add.sol/Add.json $(TCBUILDDIR)/Fibonacci.sol/Fibonacci.json $(TCBUILDDIR)/PaymentChannel.sol/PaymentChannel.json $(TCBUILDDIR)/Underfunded.sol/Underfunded.json $(TCBUILDDIR)/ReverterFactory.sol/ReverterFactory.json $(TCBUILDDIR)/Callback.sol/Callback.json
TESTCONTRACTS = $(ACBUILDDIR)/ArbSys.sol/ArbSys.json $(TESTCONTRACTSPURE)
UPGRADEFILES = $(UPGRADETESTDIR)/regcopy_old.mexe $(UPGRADETESTDIR)/regcopy_new.mexe $(UPGRADETESTDIR)/upgrade1_old.mexe $(UPGRADETESTDIR)/upgrade1_new.mexe $(UPGRADETESTDIR)/upgrade2_new.mexe
Expand Down Expand Up @@ -48,6 +48,9 @@ $(STDDIR)/priorityqtest.mexe: compiler $(STDDIR)/priorityqtest.mini
$(STDDIR)/storageMapTest.mexe: compiler $(STDDIR)/storageMapTest.mini
$(CARGORUN) compile $(STDDIR)/storageMapTest.mini -o $(STDDIR)/storageMapTest.mexe $(COMPILEFLAGS) -t

$(STDDIR)/expandingIntArrayTest.mexe: compiler $(STDDIR)/storageMapTest.mini
$(CARGORUN) compile $(STDDIR)/expandingIntArrayTest.mini -o $(STDDIR)/expandingIntArrayTest.mexe $(COMPILEFLAGS) -t

$(STDDIR)/bytearraytest.mexe: compiler $(STDDIR)/bytearraytest.mini
$(CARGORUN) compile $(STDDIR)/bytearraytest.mini -o $(STDDIR)/bytearraytest.mexe $(COMPILEFLAGS) -t

Expand Down
2 changes: 1 addition & 1 deletion stdlib/expandingIntArray.mini
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ func expandingIntArray_grow(arr: ExpandingIntArray) -> ExpandingIntArray {
chunk: newChunk,
contents: newContents,
};
}
}
90 changes: 90 additions & 0 deletions stdlib/expandingIntArrayTest.mini
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

use std::expandingIntArray::ExpandingIntArray;
use std::expandingIntArray::expandingIntArray_new;
use std::expandingIntArray::expandingIntArray_get;
use std::expandingIntArray::expandingIntArray_set;
use std::expandingIntArray::expandingIntArray_size;
use std::expandingIntArray::expandingIntArray_getConsecutive;
use std::expandingIntArray::expandingIntArray_opConsecutive;
use std::expandingIntArray::expandingIntArray_op;

use std::bytearray::opClosure;


impure func main() {
asm(tests(),) { log };
}

func tests() -> uint {

let a = expandingIntArray_new();

let index = 0;
while (index < 24) {
a = expandingIntArray_set(a, index, index);
index = index + 1;
}

let index = 0;
while (index < 23) {
let pair = expandingIntArray_getConsecutive(a, index);
if (pair.0 != index || pair.1 != index + 1) {
return 1;
}
index = index + 1;
}
let index = 25;
while (index < 1024) {
let pair = expandingIntArray_getConsecutive(a, index);
if (pair.0 != 0 || pair.1 != 0) {
return 1;
}
index = index + 1;
}

if (expandingIntArray_size(a) != 64) {
return 2;
}

a = expandingIntArray_set(a, 64, 64);
if (expandingIntArray_get(a, 64) != 64) {
return 2;
}
a = expandingIntArray_set(a, 728, 728);
if (expandingIntArray_size(a) != 4096) {
return 2;
}

let index = 0;
while (index < 4096) {
let before = expandingIntArray_get(a, index);
a = expandingIntArray_op(a, index, unsafecast<opClosure>(struct { f: addFunc, val: index, })).0;
let after = expandingIntArray_get(a, index);
if (before != after - index) {
return after;
}

a = expandingIntArray_opConsecutive(
a,
index,
unsafecast<opClosure>(struct { f: addFunc, val: index, }),
unsafecast<opClosure>(struct { f: addFunc, val: index, })
).0;

if (expandingIntArray_get(a, index) != after + index) {
return after;
}

index = index + 1;
}
if (expandingIntArray_size(a) != 4096 * 8) {
return expandingIntArray_size(a);
}

return 0;
}

func addFunc(argument: any, value: uint) -> (uint, any) {
let res = value + unsafecast<uint>(argument);
return (res, res,);
}

0 comments on commit 55b00db

Please sign in to comment.