From 9ab32552854804cfc763f87baf07d704f6c7a209 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Fri, 15 Apr 2016 18:07:07 -0700 Subject: [PATCH] updated avatarUnitTests.js --- examples/tests/avatarUnitTests.js | 54 +++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/examples/tests/avatarUnitTests.js b/examples/tests/avatarUnitTests.js index 9726a4c5ee..29e3ad0588 100644 --- a/examples/tests/avatarUnitTests.js +++ b/examples/tests/avatarUnitTests.js @@ -2,17 +2,57 @@ Script.include("../libraries/jasmine/jasmine.js"); Script.include("../libraries/jasmine/hifi-boot.js"); -describe("Avatar", function() { +// Art3mis +var DEFAULT_AVATAR_URL = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/contents/e76946cc-c272-4adf-9bb6-02cde0a4b57d/8fd984ea6fe1495147a3303f87fa6e23.fst?1460131758"; - beforeEach(function() { - print("beforeEach"); +var ORIGIN = {x: 0, y: 0, z: 0}; +var ONE_HUNDRED = {x: 100, y: 100, z: 100}; +var ROT_IDENT = {x: 0, y: 0, z: 0, w: 1}; + +describe("MyAvatar", function () { + + // reload the avatar from scratch before each test. + beforeEach(function (done) { + MyAvatar.skeletonModelURL = DEFAULT_AVATAR_URL; + + // wait until we are finished loading + var id = Script.setInterval(function () { + if (MyAvatar.jointNames.length == 72) { + // assume we are finished loading. + Script.clearInterval(id); + MyAvatar.position = ORIGIN; + MyAvatar.orientation = ROT_IDENT; + // give the avatar 1/2 a second to settle on the ground in the idle pose. + Script.setTimeout(function () { + done(); + }, 500); + } + }, 500); }); - it("test one", function() { - print("test one!"); - expect(10).toEqual(11); - throw "wtf"; + // makes the assumption that there is solid ground somewhat underneath the avatar. + it("position and orientation getters", function () { + var pos = MyAvatar.position; + + expect(Math.abs(pos.x)).toBeLessThan(0.1); + expect(Math.abs(pos.y)).toBeLessThan(1.0); + expect(Math.abs(pos.z)).toBeLessThan(0.1); + + var rot = MyAvatar.orientation; + expect(Math.abs(rot.x)).toBeLessThan(0.01); + expect(Math.abs(rot.y)).toBeLessThan(0.01); + expect(Math.abs(rot.z)).toBeLessThan(0.01); + expect(Math.abs(1 - rot.w)).toBeLessThan(0.01); }); + + it("position and orientation setters", function (done) { + MyAvatar.position = ONE_HUNDRED; + Script.setTimeout(function () { + expect(Vec3.length(Vec3.subtract(MyAvatar.position, ONE_HUNDRED))).toBeLessThan(0.1); + done(); + }, 100); + }); + }); jasmine.getEnv().execute();