This commit is contained in:
roblox888i 2025-05-04 02:06:39 +00:00 committed by GitHub
commit 65f286d055
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 0 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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'