示例#1
0
    [Fact] public void Load_Once()
    {
        Data_Generator dg      = new Data_Generator();
        Hand_Generator hg      = new Hand_Generator(dg);
        var            dat_hnd = hg.newHand(hg.newFingerList());
        var            dat_fps = dg.newFloat(100);

        var exp_hnd = dat_hnd;
        var exp_pos = hg.newJoints();

        var mock_jh = new Mock <IJointsHelper>();

        mock_jh.Setup(m => m.handToJoints(dat_hnd)).Returns(exp_pos);

        var org_N_SAMPLES = GBL.N_SAMPLES;

        GBL.N_SAMPLES = dg.newInt(100);
        var q = new Queues(mock_jh.Object);

        q.LoadSample(dat_hnd, dat_fps);
        var act_hnd = q.GetSamples();
        var act_pos = q.GetPositions();
        var act_vel = q.GetVelocities();

        GBL.N_SAMPLES = org_N_SAMPLES;

        mock_jh.Verify(m => m.handToJoints(dat_hnd), Times.Once());
        mock_jh.Verify(m => m.sub(It.IsAny <Joints>(), It.IsAny <Joints>()), Times.Never());
        mock_jh.Verify(m => m.div(It.IsAny <Joints>(), It.IsAny <float>()), Times.Never());
        test.handEqual(exp_hnd, act_hnd[0]);
        test.jointsEqual(exp_pos, act_pos[0]);
        Assert.Single <Hand>(act_hnd);
        Assert.Single <Joints>(act_pos);
        Assert.Single <Joints>(act_vel);
    }
示例#2
0
    [Fact] public void Div_Float()
    {
        Data_Generator dg     = new Data_Generator();
        Hand_Generator hg     = new Hand_Generator(dg);
        var            dat_j1 = hg.newJoints();
        var            dat_f  = dg.newFloat(100);

        var exp_j = hg.newJoints();

        var mock_vh = new Mock <IVectorHelper>();

        mock_vh.Setup(m => m.divList(dat_j1.pinky, dat_f)).Returns(exp_j.pinky);
        mock_vh.Setup(m => m.divList(dat_j1.ring, dat_f)).Returns(exp_j.ring);
        mock_vh.Setup(m => m.divList(dat_j1.middle, dat_f)).Returns(exp_j.middle);
        mock_vh.Setup(m => m.divList(dat_j1.index, dat_f)).Returns(exp_j.index);
        mock_vh.Setup(m => m.divList(dat_j1.thumb, dat_f)).Returns(exp_j.thumb);
        mock_vh.Setup(m => m.div(dat_j1.palm, dat_f)).Returns(exp_j.palm);

        JointsHelper jh    = new JointsHelper(mock_vh.Object);
        var          act_j = jh.div(dat_j1, dat_f);

        mock_vh.Verify(m => m.divList(dat_j1.pinky, dat_f), Times.Once());
        mock_vh.Verify(m => m.divList(dat_j1.ring, dat_f), Times.Once());
        mock_vh.Verify(m => m.divList(dat_j1.middle, dat_f), Times.Once());
        mock_vh.Verify(m => m.divList(dat_j1.index, dat_f), Times.Once());
        mock_vh.Verify(m => m.divList(dat_j1.thumb, dat_f), Times.Once());
        mock_vh.Verify(m => m.div(dat_j1.palm, dat_f), Times.Once());

        test.jointsEqual(exp_j, act_j);
    }
示例#3
0
    [Fact] public void greaterEqual()
    {
        Data_Generator dg = new Data_Generator();
        Hand_Generator hg = new Hand_Generator(dg);

        var dat_j1  = hg.newJoints();
        var dat_f   = dg.newFloat(100);
        var exp_j   = hg.newJoints();
        var mock_vh = new Mock <IVectorHelper>();

        Assert.True(false);
    }
