Every software library should have a testsuite attached and iPath is not different. Being written in Javascript a few options are available for a Test framework, and I have chosen Jasmin.
A test suite consists of a tests which will compare the outcome of a function on a certain input against a reference value. When your testsuite is in place and covers enough of your code, you can refactor and extend your code with far more confidence than without a proper testsuite.
A very simple javascript function which doubles a numeric value, can look like:
function double (v) {
return 2*v;
}
A very simple jasmin test could look like: it ("tests the double function",function () {
var b = 5;
expect(double(b)).toEqual(2*b);
});
the iPath functionality is in general a bit more complex than the function above. And involves testing of svg and dxf output. An example for testing a piece of code to convert a bezier to a chain of polylines is displayed below: it ("tests a bezier in dxf",function () {
var b = new Bezier2Poly(0.5),pb = new PathBuilder(3);
var array = [{x:20, y:0}, {x:0,y:20}, {x:20, y:20}];
expect(JSON.stringify(b.convert(array), signy))
.toEqual('[{"x":5.781,"y":0.859},{"x":2.969,"y":2.266},{"x":1.094,"y":3.203},{"x":0.156,"y":3.672},{"x":0.156,"y":3.672},{"x":1.094,"y":3.203},{"x":2.969,"y":2.266},{"x":5.781,"y":0.859}]');
});
Normally a test executed during a build cycle but, but for iPath this is done by accessing a test page which is publicly accessible here
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.