Commit 66a154d7 authored by Nicolas Biri's avatar Nicolas Biri
Browse files

Add examples as tests

parent 6e0778f3
...@@ -6,9 +6,6 @@ var MM = require('./MMABExamples'); //var A = MM.A; //for defining quick access ...@@ -6,9 +6,6 @@ var MM = require('./MMABExamples'); //var A = MM.A; //for defining quick access
//Load the model (in one file for the example) //Load the model (in one file for the example)
var M = require('./MABExamples'); var M = require('./MABExamples');
var inspect = require('eyes').inspector({
maxLength: 9000
});
// <=> to the underscore library. // <=> to the underscore library.
var _ = require('lodash'); var _ = require('lodash');
...@@ -31,13 +28,12 @@ var _ = require('lodash'); ...@@ -31,13 +28,12 @@ var _ = require('lodash');
var trule2 = { //ATL <=> rule trule2 { var trule2 = { //ATL <=> rule trule2 {
in : function(inputModel) { //ATL <=> from inputModel : MM!C in : function(inputModel) { //ATL <=> from inputModel : MM!C
console.log(inputModel.Filter(MM.C));
return inputModel.Filter(MM.C); return inputModel.Filter(MM.C);
}, },
out : function(inp) { out : function(inp) {
var d = MM.D.newInstance('transformed'); //ATL<~>d: MM!D ( var d = MM.D.newInstance(); //ATL<~>d: MM!D (
d.setNum(inp.id); // ATL <=> num <- inp.id d.num = inp.id; // ATL <=> num <- inp.id
return [d]; return [d];
} }
} }
...@@ -54,27 +50,23 @@ var transformation1 = { //ATL <=> rule transformation1 { ...@@ -54,27 +50,23 @@ var transformation1 = { //ATL <=> rule transformation1 {
out : function(inp) { //ATL <=> to (withtout any ref to output elements) out : function(inp) { //ATL <=> to (withtout any ref to output elements)
var b = MM.B.newInstance(''); // <=> o : MM!B //here we call newInstance explicitly.. should be hidden var b = MM.B.newInstance(''); // <=> o : MM!B //here we call newInstance explicitly.. should be hidden
b.setNameB(inp.name+'_transfo'); //ATL <=> nameB <= inp.name+'transfo' b.nameB = inp.name+'_transfo'; //ATL <=> nameB <= inp.name+'transfo'
this.assign(b, 'toD', inp.toC); // this should be b.toC=inp.toC this.assign(b, 'toD', inp.toC); // this should be b.toC=inp.toC
// ATL <=> targetOutput <- i.targetInput // ATL <=> b.toD <- inp.toC
return [b]; //to be hidden?.... order independent, possible mutilple outputmodel elements! return [b];
} }
} }
/* ************************* /* *************************
* Transformation Launcher * Transformation Launcher
*****************************/ *****************************/
var module = new Transformation(); //multiple input/output models? -> not implemented yet var transformation = new Transformation(); //multiple input/output models? -> not implemented yet
//Order independent //Order independent
module.addRule(trule2); transformation.addRule(trule2);
module.addRule(transformation1); transformation.addRule(transformation1);
//Apply rule by rule...
//module.apply(t);
//module.apply(trule2);
//Apply all rules in the models and resolve references, actual transformation execution //Apply all rules in the models and resolve references, actual transformation execution
module.apply(M.ma, M.mb); transformation.apply(M.ma, M.mb);
inspect(M.mb); module.exports.result = M.mb;
//(_(M.mb.Filter(MM.B)).first());
var t = require('./TransformationDeclaration');
var inspect = require('eyes').inspector({
maxLength: 9000
});
inspect(t.result);
int button = 9;
int led = 13;
void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);
}
long time = 0; long debounce = 200;
void state_on() {
digitalWrite(led, HIGH);
boolean guard = millis() - time > debounce;
if (digitalRead(button) == LOW && guard) {
time = millis(); state_off();
} else {
state_on();
}
}
void state_off() {
digitalWrite(led, LOW);
boolean guard = millis() - time > debounce;
if (digitalRead(button) == LOW && guard) {
time = millis(); state_on();
} else {
state_off();
}
}
void loop() { state_off(); }
...@@ -20,9 +20,6 @@ var Mi = require('./MFamily'); ...@@ -20,9 +20,6 @@ var Mi = require('./MFamily');
//Create the outputModel //Create the outputModel
var Mo = new Model('Out'); var Mo = new Model('Out');
var inspect = require('eyes').inspector({
maxLength: 9000
});
// <=> to the underscore library. // <=> to the underscore library.
var _ = require('lodash'); var _ = require('lodash');
...@@ -45,7 +42,6 @@ function familyName(member) { ...@@ -45,7 +42,6 @@ function familyName(member) {
keys.push(key); keys.push(key);
} }
}); });
//console.log(keys);
_.each(keys, function(id,el){ _.each(keys, function(id,el){
if(member[id].length==0) { if(member[id].length==0) {
// do nothing // do nothing
...@@ -105,7 +101,6 @@ var Member2FeMale = { ...@@ -105,7 +101,6 @@ var Member2FeMale = {
out : function(inp) { out : function(inp) {
var d = MMO.Female.newInstance(''); var d = MMO.Female.newInstance('');
console.log(familyName(inp));
familyName(inp); familyName(inp);
d.setFullName(inp.firstName+' '+familyName(inp)); d.setFullName(inp.firstName+' '+familyName(inp));
return [d]; return [d];
...@@ -113,13 +108,12 @@ var Member2FeMale = { ...@@ -113,13 +108,12 @@ var Member2FeMale = {
} }
// *********************** // ***********************
var module = new Transformation(); //multiple var transformation = new Transformation(); //multiple
module.addRule(Member2Male); transformation.addRule(Member2Male);
module.addRule(Member2FeMale); transformation.addRule(Member2FeMale);
//inspect(Mi.ma.Filter(MMI.Member));
//Apply all rules in the models and resolve references, actual transformation execution //Apply all rules in the models and resolve references, actual transformation execution
module.apply(Mi.ma, Mo); transformation.apply(Mi.ma, Mo);
inspect(Mo); module.exports.result = Mo;
var t = require('./FamiliesToPerson');
var inspect = require('eyes').inspector({
maxLength: 9000
});
inspect(t.result);
...@@ -62,7 +62,7 @@ Context.prototype.assign = function(element, relationName, populators) { ...@@ -62,7 +62,7 @@ Context.prototype.assign = function(element, relationName, populators) {
* that must be implied in this transformation. * that must be implied in this transformation.
* @param {function} out - A function that take an element of the selection and (optionally) the input model in parameters * @param {function} out - A function that take an element of the selection and (optionally) the input model in parameters
* and output an array of created elements. * and output an array of created elements.
* @param {string} [name] - The name for the rule, not used yet. * @param {string} [name] - The name of the rule, not used yet.
*/ */
function Rule(selection, out, name) { function Rule(selection, out, name) {
/** @member {function} in */ /** @member {function} in */
......
{ {
"name": "jsmf-jstl", "name": "jsmf-jstl",
"version": "0.5.0", "version": "0.6.0",
"description": "Model transformation for JSTL", "description": "Model transformation for JSTL",
"main": "index.js", "main": "index.js",
"directories": { "directories": {
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
"author": "Jean-Sebastien Sottet <jean-sebastien.sottet@list.lu> (http://www.list.lu/)", "author": "Jean-Sebastien Sottet <jean-sebastien.sottet@list.lu> (http://www.list.lu/)",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"lodash": "~3.10.1", "lodash": "~4.1.0",
"object-hash": "~0.9.2", "object-hash": "~0.9.2",
"jsmf-core": "git+ssh://git@git.list.lu:jsmf/jsmf-core.git#refactored" "jsmf-core": "git+ssh://git@git.list.lu:jsmf/jsmf-core.git#refactored"
}, },
......
'use strict';
var should = require('should');
var _ = require('lodash');
describe('Transformation rules', function() {
describe('simple transformation example', function() {
it('provides the expected result', function(done) {
var abPath = '../examples/ABExample/';
var MM = require(abPath + 'MMABExamples');
var M = require(abPath + 'MABExamples');
var t = require(abPath + 'TransformationDeclaration');
var bs = t.result.Filter(MM.B);
bs.should.have.length(1);
var ds = t.result.Filter(MM.D);
ds.should.have.length(2);
_.map(M.ma.Filter(MM.C), function(x) {return x.id;}).should.eql(_.map(ds, function(x) {return x.num;}));
done();
});
});
describe('family2Person transformation example', function() {
it('provides the expected result', function(done) {
var f2pPath = '../examples/Family2Person/';
var MMF = require(f2pPath + 'MMFamily');
var MF = require(f2pPath + 'MFamily');
var MMP = require(f2pPath + 'MMPerson');
var t = require(f2pPath + 'FamiliesToPerson');
var bs = t.result.Filter(MMP.Male);
bs.should.have.length(5);
var ds = t.result.Filter(MMP.Female);
ds.should.have.length(4);
done();
});
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment