Commit a07b33a7 authored by 16이상민's avatar 16이상민

Writing tests for class "MotionDiscriminator"...

parent db1b263f
using MotionAnalysis;
using NUnit.Framework;
using System.Collections.Generic;
using Windows.Kinect;
public class MotionDiscriminatorTests
{
[Test]
public void IsPreseted_False_When_Constructed()
{
var obj = new MotionDiscriminator();
var expected = false;
var actual = obj.IsPreseted;
Assert.AreEqual(expected, actual, "IsPreseted should be false when constructed");
}
[Test]
public void Motion_Unknown_When_Constructed()
{
var obj = new MotionDiscriminator();
var expected = MotionState.UNKNOWN;
var actual = obj.Motion;
Assert.AreEqual(expected, actual, "Motion should be unknown when constructed");
}
[Test]
public void IsPreset_False_When_Preset_Without_KneeJoints()
{
var obj = new MotionDiscriminator();
obj.Preset(new BodyDummy());
var expected = false;
var actual = obj.IsPreseted;
Assert.AreEqual(expected, actual, "IsPreseted should be false when preset without knee joints");
}
[Test]
public void IsPreset_True_When_Preset_With_KneeJoints()
{
var obj = new MotionDiscriminator();
obj.Preset(new KneeJointsBodyStub());
var expected = true;
var actual = obj.IsPreseted;
Assert.AreEqual(expected, actual, "IsPreseted should be true when preset with knee joints");
}
[Test]
public void Motion_Unknown_When_DistHandBaseSpineShoulder_Smaller_Than_0()
{
}
}
public class BodyDummy : BodyFake
{
public BodyDummy()
{
Joints = new Dictionary<JointType, KinectModule.IJoint>();
}
}
public class KneeJointsBodyStub : BodyFake
{
public KneeJointsBodyStub()
{
Joints = new Dictionary<JointType, KinectModule.IJoint>
{
{ JointType.KneeLeft, new JointStub() },
{ JointType.KneeRight, new JointStub() }
};
}
}
fileFormatVersion: 2
guid: 589b57a674870c843ae2e26060f61ee9
timeCreated: 1518028922
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -5,8 +5,6 @@ using System; ...@@ -5,8 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using KinectModule; using KinectModule;
// To test the update function and the updated buffer, you need a stub for the source frame class.
public class SourceBufferTests public class SourceBufferTests
{ {
[Test] [Test]
...@@ -136,29 +134,24 @@ public class SourceBufferTests ...@@ -136,29 +134,24 @@ public class SourceBufferTests
public class MultiSourceFrameStub : IMultiSourceFrame public class MultiSourceFrameStub : IMultiSourceFrame
{ {
private IColorFrame _ColorFrame; public IColorFrame LastColorFrame
private IBodyIndexFrame _BodyIndexFrame; { get; private set; }
private IDepthFrame _DepthFrame;
private IBodyFrame _BodyFrame;
public IColorFrame LastColorFrame
{ get { return _ColorFrame; } }
public IBodyIndexFrame LastBodyIndexFrame public IBodyIndexFrame LastBodyIndexFrame
{ get { return _BodyIndexFrame; } } { get; private set; }
public IDepthFrame LastDepthFrame public IDepthFrame LastDepthFrame
{ get { return _DepthFrame; } } { get; private set; }
public IBodyFrame LastBodyFrame public IBodyFrame LastBodyFrame
{ get { return _BodyFrame; } } { get; private set; }
public MultiSourceFrameStub(IColorFrame color, public MultiSourceFrameStub(IColorFrame color,
IBodyIndexFrame bodyIndex, IBodyIndexFrame bodyIndex,
IDepthFrame depth, IDepthFrame depth,
IBodyFrame body) IBodyFrame body)
{ {
_ColorFrame = color; LastColorFrame = color;
_BodyIndexFrame = bodyIndex; LastBodyIndexFrame = bodyIndex;
_DepthFrame = depth; LastDepthFrame = depth;
_BodyFrame = body; LastBodyFrame = body;
} }
} }
...@@ -236,53 +229,42 @@ public class BodyFrameDummy : IBodyFrame ...@@ -236,53 +229,42 @@ public class BodyFrameDummy : IBodyFrame
public class BodyFake : IBody public class BodyFake : IBody
{ {
private bool _IsTracked = false; public bool IsTracked
private Dictionary<JointType, IJoint> _Joints = new Dictionary<JointType, IJoint> { get; set; }
{
{ JointType.AnkleLeft, new JointStub() },
{ JointType.AnkleRight, new JointStub() },
{ JointType.ElbowLeft, new JointStub() },
{ JointType.ElbowRight, new JointStub() },
{ JointType.FootLeft, new JointStub() },
{ JointType.FootRight, new JointStub() },
{ JointType.HandLeft, new JointStub() },
{ JointType.HandRight, new JointStub() },
{ JointType.HandTipLeft, new JointStub() },
{ JointType.HandTipRight, new JointStub() },
{ JointType.Head, new JointStub() },
{ JointType.HipLeft, new JointStub() },
{ JointType.HipRight, new JointStub() },
{ JointType.KneeLeft, new JointStub() },
{ JointType.KneeRight, new JointStub() },
{ JointType.Neck, new JointStub() },
{ JointType.ShoulderLeft, new JointStub() },
{ JointType.ShoulderRight, new JointStub() },
{ JointType.SpineBase, new JointStub() },
{ JointType.SpineMid, new JointStub() },
{ JointType.SpineShoulder, new JointStub() },
{ JointType.ThumbLeft, new JointStub() },
{ JointType.ThumbRight, new JointStub() },
{ JointType.WristLeft, new JointStub() },
{ JointType.WristRight, new JointStub() }
};
public bool IsTracked
{
get
{
return _IsTracked;
}
set
{
_IsTracked = value;
}
}
public Dictionary<JointType, IJoint> Joints public Dictionary<JointType, IJoint> Joints
{ get; protected set; }
public BodyFake()
{ {
get IsTracked = false;
Joints = new Dictionary<JointType, IJoint>
{ {
return _Joints; { JointType.AnkleLeft, new JointStub() },
} { JointType.AnkleRight, new JointStub() },
{ JointType.ElbowLeft, new JointStub() },
{ JointType.ElbowRight, new JointStub() },
{ JointType.FootLeft, new JointStub() },
{ JointType.FootRight, new JointStub() },
{ JointType.HandLeft, new JointStub() },
{ JointType.HandRight, new JointStub() },
{ JointType.HandTipLeft, new JointStub() },
{ JointType.HandTipRight, new JointStub() },
{ JointType.Head, new JointStub() },
{ JointType.HipLeft, new JointStub() },
{ JointType.HipRight, new JointStub() },
{ JointType.KneeLeft, new JointStub() },
{ JointType.KneeRight, new JointStub() },
{ JointType.Neck, new JointStub() },
{ JointType.ShoulderLeft, new JointStub() },
{ JointType.ShoulderRight, new JointStub() },
{ JointType.SpineBase, new JointStub() },
{ JointType.SpineMid, new JointStub() },
{ JointType.SpineShoulder, new JointStub() },
{ JointType.ThumbLeft, new JointStub() },
{ JointType.ThumbRight, new JointStub() },
{ JointType.WristLeft, new JointStub() },
{ JointType.WristRight, new JointStub() }
};
} }
public override bool Equals(object obj) public override bool Equals(object obj)
...@@ -310,10 +292,13 @@ public class BodyFake : IBody ...@@ -310,10 +292,13 @@ public class BodyFake : IBody
public class JointStub : IJoint public class JointStub : IJoint
{ {
private CameraSpacePoint _Position = new CameraSpacePoint { X = 0, Y = 0, Z = 0 };
public CameraSpacePoint Position public CameraSpacePoint Position
{ get { return _Position; } } { get; private set; }
public JointStub()
{
Position = new CameraSpacePoint { X = 0, Y = 0, Z = 0 };
}
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
......
using UnityEngine; using System.Collections.Generic;
using UnityEngine;
using Windows.Kinect; using Windows.Kinect;
namespace MotionAnalysis namespace MotionAnalysis
...@@ -17,6 +18,23 @@ namespace MotionAnalysis ...@@ -17,6 +18,23 @@ namespace MotionAnalysis
SpineMidRecent, SpineMidRecent,
HandLeftRecent, HandLeftRecent,
HandRightRecent; HandRightRecent;
private Dictionary<string, CameraSpacePoint?> Points =
new Dictionary<string, CameraSpacePoint?>
{
{ "Head", null },
{ "HandLeft", null },
{ "HandRight", null },
{ "SpineShoulder", null },
{ "SpineMid", null },
{ "ElbowLeft", null },
{ "ElbowRight", null },
{ "KneeLeft", null },
{ "KneeRight", null },
{ "SpineMidRecent", null },
{ "HandLeftRecent", null },
{ "HandRightRecent", null }
};
private float Table; private float Table;
......
using System.Collections.Generic; using System.Linq;
using System.Linq;
using Windows.Kinect; using Windows.Kinect;
namespace MotionAnalysis namespace MotionAnalysis
...@@ -17,23 +16,21 @@ namespace MotionAnalysis ...@@ -17,23 +16,21 @@ namespace MotionAnalysis
{ {
IsPreseted = false; IsPreseted = false;
if (DoNotHaveKneeJoint(body)) if (HaveKneeJoint(body))
return; {
Extractor = new DistItvExtractor(ComputeKneeMean(body));
Extractor = new DistItvExtractor(ComputeKneeMean(body));
IsPreseted = true; IsPreseted = true;
Init(); Init();
}
} }
private bool DoNotHaveKneeJoint(KinectModule.IBody body) private bool HaveKneeJoint(KinectModule.IBody body)
{ {
KinectModule.IJoint left, return body != null &&
right; body.Joints.ContainsKey(JointType.KneeLeft) &&
body.Joints.ContainsKey(JointType.KneeRight);
return !body.Joints.TryGetValue(JointType.KneeLeft, out left) ||
!body.Joints.TryGetValue(JointType.KneeRight, out right);
} }
private float ComputeKneeMean(KinectModule.IBody body) private float ComputeKneeMean(KinectModule.IBody body)
...@@ -57,7 +54,7 @@ namespace MotionAnalysis ...@@ -57,7 +54,7 @@ namespace MotionAnalysis
Determine(); Determine();
} }
void Determine() private void Determine()
{ {
Clap(); Clap();
Jump(); Jump();
...@@ -71,7 +68,7 @@ namespace MotionAnalysis ...@@ -71,7 +68,7 @@ namespace MotionAnalysis
OnTheTable(); OnTheTable();
} }
void Clap() private void Clap()
{ {
const float distPrepare = 0.3f, const float distPrepare = 0.3f,
distDone = 0.1f; distDone = 0.1f;
...@@ -85,7 +82,7 @@ namespace MotionAnalysis ...@@ -85,7 +82,7 @@ namespace MotionAnalysis
Motion |= MotionState.CLAP_DONE; Motion |= MotionState.CLAP_DONE;
} }
void Jump() private void Jump()
{ {
const float distPrepare = 0.05f, const float distPrepare = 0.05f,
distDone = 0.0f; distDone = 0.0f;
...@@ -96,13 +93,13 @@ namespace MotionAnalysis ...@@ -96,13 +93,13 @@ namespace MotionAnalysis
Motion |= MotionState.JUMP_DONE; Motion |= MotionState.JUMP_DONE;
} }
void Hurray() private void Hurray()
{ {
if (Extractor.DistHandBaseHead > 0) if (Extractor.DistHandBaseHead > 0)
Motion |= MotionState.HURRAY; Motion |= MotionState.HURRAY;
} }
void HandMove() private void HandMove()
{ {
if (Extractor.DistHandLeft > 0) if (Extractor.DistHandLeft > 0)
Motion |= MotionState.HAND_MOVE_UP_LEFT; Motion |= MotionState.HAND_MOVE_UP_LEFT;
...@@ -115,7 +112,7 @@ namespace MotionAnalysis ...@@ -115,7 +112,7 @@ namespace MotionAnalysis
Motion |= MotionState.HAND_MOVE_DOWN_RIGHT; Motion |= MotionState.HAND_MOVE_DOWN_RIGHT;
} }
void GuardBase() private void GuardBase()
{ {
const float distBase = 0.5f; const float distBase = 0.5f;
...@@ -128,7 +125,7 @@ namespace MotionAnalysis ...@@ -128,7 +125,7 @@ namespace MotionAnalysis
Motion |= MotionState.GUARD_BASE_RIGHT; Motion |= MotionState.GUARD_BASE_RIGHT;
} }
void HandUp() private void HandUp()
{ {
const float distUp = 0.2f; const float distUp = 0.2f;
...@@ -139,7 +136,7 @@ namespace MotionAnalysis ...@@ -139,7 +136,7 @@ namespace MotionAnalysis
Motion |= MotionState.HAND_UP_RIGHT; Motion |= MotionState.HAND_UP_RIGHT;
} }
void HandDown() private void HandDown()
{ {
if (Extractor.DistHandBaseSpineMid_Left < 0.0f) if (Extractor.DistHandBaseSpineMid_Left < 0.0f)
Motion |= MotionState.HAND_DOWN_LEFT; Motion |= MotionState.HAND_DOWN_LEFT;
...@@ -148,7 +145,7 @@ namespace MotionAnalysis ...@@ -148,7 +145,7 @@ namespace MotionAnalysis
Motion |= MotionState.HAND_DOWN_RIGHT; Motion |= MotionState.HAND_DOWN_RIGHT;
} }
void Jesus() private void Jesus()
{ {
const float distJesus = 0.5f; const float distJesus = 0.5f;
...@@ -156,7 +153,7 @@ namespace MotionAnalysis ...@@ -156,7 +153,7 @@ namespace MotionAnalysis
Motion |= MotionState.JESUS; Motion |= MotionState.JESUS;
} }
void Headphone() private void Headphone()
{ {
const float itvDepth = 0.2f, const float itvDepth = 0.2f,
itvEar = 0.2f; itvEar = 0.2f;
...@@ -170,7 +167,7 @@ namespace MotionAnalysis ...@@ -170,7 +167,7 @@ namespace MotionAnalysis
Motion |= MotionState.HEADPHONE_RIGHT; Motion |= MotionState.HEADPHONE_RIGHT;
} }
void OnTheTable() private void OnTheTable()
{ {
const float distTable = 0.5f; const float distTable = 0.5f;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment