Skip to content

Commit

Permalink
Playing with results a bit more. Added some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarie committed May 8, 2012
1 parent 6b72da3 commit 31fa801
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/typecalc.js
Expand Up @@ -19,8 +19,8 @@ var TYPECALC = {
team = TYPECALC.io.walkTheTeam();
weaks = TYPECALC.calc.weaknesses(team);
count = TYPECALC.calc.reduceWeaknesses(weaks);
TYPECALC.io.showResultsOnUi("Resists: " + count.resistCount.toString() + "<br />", true);
TYPECALC.io.showResultsOnUi("Weaknesses: " + count.weaknessCount.toString(), false);

TYPECALC.io.showResultsOnUi(TYPECALC.calc.print_table(count), true);
});
},
debug: function () {
Expand Down Expand Up @@ -204,6 +204,27 @@ TYPECALC.calc = (function () {
return count;
};

// Methods to count how many weaknesses/resists you have for each type
var print_table = function (count) {
var output = "";

// Weaknesses list
output += "<ul><h2>Your team has some weaknesses...</h2>";
count.weaknessCount.forEach(function(entry, index) {
output += "<li>" + TYPES[index] + ": " + entry + "</li>";
});
output += "</ul>";

// Resists list
output += "<ul><h2>And some resists...</h2>";
count.resistCount.forEach(function(entry, index) {
output += "<li>" + TYPES[index] + ": " + entry + "</li>";
});
output += "</ul>";

return output;
};

// Assumes that the input is an object of arrays
var transpose = function (matrix) {
if (typeof matrix !== "object") {
Expand Down Expand Up @@ -269,6 +290,7 @@ TYPECALC.calc = (function () {
weaknesses: weaknesses,
mapEffectivity: mapEffectivity,
reduceWeaknesses: reduceWeaknesses,
print_table: print_table,
transpose: transpose,
dotProduct: dotProduct
};
Expand Down
9 changes: 9 additions & 0 deletions tests/typecalc-test.js
Expand Up @@ -13,6 +13,10 @@ TestCase("CalcTest", {
assertObject(this.calc);
},

"test constant TYPES should be hidden": function () {
assertUndefined(this.calc.TYPES);
},

"test constant TYPE_ORDER should be hidden": function() {
assertUndefined(this.calc.TYPE_ORDER);
},
Expand All @@ -23,9 +27,14 @@ TestCase("CalcTest", {

"test matchup should return array": function () {
assertNotUndefined(this.calc.matchup("normal").length);
assertArray(this.calc.matchup("normal"));

assertNotUndefined(this.calc.matchup("normal", "fire").length);
assertArray(this.calc.matchup("normal", "fire"));
},

// weakness, mapEffectivity and reduceWeaknesses

"test transpose should return false if input isn't object": function () {
assertFalse(this.calc.transpose([]));
},
Expand Down

0 comments on commit 31fa801

Please sign in to comment.