mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-13 14:00:52 -04:00
Merge 31ac5ef6f7
into f207757ef0
This commit is contained in:
commit
65f286d055
3 changed files with 51 additions and 0 deletions
|
@ -21,6 +21,7 @@ class Scratch3OperatorsBlocks {
|
|||
operator_multiply: this.multiply,
|
||||
operator_divide: this.divide,
|
||||
operator_lt: this.lt,
|
||||
operator_exponent: this.exponent,
|
||||
operator_equals: this.equals,
|
||||
operator_gt: this.gt,
|
||||
operator_and: this.and,
|
||||
|
@ -52,6 +53,10 @@ class Scratch3OperatorsBlocks {
|
|||
divide (args) {
|
||||
return Cast.toNumber(args.NUM1) / Cast.toNumber(args.NUM2);
|
||||
}
|
||||
exponent (args) {
|
||||
return Cast.toNumber(args.NUM1) ** Cast.toNumber(args.NUM2);
|
||||
}
|
||||
|
||||
|
||||
lt (args) {
|
||||
return Cast.compare(args.OPERAND1, args.OPERAND2) < 0;
|
||||
|
|
|
@ -32,6 +32,12 @@ test('divide', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('exponent', t => {
|
||||
t.strictEqual(blocks.exponent({NUM1: '2', NUM2: '3'}), 8);
|
||||
t.strictEqual(blocks.exponent({NUM1: 'foo', NUM2: 'bar'}), 1);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('lt', t => {
|
||||
t.strictEqual(blocks.lt({OPERAND1: '1', OPERAND2: '2'}), true);
|
||||
t.strictEqual(blocks.lt({OPERAND1: '2', OPERAND2: '1'}), false);
|
||||
|
|
|
@ -11,6 +11,46 @@ test('divide: (1) / (0) = Infinity', t => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('exponent: exponentiation with Infinity', t => {
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 'Infinity', NUM2: 111}), Infinity, '"Infinity" ^ 111 = Infinity'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 'INFINITY', NUM2: 222}), 0, '"INFINITY" ^ 222 = 0'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: Infinity, NUM2: 333}), Infinity, 'Infinity ^ 333 = Infinity'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 111, NUM2: 'Infinity'}), Infinity, '111 ^ "Infinity" = Infinity'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 222, NUM2: 'INFINITY'}), 1, '222 ^ "INFINITY" = 1'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 333, NUM2: Infinity}), Infinity, '333 ^ Infinity = Infinity'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: '-Infinity', NUM2: 111}), -Infinity, '"-Infinity" ^ 111 = -Infinity'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: '-INFINITY', NUM2: 222}), 0, '"-INFINITY" ^ 222 = 0'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: -Infinity, NUM2: 333}), -Infinity, '-Infinity ^ 333 = -Infinity'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 111, NUM2: '-Infinity'}), 0, '111 ^ "-Infinity" = 0'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 222, NUM2: '-INFINITY'}), 1, '222 ^ "-INFINITY" = 1'
|
||||
);
|
||||
t.strictEqual(
|
||||
blocks.exponent({NUM1: 333, NUM2: -Infinity}), 0, '333 ^ -Infinity = 0'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('divide: division with Infinity', t => {
|
||||
t.strictEqual(
|
||||
blocks.divide({NUM1: 'Infinity', NUM2: 111}), Infinity, '"Infinity" / 111 = Infinity'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue