Created
May 25, 2019 18:33
-
-
Save alexanderbazo/85d4c2ffd188a92d2aa48593681f9ee2 to your computer and use it in GitHub Desktop.
Beispiel für Test-Skript zur Simon-Says-Aufgabe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env browser */ | |
/* eslint-disable no-console */ | |
import Config from "../utils/config.js"; | |
import Pattern from "../game/Pattern.js"; | |
import Level from "../game/Level.js"; | |
import Game from "../game/Game.js"; | |
import View from "../ui/View.js"; | |
function run() { | |
console.log("#### Running tests on Simon Says Application ####"); | |
printConfig(); | |
testPattern(); | |
testGame(); | |
testView(); | |
} | |
function printConfig() { | |
// Print current game configuration | |
console.log(""); | |
console.log("#### Configuration ####"); | |
for (let attr in Config) { | |
if (Config.hasOwnProperty(attr)) { | |
console.log(`[${attr}] = ${Config[attr]}`); | |
} | |
} | |
} | |
function testPattern() { | |
console.log(""); | |
console.log("#### Pattern ####"); | |
console.log("Testing pattern construction with valid colors"); | |
let colors = ["red", "green", "yellow", "blue"]; | |
try { | |
let pattern = new Pattern(colors); | |
console.info("[PASSED]"); | |
} catch (error) { | |
console.error(`[FAILED] Failed with "${error}"-Error`); | |
} | |
console.log("Testing pattern construction with invalid colors"); | |
colors = ["red", "black", "yellow", "blue"]; | |
try { | |
let pattern = new Pattern(colors); | |
console.error("[FAILED]"); | |
} catch (error) { | |
console.info( | |
`[PASSED] and "${error}"-Error thrown for invalid color pattern`); | |
} | |
} | |
function testGame() { | |
console.log(""); | |
console.log("#### Game ####"); | |
console.log("Testing level creation (first level)"); | |
let level = Game.getNextLevel(); | |
if (level.id === 1) { | |
console.info("[PASSED]"); | |
} else { | |
console.error("[FAILED]"); | |
} | |
console.log("Testing level creation (second level)"); | |
level = Game.getNextLevel(); | |
if (level.id === 2) { | |
console.info("[PASSED]"); | |
} else { | |
console.error("[FAILED]"); | |
} | |
console.log("Testing level creation (exceeding level cap)"); | |
level = new Level(Number.MAX_SAFE_INTEGER, null); | |
if (level.id === Config.MAX_LEVEL_NUMBER) { | |
console.info("[PASSED]"); | |
} else { | |
console.error("[FAILED]"); | |
} | |
} | |
function testView() { | |
console.log(""); | |
console.log("#### View ####"); | |
let el = document.createElement("div"), | |
viewEl = new View(); | |
document.body.append(el); | |
viewEl.setElement(el); | |
console.log("Testing visibility toggling: hide)"); | |
viewEl.hide(); | |
// offsetParent returns null if element or parent has display property set to none | |
if (el.offsetParent === null) { | |
console.info("[PASSED]"); | |
} else { | |
console.error("[FAILED]"); | |
} | |
console.log("Testing visibility toggling: show)"); | |
viewEl.show(); | |
if (el.offsetParent !== null) { | |
console.info("[PASSED]"); | |
} else { | |
console.error("[FAILED]"); | |
} | |
} | |
export default { | |
run: run, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-env browser */ | |
import Tests from "./test/ApplicationTest.js"; | |
function init() { | |
Tests.run(); | |
} | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment