RosettaCodeData/Task/Loops-Wrong-ranges/Huginn/loops-wrong-ranges.huginn
2023-07-01 13:44:08 -04:00

35 lines
1 KiB
Text

import Algorithms as algo;
class Example {
_start = none;
_stop = none;
_step = none;
_comment = none;
}
main() {
examples = [
Example( -2, 2, 1, "Normal" ),
Example( 2, 2, 0, "Start equal stop: zero increment" ),
Example( 0, 0, 0, "Start equal stop equal zero: zero increment" ),
Example( 2, 2, 1, "Start equal stop: positive increment" ),
Example( 2, 2, -1, "Start equal stop: negative increment" ),
Example( -2, 2, 10, "First increment is beyond stop value" ),
Example( -2, 2, 0, "Zero increment, stop greater than start" ),
Example( -2, 2, -1, "Increments away from stop value" ),
Example( 2, -2, 1, "Start more than stop: positive increment" )
];
for ( ex : examples ) {
print(
"{}\nRange( {}, {}, {} ) -> ".format(
ex._comment, ex._start, ex._stop, ex._step
)
);
r = algo.range( ex._start, ex._stop, ex._step );
print(
"{}\n\n".format(
algo.materialize( algo.slice( r, 22 ), list )
)
);
}
}