mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2025-05-13 06:11:18 -04:00
Clean up tests
This commit is contained in:
parent
bc9c3e0ab3
commit
b164232b3f
5 changed files with 115 additions and 130 deletions
21
lib/sb2.js
21
lib/sb2.js
|
@ -1,3 +1,5 @@
|
|||
const utility = require('./utility');
|
||||
|
||||
/**
|
||||
* Returns an array of items matching the specified attribute.
|
||||
* @param {object} project Project object (SB2 format)
|
||||
|
@ -81,23 +83,6 @@ const sprites = function (input) {
|
|||
return {count: result};
|
||||
};
|
||||
|
||||
/**
|
||||
* Tallys term frequency from an array of strings.
|
||||
* @param {array} input Array of strings
|
||||
* @return {object} Frequency information
|
||||
*/
|
||||
const frequency = function (input) {
|
||||
const result = Object.create(null);
|
||||
|
||||
for (let i in input) {
|
||||
var term = input[i];
|
||||
if (typeof result[term] === 'undefined') result[term] = 0;
|
||||
result[term]++;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extracts all blocks and generates a frequency count.
|
||||
* @param {object} project Project object (SB2 format)
|
||||
|
@ -136,7 +121,7 @@ const blocks = function (project) {
|
|||
walk(flatten(project, 'scripts'));
|
||||
|
||||
// Generate frequency count
|
||||
const freq = frequency(result);
|
||||
const freq = utility.frequency(result);
|
||||
|
||||
// Build result and return
|
||||
return {
|
||||
|
|
14
lib/sb3.js
14
lib/sb3.js
|
@ -9,7 +9,7 @@ const scripts = function (targets) {
|
|||
for (let b in targets[t].blocks) {
|
||||
if (targets[t].blocks[b].topLevel) occurances++;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
count: occurances
|
||||
|
@ -27,7 +27,7 @@ const variables = function (targets, attribute) {
|
|||
occurances++;
|
||||
idList.push(variable[0]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
count: occurances,
|
||||
|
@ -49,7 +49,7 @@ const extract = function (targets, attribute, id, hash) {
|
|||
if (typeof id !== 'undefined') idList.push(asset[id]);
|
||||
if (typeof hash !== 'undefined') hashList.push(asset[hash]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const result = {count: occurances};
|
||||
if (typeof id !== 'undefined') result.id = idList;
|
||||
|
@ -61,7 +61,7 @@ const sprites = function (targets) {
|
|||
return {
|
||||
count: targets.length - 1
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const blocks = function (targets) {
|
||||
// Storage object
|
||||
|
@ -86,10 +86,10 @@ const blocks = function (targets) {
|
|||
};
|
||||
};
|
||||
|
||||
const extensions = function (extensions) {
|
||||
const extensions = function (list) {
|
||||
return {
|
||||
count: extensions.length,
|
||||
id: extensions
|
||||
count: list.length,
|
||||
id: list
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class Utility {
|
|||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Utility;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue