add more missing tests

master
adeveria 2013-09-24 13:16:55 -07:00
parent 25b4a2cfb2
commit a553d07b28
3 changed files with 42 additions and 1 deletions

View File

@ -53,7 +53,7 @@ describe("Path methods", function () {
alpha: 180
});
});
it("Savage.path.bezierBBox", function () {
it("Savage.path.bezierBBox - params", function () {
var bbox = Savage.path.bezierBBox(10, 10, 10, 20, 110, 0, 110, 10);
expect(bbox.cx).to.be(60);
expect(bbox.cy).to.be(10);
@ -62,6 +62,25 @@ describe("Path methods", function () {
expect(bbox.width).to.be(100);
expect(bbox.x2).to.be(110);
});
it("Savage.path.bezierBBox - array", function () {
var bbox = Savage.path.bezierBBox([10, 10, 10, 20, 110, 0, 110, 10]);
expect(bbox.cx).to.be(60);
expect(bbox.cy).to.be(10);
expect(bbox.x).to.be(10);
expect(bbox.w).to.be(100);
expect(bbox.width).to.be(100);
expect(bbox.x2).to.be(110);
});
it("Savage.path.getBBox", function() {
// same as 10,20,30,40 rect
var bbox = Savage.path.getBBox("M10,20h30v40h-30z");
expect(bbox.x).to.eql(10);
expect(bbox.y).to.eql(20);
expect(bbox.width).to.eql(30);
expect(bbox.height).to.eql(40);
expect(bbox.x2).to.eql(10 + 30);
expect(bbox.y2).to.eql(20 + 40);
});
it("Savage.path.isPointInsideBBox", function () {
expect(Savage.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 5, 5)).to.be(true);
expect(Savage.path.isPointInsideBBox({x: 0, y: 0, width: 10, height: 10}, 10, 5)).to.be(true);

View File

@ -94,6 +94,14 @@ describe("Primitives creation", function () {
expect(C).to.not.be(null);
expect(C.childNodes.length).to.be(2);
});
it("creates and fills a group on creation", function () {
var circle1 = s.circle(10, 10, 10);
var circle2 = s.circle(20, 10, 10);
var group = s.g(circle1, circle2);
var groupEl = document.querySelector("g");
expect(groupEl).to.not.be(null);
expect(groupEl.childNodes.length).to.be(2);
});
it("creates a text", function () {
var c = s.text(10, 10, "test");
var C = document.querySelector("text");

View File

@ -396,4 +396,18 @@ describe("Savage methods", function () {
expect(bbox.x2).to.eql(10 + 30);
expect(bbox.y2).to.eql(20 + 40);
});
it("Savage.angle - 2 points", function() {
var angle = Savage.angle(0, 0, 10, 10);
expect(angle).to.not.be(0);
expect(angle % 45).to.be(0);
angle = Savage.angle(0, 0, 10, 0);
expect(angle % 90).to.be(0);
});
it("Savage.angle - 3 points", function() {
var angle = Savage.angle(10, 0, 0, 10, 0, 0);
expect(angle).to.not.be(0);
expect(angle % 45).to.be(0);
angle = Savage.angle(10, 0, 0, 10, 0, 0);
expect(Math.abs(angle)).to.be(90);
});
});