testing framework

This commit is contained in:
Val Erastov 2015-02-24 01:03:14 -08:00
parent 067f0ecbc1
commit 952da3de67
4 changed files with 44 additions and 6 deletions

2
web/app/test/fixtures.js Normal file
View file

@ -0,0 +1,2 @@
TCAD.test.fixtures = {};
TCAD.test.fixtures.RoundRect = {"layers":[{"name":"_dim","data":[]},{"name":"default","data":[{"id":6,"_class":"TCAD.TWO.Segment","points":[[0,[1,266.5634479999531],[2,794.5807272294047]],[3,[4,776.6236240728185],[5,794.5807272294039]]]},{"id":13,"_class":"TCAD.TWO.Segment","points":[[7,[8,927.2879843119589],[9,643.9224734815724]],[10,[11,927.2879843120583],[12,174.51664392112346]]]},{"id":20,"_class":"TCAD.TWO.Segment","points":[[14,[15,266.5475645170609],[16,23.8639268074262]],[17,[18,776.6354356426971],[19,23.863926807460135]]]},{"id":27,"_class":"TCAD.TWO.Segment","points":[[21,[22,115.90857396213624],[23,643.9003106222236]],[24,[25,115.90857396213619],[26,174.4837595347564]]]},{"id":37,"_class":"TCAD.TWO.Arc","points":[[28,[29,927.2879843119588],[30,643.9224734815724]],[31,[32,776.6236240728185],[33,794.5807272294043]],[34,[35,776.6353054124875],[36,643.9280483299306]]]},{"id":48,"_class":"TCAD.TWO.Arc","points":[[39,[40,266.5634479999531],[41,794.5807272294056]],[42,[43,115.90857396213616],[44,643.9003106222236]],[45,[46,266.5612528616091],[47,643.9280483299286]]]},{"id":59,"_class":"TCAD.TWO.Arc","points":[[50,[51,115.90857396213627],[52,174.4837595347564]],[53,[54,266.5475645170609],[55,23.86392680742626]],[56,[57,266.56125286160903],[58,174.5166057068994]]]},{"id":70,"_class":"TCAD.TWO.Arc","points":[[61,[62,776.6354356426971],[63,23.863926807393575]],[64,[65,927.2879843118895],[66,174.51664392112346]],[67,[68,776.635305412442],[69,174.5166057068957]]]}]}],"constraints":[["coi",[0,39]],["coi",[42,21]],["coi",[24,50]],["coi",[53,14]],["coi",[17,61]],["coi",[64,10]],["coi",[28,7]],["coi",[31,3]],["Horizontal",[6]],["Horizontal",[20]],["Vertical",[13]],["Vertical",[27]],["Tangent",[48,6]],["Tangent",[37,6]],["Tangent",[37,13]],["Tangent",[70,13]],["Tangent",[70,20]],["Tangent",[59,20]],["Tangent",[59,27]],["Tangent",[48,27]],["RR",[37,48]],["RR",[48,59]],["RR",[59,70]]]}

25
web/app/test/suite.js Normal file
View file

@ -0,0 +1,25 @@
TCAD.test = {};
TCAD.test.cases = {};
TCAD.test.runSuite = function() {
for (var p in TCAD.test.cases) {
_log("... Run test " + p);
TCAD.test.cases[p].apply();
}
_log("DONE.");
};
function _log(text) {
$('#testOutput').append("<div>"+text+"</div>");
};
_loadFixture = function(name) {
THE_APP.loadSketch(TCAD.test.fixtures[name]);
};
_assertEq = function(expected, actual, msg) {
if (expected !== actual) {
_log("<b class='err'>*</b> Assertion Error. Expected [" + expected + "], but was [" + actual + "]");
if (!!msg) _log(msg);
}
};

View file

@ -0,0 +1,5 @@
TCAD.test.cases.roundRect = function() {
_loadFixture("RoundRect");
_assertEq(31, THE_APP.viewer.parametricManager.system.length);
};

View file

@ -6,15 +6,15 @@
<style>
body {
font-family: Monospace;
color: white;
overflow: hidden;
}
html, body {
background: gray;
height: 100%;
padding: 0;
margin: 0;
}
.err {color: red;}
</style>
<script src="lib/jquery-2.1.0.min.js"></script>
@ -44,10 +44,15 @@
<script src="app/workbench.js"></script>
<script src="app/ui.js"></script>
<script src="app/math/graph.js"></script>
<script src="app/test/suite.js"></script>
<script src="app/test/fixtures.js"></script>
<script src="app/test/testCases.js"></script>
<script>
function start() {
var app = new TCAD.App2D();
THE_APP = new TCAD.App2D();
TCAD.test.runSuite();
}
window.onload = function() {
setTimeout(start, 0);
@ -55,7 +60,8 @@
</script>
</head>
<body>
<canvas width="300" height="300" id="viewer"></canvas>
<div id="testResults"></div>
<canvas width="300" height="300" style="height: 301px;" id="viewer"></canvas>
<h3>TEST RESULTS</h3>
<div id="testOutput"></div>
</body>
</html>