|
|
@@ -0,0 +1,182 @@
|
|
|
+"use strict";
|
|
|
+
|
|
|
+let assert = require("assert"),
|
|
|
+ Generator = require("../modellang");
|
|
|
+
|
|
|
+//EXAMPLE
|
|
|
+// BEHAVIOR: foobarbaz = foo bar baz;
|
|
|
+let parsed = {
|
|
|
+ systems: {},
|
|
|
+ behaviors: {
|
|
|
+ foobarbaz: {type: "Behavior", id: "foobarbaz", refs: ["foo", "bar", "baz"],
|
|
|
+ body: [
|
|
|
+ {type: "Sequence", scope: {min: 1, max: 1},
|
|
|
+ body: [
|
|
|
+ {type: "Behavior", id: "foo", scope: {min: 1, max: 1}},
|
|
|
+ {type: "Behavior", id: "bar", scope: {min: 1, max: 1}},
|
|
|
+ {type: "Behavior", id: "baz", scope: {min: 1, max: 1}},
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ foo: {type: "Behavior", id: "foo", refs: [], body: []},
|
|
|
+ bar: {type: "Behavior", id: "bar", refs: [], body: []},
|
|
|
+ baz: {type: "Behavior", id: "baz", refs: [], body: []},
|
|
|
+ },
|
|
|
+ interactions: [],
|
|
|
+ triggers: [],
|
|
|
+ errors: [],
|
|
|
+};
|
|
|
+
|
|
|
+let g = new Generator(parsed);
|
|
|
+
|
|
|
+describe("Generator", function() {
|
|
|
+
|
|
|
+ describe("generate", function() {
|
|
|
+
|
|
|
+ function getGenerated(obj, min, max, scope) {
|
|
|
+ return [
|
|
|
+ for (evt of g.generate(obj, min, max, scope))
|
|
|
+ evt.map(s => s.replace(/_\S+$/, ""))
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ describe("Behavior (leaf/atomic)", function() {
|
|
|
+
|
|
|
+ let obj = g.behaviors.foo;
|
|
|
+
|
|
|
+ it("should return 1 trace if min=1, max=1", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 1), [
|
|
|
+ ["foo"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 2 traces if min=1, max=2", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 2), [
|
|
|
+ ["foo"],
|
|
|
+ ["foo", "foo"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 3 traces if min=1, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 3), [
|
|
|
+ ["foo"],
|
|
|
+ ["foo", "foo"],
|
|
|
+ ["foo", "foo", "foo"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 2 traces if min=2, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 2, 3), [
|
|
|
+ ["foo", "foo"],
|
|
|
+ ["foo", "foo", "foo"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 1 trace if min=3, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 3, 3), [
|
|
|
+ ["foo", "foo", "foo"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should not use scope", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 1, 1), getGenerated(obj, 1, 1, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 2, 1), getGenerated(obj, 1, 2, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 3, 1), getGenerated(obj, 1, 3, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 2, 3, 1), getGenerated(obj, 2, 3, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 3, 3, 1), getGenerated(obj, 3, 3, 10));
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ describe("Sequence", function() {
|
|
|
+
|
|
|
+ let obj = g.behaviors.foobarbaz.body[0];
|
|
|
+
|
|
|
+ it("should return 1 trace if min=1, max=1", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 1), [
|
|
|
+ ["foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 2 traces if min=1, max=2", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 2), [
|
|
|
+ ["foo", "bar", "baz"],
|
|
|
+ ["foo", "bar", "baz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 3 traces if min=1, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 3), [
|
|
|
+ ["foo", "bar", "baz"],
|
|
|
+ ["foo", "bar", "baz", "foo", "bar", "baz"],
|
|
|
+ ["foo", "bar", "baz", "foo", "bar", "baz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 2 traces if min=2, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 2, 3), [
|
|
|
+ ["foo", "bar", "baz", "foo", "bar", "baz"],
|
|
|
+ ["foo", "bar", "baz", "foo", "bar", "baz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 1 trace if min=3, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 3, 3), [
|
|
|
+ ["foo", "bar", "baz", "foo", "bar", "baz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should not use scope", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 1, 1), getGenerated(obj, 1, 1, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 2, 1), getGenerated(obj, 1, 2, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 3, 1), getGenerated(obj, 1, 3, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 2, 3, 1), getGenerated(obj, 2, 3, 10));
|
|
|
+ assert.deepEqual(getGenerated(obj, 3, 3, 1), getGenerated(obj, 3, 3, 10));
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ describe("Behavior (parent/complex)", function() {
|
|
|
+
|
|
|
+ let obj = g.behaviors.foobarbaz;
|
|
|
+
|
|
|
+ it("should return 1 trace if min=1, max=1", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 1), [
|
|
|
+ ["foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 2 traces if min=1, max=2", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 2), [
|
|
|
+ ["foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ["foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 3 traces if min=1, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 1, 3), [
|
|
|
+ ["foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ["foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ["foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 2 traces if min=2, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 2, 3), [
|
|
|
+ ["foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ["foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("should return 1 trace if min=3, max=3", function() {
|
|
|
+ assert.deepEqual(getGenerated(obj, 3, 3), [
|
|
|
+ ["foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz", "foobarbaz", "foo", "bar", "baz"],
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+});
|