Implementation + tests for loud? block

This commit is contained in:
Florrie 2018-04-30 19:50:13 -03:00
parent 23e72525bf
commit 8e271c70d0
3 changed files with 30 additions and 0 deletions

View file

@ -65,6 +65,7 @@ class Scratch3SensingBlocks {
sensing_current: this.current,
sensing_dayssince2000: this.daysSince2000,
sensing_loudness: this.getLoudness,
sensing_loud: this.isLoud,
sensing_askandwait: this.askAndWait,
sensing_answer: this.getAnswer
};
@ -249,6 +250,10 @@ class Scratch3SensingBlocks {
return this._cachedLoudness;
}
isLoud () {
return this.getLoudness() > 10;
}
getAttributeOf (args) {
let attrTarget;

View file

@ -964,6 +964,11 @@ const specMap = {
argMap: [
]
},
'isLoud': {
opcode: 'sensing_loud',
argMap: [
]
},
// 'senseVideoMotion': {
// opcode: 'sensing_videoon',
// argMap: [

View file

@ -123,3 +123,23 @@ test('get loudness with caching', t => {
t.end();
});
test('loud? boolean', t => {
const rt = new Runtime();
const sensing = new Sensing(rt);
// The simplest way to test this is to actually override the getLoudness
// method, which isLoud uses.
let simulatedLoudness = 0;
sensing.getLoudness = () => simulatedLoudness;
t.false(sensing.isLoud());
// Check for GREATER than 10, not equal.
simulatedLoudness = 10;
t.false(sensing.isLoud());
simulatedLoudness = 11;
t.true(sensing.isLoud());
t.end();
})