Commit 5a23cb47 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch 'issue/13' into 'master'

Issue #13: Fix engine tests

See merge request !8
parents 2e0797f1 62e71465
Pipeline #9339 passed with stage
in 37 seconds
......@@ -94,7 +94,6 @@ describe("engine class", () => {
new View({ metrics: [met3, met4, met7], dimensions: [dim4, dim5]}),
new View({ metrics: [met6, met7], dimensions: [dim3, dim4, dim5, dim6]}),
new View({ metrics: [met8, met2, met3], dimensions: [dim1, dim2, dim7]}),
new View({ metrics: [met1, met2, met3], dimensions: [dim1, dim2]}),
new View({ metrics: [met2, met4], dimensions: [dim1, dim2]}),
new View({ metrics: [met8], dimensions: [dim8, dim9, dim10]}),
new View({ metrics: [met9], dimensions: [dim8, dim9, dim10]}),
......@@ -148,18 +147,19 @@ describe("engine class", () => {
expect(optimalView.metrics).to.be.an("array");
expect(optimalView.dimensions).to.be.an("array");
expect(optimalView.childViews).to.be.an("array");
expect(optimalView.metrics.length === 10);
expect(optimalView.dimensions.length === 10);
expect(optimalView.childViews.length === 4);
expect(optimalView.metrics).to.have.length(10);
expect(optimalView.dimensions).to.have.length(10);
expect(optimalView.childViews).to.have.length(4);
let metAux: number[] = optimalView.metrics.sort().map((met: Metric) => {
return Number(met.name.split(":")[1]);
});
let dimAux: number[] = optimalView.dimensions.sort().map((dim: Dimension) => {
return Number(dim.name.split(":")[1]);
});
for (let i: number = 1; i <= 10; ++i) {
expect(dimAux[i] === i);
expect(metAux[i] === i);
for (let i: number = 0; i < 10; ++i) {
expect(dimAux[i]).to.be.equal(i+1);
expect(metAux[i]).to.be.equal(i+1);
}
});
it("should throw an exception, query with non-existent metric", () => {
......@@ -201,11 +201,11 @@ describe("engine class", () => {
expect(optimalView.metrics).to.be.an("array");
expect(optimalView.dimensions).to.be.an("array");
expect(optimalView.childViews).to.be.an("array");
expect(optimalView.metrics.length === 3);
expect(optimalView.dimensions.length === 2);
expect(optimalView.childViews.length === 0);
expect(optimalView.metrics).to.have.length(3);
expect(optimalView.dimensions).to.have.length(2);
expect(optimalView.childViews).to.have.length(0);
expect(optimalView.id === views[0].id);
expect(optimalView.id).to.be.equal(views[0].id);
});
it("should be create a fill that cover the query, using sub dimensions", () => {
......@@ -222,12 +222,16 @@ describe("engine class", () => {
expect(optimalView.metrics).to.be.an("array");
expect(optimalView.dimensions).to.be.an("array");
expect(optimalView.childViews).to.be.an("array");
expect(optimalView.metrics.length === 0);
expect(optimalView.dimensions.length === 2);
expect(optimalView.childViews.length === 1);
expect(optimalView.metrics).to.have.length(0);
expect(optimalView.dimensions).to.have.length(2);
expect(optimalView.childViews).to.have.length(1);
expect(optimalView.childViews[0].dimensions.some((item) => item.name === subdim1.name));
expect(optimalView.childViews[0].dimensions.some((item) => item.name === subdim2.name));
expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim1.name);
});
expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim1.name);
});
});
it("should be create a fill that cover the query, using the parents of sub dimensions", () => {
......@@ -244,11 +248,16 @@ describe("engine class", () => {
expect(optimalView.metrics).to.be.an("array");
expect(optimalView.dimensions).to.be.an("array");
expect(optimalView.childViews).to.be.an("array");
expect(optimalView.metrics.length === 0);
expect(optimalView.dimensions.length === 2);
expect(optimalView.childViews.length === 1);
expect(optimalView.metrics).to.have.length(0);
expect(optimalView.dimensions).to.have.length(2);
expect(optimalView.childViews).to.have.length(1);
expect(optimalView.id === views[0].id);
expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim3.name);
});
expect(optimalView).satisfy((optView: View) => {
return optView.childViews[0].dimensions.some((item) => item.name === subdim5.name);
});
});
it("should throw an exception, sub-dimension with non-existent parent", () => {
......@@ -261,6 +270,6 @@ describe("engine class", () => {
expect(e.message).to.be.equal("Engine sub-dimention " + subdim4.name + " with no parent");
}
expect(error);
expect(error).to.be.true;
});
});
......@@ -166,8 +166,10 @@ export class Engine {
// If all the metrics and dimensions are the same and only exist one child view
// return this single child view
if (optimalViews.length === 1 &&
q.metrics.every((item) => optimalViews[0].view.metrics.indexOf(item) !== -1) &&
q.dimensions.every((item) => optimalViews[0].view.dimensions.indexOf(item) !== -1)) {
optimalViews[0].view.metrics.length === q.metrics.length &&
optimalViews[0].view.dimensions.length === q.dimensions.length &&
optimalViews[0].view.metrics.every((item) => q.metrics.indexOf(item) !== -1) &&
optimalViews[0].view.dimensions.every((item) => q.dimensions.indexOf(item) !== -1)) {
return optimalViews[0].view;
}
else {
......
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