Exemplo n.º 1
0
    [Fact] public void Average()
    {
        Data_Generator dg      = new Data_Generator();
        Hand_Generator hg      = new Hand_Generator(dg);
        int            dat_len = dg.newInt(100);
        List <Joints>  dat_jL  = hg.newJointsList(dat_len);

        Joints exp_ave = hg.newJoints();

        Mock <IJointsHelper> mock_jh = new Mock <IJointsHelper>();

        for (int i = 0; i < dat_len; i++)
        {
            mock_jh.Setup(m => m
                          .add(It.IsAny <Joints>(), dat_jL[i]))
            .Returns(exp_ave);
        }
        mock_jh.Setup(m => m
                      .div(exp_ave, dat_len))
        .Returns(exp_ave);

        Stats  s       = new Stats(mock_jh.Object);
        Joints act_ave = s.average(dat_jL);

        mock_jh.Verify(m => m.add(It.IsAny <Joints>(), It.IsAny <Joints>()), Times.Exactly(dat_len));
        mock_jh.Verify(m => m.div(exp_ave, dat_len), Times.Once());
        test.jointsEqual(exp_ave, act_ave);
    }
Exemplo n.º 2
0
    [Fact] public void Div_Int()
    {
        Data_Generator dg     = new Data_Generator();
        Hand_Generator hg     = new Hand_Generator(dg);
        var            dat_j1 = hg.newJoints();
        var            dat_f  = dg.newInt(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);
    }
Exemplo n.º 3
0
    [Fact] public void Range()
    {
        Data_Generator dg      = new Data_Generator();
        Hand_Generator hg      = new Hand_Generator(dg);
        int            dat_len = dg.newInt(100);
        List <Joints>  dat_jL  = hg.newJointsList(dat_len);

        Joints exp_range = hg.newJoints();
        Joints exp_min   = hg.newJoints();
        Joints exp_max   = hg.newJoints();

        Mock <IJointsHelper> mock_jh = new Mock <IJointsHelper>();

        foreach (var j in dat_jL)
        {
            mock_jh.Setup(m => m.minMax(It.IsAny <Joints>(), It.IsAny <Joints>(), j)).Returns((exp_min, exp_max));
        }
        mock_jh.Setup(m => m.sub(exp_max, exp_min)).Returns(exp_range);

        Stats  s         = new Stats(mock_jh.Object);
        Joints act_range = s.range(dat_jL);

        foreach (var j in dat_jL)
        {
            mock_jh.Verify(m => m.minMax(It.IsAny <Joints>(), It.IsAny <Joints>(), j), Times.Once());
        }
        mock_jh.Verify(m => m.sub(exp_max, exp_min), Times.Once());
        test.jointsEqual(exp_range, act_range);
    }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
 public Finger newFinger(Vector[] jointList) => new Finger(
     dg.newLong(100),
     dg.newInt(100),
     dg.newInt(100),
     dg.newFloat(100),
     dg.newVector(),
     dg.newVector(),
     dg.newVector(),
     dg.newVector(),
     dg.newFloat(100),
     dg.newFloat(100),
     new bool(),
     new Finger.FingerType(),
     newBone(jointList[0], jointList[1]),
     newBone(jointList[1], jointList[2]),
     newBone(jointList[2], jointList[3]),
     newBone(jointList[3], jointList[4])
     );