示例#4
0
    [Fact] public void Load_Multiple()
    {
        Data_Generator dg       = new Data_Generator();
        Hand_Generator hg       = new Hand_Generator(dg);
        var            dat_hnd1 = hg.newHand(hg.newFingerList());
        var            dat_fps1 = dg.newFloat(100);
        var            dat_hnd2 = hg.newHand(hg.newFingerList());
        var            dat_fps2 = dg.newFloat(100);

        var exp_hnd1 = dat_hnd1;
        var exp_pos1 = hg.newJoints();
        var exp_hnd2 = dat_hnd2;
        var exp_pos2 = hg.newJoints();

        var mock_jh = new Mock <IJointsHelper>();

        mock_jh.Setup(m => m.handToJoints(dat_hnd1)).Returns(exp_pos1);
        mock_jh.Setup(m => m.handToJoints(dat_hnd2)).Returns(exp_pos2);

        var org_N_SAMPLES = GBL.N_SAMPLES;

        GBL.N_SAMPLES = dg.newInt(100);
        var q = new Queues(mock_jh.Object);

        q.LoadSample(dat_hnd1, dat_fps1);
        q.LoadSample(dat_hnd2, dat_fps2);
        var act_hnds = q.GetSamples();
        var act_poss = q.GetPositions();
        var act_vels = q.GetVelocities();

        GBL.N_SAMPLES = org_N_SAMPLES;

        mock_jh.Verify(m => m.handToJoints(dat_hnd1), Times.Once());
        mock_jh.Verify(m => m.handToJoints(dat_hnd2), Times.Once());
        test.handEqual(exp_hnd1, act_hnds[0]);
        test.handEqual(exp_hnd2, act_hnds[1]);
        test.jointsEqual(exp_pos1, act_poss[0]);
        test.jointsEqual(exp_pos2, act_poss[1]);
    }
示例#5
0
    [Fact] public void AquireTarget()
    {
        Data_Generator dg               = new Data_Generator();
        Hand_Generator hg               = new Hand_Generator(dg);
        Joints         inp_joint        = hg.newJoints();
        float          org_UH_INTENSITY = GBL.UH_INTENSITY;
        float          org_UH_FREQUENCY = GBL.UH_FREQUENCY;

        float exp_UH_INTENSITY = dg.newFloat(100);
        float exp_UH_FREQUENCY = dg.newFloat(200);
        AmplitudeModulationControlPoint exp = new AmplitudeModulationControlPoint(
            inp_joint.palm.x,
            inp_joint.palm.z * -1,
            inp_joint.palm.y,
            exp_UH_INTENSITY,
            exp_UH_FREQUENCY
            );
        Haptic h   = new Haptic(new JointsHelper(new VectorHelper()), new AmplitudeModulationEmitter());
        var    act = h.AquireTarget(inp_joint);

        Assert.Equal(exp.getPosition().x, act.getPosition().x);
        Assert.Equal(exp.getPosition().y, act.getPosition().y);
        Assert.Equal(exp.getPosition().z, act.getPosition().z);
    }
