style-js
Version:
Comprehensive color manipulation classes.
119 lines (92 loc) • 3.61 kB
HTML
<html>
<head>
<title>Style.js - Object Creation and Conversion Tests</title>
<script type="text/javascript" src="../../Type.js/src/Type.js"></script>
<script type="text/javascript" src="../../Util.js/src/Util.js"></script>
<script type="text/javascript" src="../src/Style.js"></script>
<style type="text/css">
h2 {
margin: 0
}
pre {
font-size: 12px
}
.er {
color: #f30
}
.ok {
color: #393
}
</style>
</head>
<body>
<pre><code><script type="text/javascript">
var benchmark = +(new Date());
var functions = [];
for (var i in Color) {
if (Type.isString(Color[i]) && Color[i] !== 'Named' && Color[i] !== 'red' && Color[i] !== 'green' && Color[i] !== 'blue') {
functions.push(Color[i]);
}
}
var len = functions.length;
var color, func, tmp;
var countPass = 0, countFail = 0;
var out = '';
if (len > 0) {
for (var y = 0; y < len; ++y) {
out += '<h2>Random ' + functions[y] + ' color</h2>';
if (this[functions[y]] !== undefined && Type.isFunction(this[functions[y]]['random'])) {
++countPass;
color = this[functions[y]]['random']();
if (color && color.isSet()) {
++countPass;
for (var i = 0; i < len; ++i) {
if (this[functions[i]] !== undefined) {
var obj = new this[functions[i]](color);
if (obj.isSet()) {
++countPass;
out += '<span class="ok" style="font-weight: bold; font-size: 14px">' + functions[i] + ' creation success</span>\n';
for (var x = 0; x < len; ++x) {
if (functions[x] !== functions[i]) {
func = 'to' + functions[x];
if (Type.isFunction(obj[func])) {
tmp = obj[func]();
if (tmp !== undefined && functions[x] === Type.getType(tmp) && tmp.isSet()) {
++countPass;
out += '-> <span class="ok">PASS: ' + functions[i] + '.' + func + '()</span>\n';
} else {
++countFail;
out += '-> <span class="er">FAIL: ' + functions[i] + '.' + func + '()</span>\n';
}
} else {
++countFail;
out += '-> <span class="er">FAIL: ' + functions[i] + '.' + func + '()</span>\n';
}
}
}
out += '\n';
} else {
countFail += len;
out += '<span class="er" style="font-weight: bold; font-size: 14px">' + functions[i] + ' creation failure</span>\n';
}
} else {
countFail += len;
out += '<span class="er" style="font-weight: bold; font-size: 14px">' + functions[i] + ' creation failure</span>\n';
}
}
} else {
++countFail;
out += '<span class="er">FAIL: ' + functions[i] + '.random() didn\'t return a valid color</span>\n';
}
} else {
++countFail;
out += '<span class="er">FAIL: ' + functions[i] + '.random() doesn\'t exist</span>\n';
}
}
}
var total = countPass + countFail;
benchmark = ((+(new Date()) - benchmark) / 1000).round(3);
document.write('<h1 ' + (countFail > 0 ? 'class="er">Failed' : 'class="ok">Passed') + ' Object Creation and Conversion Tests</h1><span class="ok" style="font-weight: bold">PASSED: ' + countPass + ' (' + ((countPass / total) * 100).round(2) + '%)</span>\n<span class="er" style="font-weight: bold">FAILED: ' + countFail + ' (' + ((countFail / total) * 100).round(2) + '%)</span>\n<strong>TIME: ' + benchmark + 's</strong>\n\n' + out.slice(0, -2));
</script></code></pre>
</body>
</html>