Exemplo n.º 6
0
    [Fact] public void greaterEqualListOneToOne()
    {
        Data_Generator dg     = new Data_Generator();
        int            length = dg.newInt(100);

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

        var exp_tupleList = new (bool exp_x, bool exp_y, bool exp_z)[length];
Exemplo n.º 7
0
    [Fact] public void Variance()
    {
        Data_Generator dg               = new Data_Generator();
        Hand_Generator hg               = new Hand_Generator(dg);
        int            dat_len          = dg.newInt(100);
        List <Joints>  dat_jL           = hg.newJointsList(dat_len);
        var            mock_vh          = new Mock <IVectorHelper>();
        Joints         exp_sum          = hg.newJoints();
        Joints         exp_avg          = hg.newJoints();
        Joints         exp              = hg.newJoints();
        Joints         exp_error        = hg.newJoints();
        Joints         exp_sq_error     = hg.newJoints();
        Joints         exp_sum_sq_error = hg.newJoints();
        Joints         exp_Variance     = hg.newJoints();

        Mock <IJointsHelper> mock_jh = new Mock <IJointsHelper>();

        foreach (var j in dat_jL)
        {
            mock_jh.Setup(m => m.add(It.IsAny <Joints>(), j)).Returns(exp_sum);
        }
        mock_jh.Setup(m => m.div(exp_sum, dat_len)).Returns(exp_avg);

        foreach (var j in dat_jL)
        {
            mock_jh.Setup(m => m.sub(j, exp_avg)).Returns(exp_error);
            mock_jh.Setup(m => m.pow(exp_error, 2)).Returns(exp_sq_error);
            mock_jh.Setup(m => m.add(It.IsAny <Joints>(), exp_sq_error)).Returns(exp_sum_sq_error);
        }
        mock_jh.Setup(m => m.div(exp_sum_sq_error, dat_len - 1)).Returns(exp_Variance);

        Stats s            = new Stats(mock_jh.Object);
        var   act_Variance = s.variance(dat_jL);

        foreach (var j in dat_jL)
        {
            mock_jh.Verify(m => m.add(It.IsAny <Joints>(), j), Times.Once());
        }
        mock_jh.Verify(m => m.div(exp_sum, dat_len), Times.Once());

        foreach (var j in dat_jL)
        {
            mock_jh.Verify(m => m.sub(j, exp_avg), Times.Once());
            mock_jh.Verify(m => m.pow(exp_error, 2), Times.Exactly(dat_len));
            mock_jh.Verify(m => m.add(It.IsAny <Joints>(), exp_sq_error), Times.Exactly(dat_len));
        }

        test.jointsEqual(exp_Variance, act_Variance);
    }
Exemplo n.º 8
0
    [Fact] public void Lowest()
    {
        Data_Generator dg  = new Data_Generator();
        int            len = dg.newInt(100);

        Vector[] input = dg.newVectors(len);
        input[0] = new Vector(-1, -1, -1);

        Vector exp = input[0];

        VectorHelper vh  = new VectorHelper();
        Vector       act = vh.lowest(input);

        test.vectorEqual(exp, act);
    }
Exemplo n.º 9
0
    [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);
    }
Exemplo n.º 10
0
    [Fact] public void AddList()
    {
        Data_Generator dg     = new Data_Generator();
        int            length = dg.newInt(100);

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

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

        Vector[] act = v.addList(v1, v2);
        test.vectorsEqual(exp, act);
    }
Exemplo n.º 11
0
    [Fact] public void MinMaxList()
    {
        var dg = new Data_Generator();
        //var dat_i = 0;
        var dat_len = dg.newInt(100);

        var dat_vA  = dg.newVectors(dat_len);
        var dat_min = dg.newMinVectors(dat_len);
        var dat_max = dg.newZeroVectors(dat_len);

        (Vector[] min, Vector[] max)exp = (new Vector[dat_len], new Vector[dat_len]);
        exp.min = dat_min;
        exp.max = dat_vA;

        var vh = new VectorHelper();

        (Vector[] min, Vector[] max)act = vh.minMaxList(dat_min, dat_max, dat_vA);

        test.vectorsEqual(exp.min, act.min);
        test.vectorsEqual(exp.max, act.max);
    }
Exemplo n.º 12
0
    [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);
    }
Exemplo n.º 13
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]);
    }
Exemplo n.º 14
0
    [Fact] public void Average()
    {
        Data_Generator dg  = new Data_Generator();
        int            len = dg.newInt(100);

        Vector[] vL = dg.newVectors(len);

        Vector exp = new Vector(0, 0, 0);

        for (int i = 0; i < len; i++)
        {
            exp.x += vL[i].x;
            exp.y += vL[i].y;
            exp.z += vL[i].z;
        }
        exp.x /= (float)len;
        exp.y /= (float)len;
        exp.z /= (float)len;

        VectorHelper vh  = new VectorHelper();
        Vector       act = vh.average(vL);

        test.vectorEqual(exp, act);
    }
Exemplo n.º 15
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);
    }