示例#6
0
    [Fact] public void MinMax()
    {
        Data_Generator dg = new Data_Generator();
        Hand_Generator hg = new Hand_Generator(dg);

        (Joints min, Joints max, Joints j)dat;
        dat.j   = hg.newJoints();
        dat.min = new Joints(dg.newMinVectors(5), dg.newMinVectors(5), dg.newMinVectors(5), dg.newMinVectors(5),
                             dg.newMinVectors(5), dg.newMinVector(), dg.newFloat(100));
        dat.max = new Joints(dg.newZeroVectors(5), dg.newZeroVectors(5), dg.newZeroVectors(5), dg.newZeroVectors(5),
                             dg.newZeroVectors(5), dg.newZeroVector(), dg.newFloat(100));

        (Joints min, Joints max)exp;
        exp.min = dat.min;
        exp.max = dat.j;

        var vH = new VectorHelper();
        var jH = new JointsHelper(vH);

        var act = jH.minMax(dat.min, dat.max, dat.j);

        test.jointsEqual(exp.min, act.min);
        test.jointsEqual(exp.max, act.max);
    }
    [Fact] public void Div()
    {
        Data_Generator dg = new Data_Generator();
        Vector         v1 = dg.newVector();
        float          v2 = dg.newFloat(100);

        Vector exp = new Vector {
            x = v1.x / v2,
            y = v1.y / v2,
            z = v1.z / v2
        };

        VectorHelper v   = new VectorHelper();
        Vector       act = v.div(v1, v2);

        test.vectorEqual(exp, act);
    }
    [Fact] public void Pow()
    {
        Data_Generator dg = new Data_Generator();
        Vector         v1 = dg.newVector();
        float          f  = dg.newFloat(100);

        Vector exp = new Vector {
            x = (float)Math.Pow(v1.x, f),
            y = (float)Math.Pow(v1.y, f),
            z = (float)Math.Pow(v1.z, f)
        };

        VectorHelper v   = new VectorHelper();
        Vector       act = v.pow(v1, f);

        test.vectorEqual(act, exp);
    }
    [Fact] public void PowList()
    {
        Data_Generator dg     = new Data_Generator();
        int            length = dg.newInt(100);
        float          f      = dg.newFloat(100);

        Vector[] v1  = dg.newVectors(length);
        Vector[] exp = dg.newZeroVectors(length);
        for (int i = 0; i < length; i++)
        {
            exp[i].x = (float)Math.Pow(v1[i].x, f);
            exp[i].y = (float)Math.Pow(v1[i].y, f);
            exp[i].z = (float)Math.Pow(v1[i].z, f);
        }
        VectorHelper v = new VectorHelper();

        Vector[] act = v.powList(v1, f);
        test.vectorsEqual(act, exp);
    }
    [Fact] public void DivList()
    {
        Data_Generator dg     = new Data_Generator();
        int            length = dg.newInt(100);

        Vector[] v1 = dg.newVectors(length);
        float    v2 = dg.newFloat(100);

        Vector[] exp = dg.newZeroVectors(length);

        for (int i = 0; i < length; i++)
        {
            exp[i].x = v1[i].x / v2;
            exp[i].y = v1[i].y / v2;
            exp[i].z = v1[i].z / v2;
        }
        VectorHelper v = new VectorHelper();

        Vector[] act = v.divList(v1, v2);
        test.vectorsEqual(exp, act);
    }
示例#11
0
    [Fact] public void Clear()
    {
        Data_Generator dg      = new Data_Generator();
        Hand_Generator hg      = new Hand_Generator(dg);
        var            dat_hnd = hg.newHand(hg.newFingerList());
        var            dat_fps = dg.newFloat(100);

        var exp_hnd = dat_hnd;
        var exp_pos = hg.newJoints();

        var mock_jh = new Mock <IJointsHelper>();

        mock_jh.Setup(m => m.handToJoints(dat_hnd)).Returns(exp_pos);

        var org_N_SAMPLES = GBL.N_SAMPLES;

        GBL.N_SAMPLES = dg.newInt(100);
        var q = new Queues(mock_jh.Object);

        q.LoadSample(dat_hnd, dat_fps);
        q.Clear();
        var act_hnd = q.GetSamples();
        var act_pos = q.GetPositions();
        var act_vel = q.GetVelocities();

        GBL.N_SAMPLES = org_N_SAMPLES;

        (List <Hand> samples, List <Joints> positions, List <Joints> velocities)exp;
        exp.samples    = null;
        exp.positions  = null;
        exp.velocities = null;

        test.Equals(act_hnd, exp.samples);
        test.Equals(act_pos, exp.positions);
        test.Equals(act_vel, exp.velocities);
    }
示例#12
0
 public Bone newBone(Vector joint1, Vector joint2) => new Bone
 {
     PrevJoint = joint1,
     NextJoint = joint2,
     Center    = dg.newVector(),
     Direction = dg.newVector(),
     Length    = dg.newFloat(100),
     Width     = dg.newFloat(100),
     Type      = new Bone.BoneType()
 };