Merge "Unit tests for PostfixExpr utility class"

This commit is contained in:
Jenkins 2016-12-30 10:13:40 +00:00 committed by Gerrit Code Review
commit d55f5ff45f
2 changed files with 116 additions and 0 deletions

View File

@ -63,6 +63,7 @@
validUuidPattern) {
var service = {
DriverProperty: DriverProperty,
PostfixExpr: PostfixExpr,
Graph: Graph
};

View File

@ -109,5 +109,120 @@
expect(property._getDefaultValue()).toEqual('5');
});
});
describe('PostfixExpr', function() {
it('Base construction', function() {
var expr = new service.PostfixExpr();
var ret = expr.evaluate({});
expect(ret[0]).toBe(service.PostfixExpr.status.MALFORMED);
expect(ret[1]).toBe(service.PostfixExpr.UNDEFINED);
});
function evalBinary(val1, val2, op) {
var propertySet = {};
var prop1 = new service.DriverProperty("prop1", "", propertySet);
propertySet.prop1 = prop1;
var prop2 = new service.DriverProperty("prop2", "", propertySet);
propertySet.prop2 = prop2;
var expr = new service.PostfixExpr();
expr.addProperty("prop1");
expr.addProperty("prop2");
prop1.inputValue = val1;
prop2.inputValue = val2;
expr.addOperator(op);
return expr.evaluate(propertySet);
}
it('T and T', function() {
var ret = evalBinary(true, true, service.PostfixExpr.op.AND);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('T and F', function() {
var ret = evalBinary(true, false, service.PostfixExpr.op.AND);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('F and T', function() {
var ret = evalBinary(false, true, service.PostfixExpr.op.AND);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('F and F', function() {
var ret = evalBinary(false, false, service.PostfixExpr.op.AND);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('T or T', function() {
var ret = evalBinary(true, true, service.PostfixExpr.op.OR);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('T or F', function() {
var ret = evalBinary(true, false, service.PostfixExpr.op.OR);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('F or T', function() {
var ret = evalBinary(false, true, service.PostfixExpr.op.OR);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('F or F', function() {
var ret = evalBinary(false, false, service.PostfixExpr.op.OR);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('T eq T', function() {
var ret = evalBinary(true, true, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('T eq F', function() {
var ret = evalBinary(true, false, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('F eq T', function() {
var ret = evalBinary(false, true, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('F eq F', function() {
var ret = evalBinary(false, false, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('1 eq 1', function() {
var ret = evalBinary(1, 1, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(true);
});
it('1 eq 0', function() {
var ret = evalBinary(1, 0, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
it('"1" eq 1', function() {
var ret = evalBinary('1', 1, service.PostfixExpr.op.EQ);
expect(ret[0]).toBe(service.PostfixExpr.status.OK);
expect(ret[1]).toBe(false);
});
});
});
})();