const { calculate } = require('../public/calculateAngles');



function foundMarkers(alpha, robot){
    const alphaPi = alpha * Math.PI / 180;

    m = {"markers": [{"id": 0, "position_mm":[0,Math.sin(alphaPi)*10,Math.cos(alphaPi)*10]}]}

    return m
}

robot = {
    "Elements":["Base", "Arm1"],
    "ElementLength":{"Arm1":250, "Arm2":250, "Finger1":100, "Finger2":100},
    "Joints":{
        "jointB":{"name":"Shoulder","type":"revolute","axis":[1,0,0],"parent":"Base","child":"Arm1","origin":[0,0,0], "originSource":[null, "test", "test"]},
    },
    "Marker":[
        {"id":0, "on":"Arm1", "relPos":[0,0,10]}
    ],
    "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 () => {
  
        for (let alpha = -180; alpha <= 181; alpha += 15) {

            var result =  calculate(foundMarkers(alpha, robot), robot);

            expect(result).toBeDefined();
            expect(robot.recognized.y).toBeDefined();
            expect(robot.recognized.y).toBeCloseTo(alpha,2);
        } 
  })

  it('should run calculate() artificially created robot & testData 2', async () => {
  
        for (let alpha = -30; alpha <= 761; alpha += 15) {

            var result =  calculate(foundMarkers(alpha, robot), robot);

            expect(result).toBeDefined();
            expect(robot.recognized.y).toBeDefined();
            expect(normalizeAngleDeg(robot.recognized.y)).toBeCloseTo(normalizeAngleDeg(alpha),2);
        } 
  })
});