Browse Source

Add tests implementing simple formulas to test composing binary expressions.

dev
Joyce Chen 12 years ago
committed by Di Wu
parent
commit
45a9a7ed61
  1. 8
      test/dialects/support.js
  2. 30
      test/dialects/value-expression-tests.js

8
test/dialects/support.js

@ -84,5 +84,13 @@ module.exports = {
name: 'customer', name: 'customer',
columns: ['id', 'name', 'age', 'income'] columns: ['id', 'name', 'age', 'income']
}); });
},
// This table contains column names that correspond to popularly used variables in formulas.
defineVariableTable: function() {
return Table.define({
name: 'variable',
columns: ['a', 'b', 'c', 'd', 't', 'u', 'v', 'x', 'y', 'z']
});
} }
}; };

30
test/dialects/value-expression-tests.js

@ -2,7 +2,9 @@
var Harness = require('./support'); var Harness = require('./support');
var customer = Harness.defineCustomerTable(); var customer = Harness.defineCustomerTable();
var v = Harness.defineVariableTable();
// Test composition of binary methods +, *, -, =.
Harness.test({ Harness.test({
query : customer.select(customer.name, customer.income.modulo(100)).where(customer.age.add(5).multiply(customer.age.subtract(2)).equals(10)), query : customer.select(customer.name, customer.income.modulo(100)).where(customer.age.add(5).multiply(customer.age.subtract(2)).equals(10)),
pg : 'SELECT "customer"."name", ("customer"."income" % $1) FROM "customer" WHERE ((("customer"."age" + $2) * ("customer"."age" - $3)) = $4)', pg : 'SELECT "customer"."name", ("customer"."income" % $1) FROM "customer" WHERE ((("customer"."age" + $2) * ("customer"."age" - $3)) = $4)',
@ -10,3 +12,31 @@ Harness.test({
mysql : 'SELECT `customer`.`name`, (`customer`.`income` % ?) FROM `customer` WHERE (((`customer`.`age` + ?) * (`customer`.`age` - ?)) = ?)', mysql : 'SELECT `customer`.`name`, (`customer`.`income` % ?) FROM `customer` WHERE (((`customer`.`age` + ?) * (`customer`.`age` - ?)) = ?)',
params: [100, 5, 2, 10] params: [100, 5, 2, 10]
}); });
// Test composition of binary (e.g. +) and unary (e.g. like) methods.
Harness.test({
query : customer.select(customer.name).where(customer.name.like(customer.id.add('hello'))),
pg : 'SELECT "customer"."name" FROM "customer" WHERE ("customer"."name" LIKE ("customer"."id" + $1))',
sqlite: 'SELECT "customer"."name" FROM "customer" WHERE ("customer"."name" LIKE ("customer"."id" + $1))',
mysql : 'SELECT `customer`.`name` FROM `customer` WHERE (`customer`.`name` LIKE (`customer`.`id` + ?))',
params: ['hello']
});
// Test implementing simple formulas.
// Acceleration formula. (a * t^2 / 2) + (v * t) = d
Harness.test({
query : v.select(v.a.multiply(v.a).divide(2).add(v.v.multiply(v.t)).equals(v.d)),
pg : 'SELECT (((("variable"."a" * "variable"."a") / $1) + ("variable"."v" * "variable"."t")) = "variable"."d") FROM "variable"',
sqlite: 'SELECT (((("variable"."a" * "variable"."a") / $1) + ("variable"."v" * "variable"."t")) = "variable"."d") FROM "variable"',
mysql : 'SELECT ((((`variable`.`a` * `variable`.`a`) / ?) + (`variable`.`v` * `variable`.`t`)) = `variable`.`d`) FROM `variable`',
params: [2]
});
// Pythagorean theorem. a^2 + b^2 = c^2.
Harness.test({
query : v.select(v.a.multiply(v.a).add(v.b.multiply(v.b)).equals(v.c.multiply(v.c))),
pg : 'SELECT ((("variable"."a" * "variable"."a") + ("variable"."b" * "variable"."b")) = ("variable"."c" * "variable"."c")) FROM "variable"',
sqlite: 'SELECT ((("variable"."a" * "variable"."a") + ("variable"."b" * "variable"."b")) = ("variable"."c" * "variable"."c")) FROM "variable"',
mysql : 'SELECT (((`variable`.`a` * `variable`.`a`) + (`variable`.`b` * `variable`.`b`)) = (`variable`.`c` * `variable`.`c`)) FROM `variable`',
params: []
});

Loading…
Cancel
Save