const { calculate } = require('../public/calculateAngles'); function foundMarkers(y, robot, a=0, translate=[0,0,0]){ const alphaPi = y * Math.PI / 180; const pos20 = [0,Math.sin(alphaPi)*10,Math.cos(alphaPi)*10] m = {"markers": [ {"id": 20, "position_mm": pos20 } ]} return m } robot = { "Elements":["Base", "Arm1"], "ElementLength":{"Arm1":250, "Joint1": 89.5, "Arm2":250, "Finger1":100, "Finger2":100}, "Joints":{ "jointB":{"name":"Shoulder","type":"revolute","axis":[1,0,0],"parent":"Base","child":"Arm1","origin":[-89.5,0,0], "originSource":[null, "test", "test"]}, "jointC":{"name":"Ellbow","type":"revolute","axis":[1,0,0],"parent":"Arm1","child":"Joint1", "origin":[-89.5, -250, 0]}, "jointD":{"name":"EllbowTwist","type":"revolute","axis":[0,1,0],"parent":"Joint1","child":"Arm2", "origin":[0, -250, 0]} }, "Marker":[ {"id":20, "on":"Arm1", "relPos":[0,0,10]}, {"id":40, "on":"Arm2", "relPos":[0,200,35]}, {"id":41, "on":"Arm2", "relPos":[0,160,35]} ], "recognized":{"x":null, "y":null, "z":null} } function normalizeAngleDeg(angle) { return ((angle % 360) + 360) % 360; } describe('calculateAngles minimal test', () => { it('should run calculate() artificially created robot & testData', async () => { var result = calculate(foundMarkers(45, robot), robot); expect(result).toBeDefined(); expect(robot.recognized.y).toBeDefined(); expect(robot.recognized.y).toBeCloseTo(45,2); }) });