Skip to content

Commit

Permalink
add some tests for min/max on ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Sep 5, 2023
1 parent 23e5fe5 commit c60c569
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/jme-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -13787,6 +13787,8 @@ newBuiltin('mod', [TNum,TNum], TNum, math.mod );
newBuiltin('max', [TNum,TNum], TNum, math.max );
newBuiltin('min', [TNum,TNum], TNum, math.min );
newBuiltin('clamp',[TNum,TNum,TNum], TNum, function(x,min,max) { return math.max(math.min(x,max),min); });
newBuiltin('max', [TRange], TNum, function(range) { return range[1]; });
newBuiltin('min', [TRange], TNum, function(range) { return range[0]; });
newBuiltin('max', [sig.listof(sig.type('number'))], TNum, math.listmax, {unwrapValues: true});
newBuiltin('min', [sig.listof(sig.type('number'))], TNum, math.listmin, {unwrapValues: true});
/**
Expand Down
4 changes: 4 additions & 0 deletions tests/jme/jme-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,10 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal

deepCloseEqual(assert, evaluate('dpformat(list(0.2..4#0.2)[6],20)').value, '1.40000000000000000', 'don\'t accumulate rounding error with non-integer step size');

closeEqual(assert, evaluate('min(1..1000)').value,1,'min(1..1000)');
closeEqual(assert, evaluate('max(1..1000)').value,1000,'max(1..1000)');
closeEqual(assert, evaluate('min(-10^6 .. 10^7)').value,-Math.pow(10,6),'min(-10^6 .. 10^6)');
closeEqual(assert, evaluate('max(-10^6 .. 10^7)').value,Math.pow(10,7),'max(-10^6 .. 10^6)');
});


Expand Down
2 changes: 2 additions & 0 deletions tests/numbas-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -13776,6 +13776,8 @@ newBuiltin('mod', [TNum,TNum], TNum, math.mod );
newBuiltin('max', [TNum,TNum], TNum, math.max );
newBuiltin('min', [TNum,TNum], TNum, math.min );
newBuiltin('clamp',[TNum,TNum,TNum], TNum, function(x,min,max) { return math.max(math.min(x,max),min); });
newBuiltin('max', [TRange], TNum, function(range) { return range[1]; });
newBuiltin('min', [TRange], TNum, function(range) { return range[0]; });
newBuiltin('max', [sig.listof(sig.type('number'))], TNum, math.listmax, {unwrapValues: true});
newBuiltin('min', [sig.listof(sig.type('number'))], TNum, math.listmin, {unwrapValues: true});
/**
Expand Down

0 comments on commit c60c569

Please sign in to comment.