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

Write a test for the class "MotionStatusExtractor"

parent a7e8ca71
using NUnit.Framework;
using MotionAnalysis;
using StatusConvert;
using System.Linq;
using System.Collections.Generic;
class MotionStatusExtractorTest
{
[Test]
public void Output_Should_None_State_When_InvalidName()
{
var expected = true;
var actual =
StateChecker.CheckNotContain(
"asdf",
MotionState.ALL,
MotionStatus.None);
Assert.AreEqual(expected, actual, "output should be none state when entered invalid name.");
}
[Test]
public void Output_Should_Prepared_State_When_Name_Clap_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.CheckContain("Clap",
MotionState.CLAP_PREPARE,
MotionStatus.Prepared);
Assert.AreEqual(expected, actual, "output should be prepared state when name is Clap and valid input.");
}
[Test]
public void Output_Should_Done_State_When_Name_Clap_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.Check("Clap",
MotionState.CLAP_DONE,
MotionState.CLAP_PREPARE,
MotionStatus.Done);
Assert.AreEqual(expected, actual, "output should be done state when name is Clap and valid input.");
}
[Test]
public void Output_Should_None_State_When_Name_Clap_And_Invalid_Input()
{
var expected = true;
var actual =
StateChecker.CheckNotContain("Clap",
MotionState.CLAP_PREPARE |
MotionState.CLAP_DONE,
MotionStatus.None);
Assert.AreEqual(expected, actual, "output should be none state when name is Clap and invalid input.");
}
[Test]
public void Output_Should_Prepared_State_When_Name_PushUpLeft_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.CheckContain("PushUpLeft",
MotionState.HURRAY |
MotionState.HAND_MOVE_UP_LEFT,
MotionStatus.Prepared);
Assert.AreEqual(expected, actual, "output should be prepared state when name is PushUpLeft and valid input.");
}
[Test]
public void Output_Should_Done_State_When_Name_PushUpLeft_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.Check("PushUpLeft",
MotionState.HURRAY |
MotionState.HAND_MOVE_DOWN_LEFT,
MotionState.HAND_MOVE_UP_LEFT,
MotionStatus.Done);
Assert.AreEqual(expected, actual, "output should be done state when name is PushUpLeft and valid input.");
}
[Test]
public void Output_Should_None_State_When_Name_PushUpLeft_And_Invalid_Input()
{
var expected = true;
var actual =
StateChecker.CheckNotContain("PushUpLeft",
MotionState.HURRAY,
MotionStatus.None) ||
StateChecker.CheckNotContain("PushUpLeft",
MotionState.HURRAY |
MotionState.HAND_MOVE_UP_LEFT,
MotionStatus.None) ||
StateChecker.CheckNotContain("PushUpLeft",
MotionState.HURRAY |
MotionState.HAND_MOVE_DOWN_LEFT,
MotionStatus.None) ||
StateChecker.CheckNotContain("PushUpLeft",
MotionState.HAND_MOVE_UP_LEFT |
MotionState.HAND_MOVE_DOWN_LEFT,
MotionStatus.None);
Assert.AreEqual(expected, actual, "output should be none state when name is PushUpLeft and invalid input.");
}
[Test]
public void Output_Should_Prepared_State_When_Name_JumpPushUpLeft_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.CheckContain("JumpPushUpLeft",
MotionState.HURRAY |
MotionState.JUMP_PREPARE |
MotionState.HAND_MOVE_UP_LEFT,
MotionStatus.Prepared);
Assert.AreEqual(expected, actual, "output should be prepared state when name is JumpPushUpLeft and valid input.");
}
[Test]
public void Output_Should_Done_State_When_Name_JumpPushUpLeft_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.Check("JumpPushUpLeft",
MotionState.HURRAY |
MotionState.JUMP_DONE |
MotionState.HAND_MOVE_DOWN_LEFT,
MotionState.JUMP_PREPARE |
MotionState.HAND_MOVE_UP_LEFT,
MotionStatus.Done);
Assert.AreEqual(expected, actual, "output should be done state when name is JumpPushUpLeft and valid input.");
}
[Test]
public void Output_Should_None_State_When_Name_JumpPushUpLeft_And_Invalid_Input()
{
var expected = true;
var actual =
StateChecker.CheckNotContain("JumpPushUpLeft",
MotionState.HURRAY,
MotionStatus.None) ||
StateChecker.CheckNotContain("JumpPushUpLeft",
MotionState.HURRAY |
MotionState.JUMP_PREPARE |
MotionState.HAND_MOVE_UP_LEFT,
MotionStatus.None) ||
StateChecker.CheckNotContain("JumpPushUpLeft",
MotionState.HURRAY |
MotionState.JUMP_DONE |
MotionState.HAND_MOVE_DOWN_LEFT,
MotionStatus.None) ||
StateChecker.CheckNotContain("JumpPushUpLeft",
MotionState.JUMP_PREPARE |
MotionState.JUMP_DONE |
MotionState.HAND_MOVE_UP_LEFT |
MotionState.HAND_MOVE_DOWN_LEFT,
MotionStatus.None);
Assert.AreEqual(expected, actual, "output should be none state when name is JumpPushUpLeft and invalid input.");
}
[Test]
public void Output_Should_Prepared_Done_State_When_Name_Jesus_And_Valid_Input()
{
var expected = true;
var actual =
StateChecker.CheckContain("Jesus",
MotionState.JESUS,
MotionStatus.Prepared |
MotionStatus.Done);
Assert.AreEqual(expected, actual, "output should be done state when name is Jesus and valid input.");
}
[Test]
public void Output_Should_None_State_When_Name_Jesus_And_Invalid_Input()
{
var expected = true;
var actual =
StateChecker.CheckNotContain("Jesus",
MotionState.JESUS,
MotionStatus.None);
Assert.AreEqual(expected, actual, "output should be none state when name is Jesus and invalid input.");
}
}
public static class StateChecker
{
public static bool Check(string name, MotionState contain, MotionState none, MotionStatus result)
{
return AreCorrectResults(name, result, ConditionalPossibiltiy(contain, none));
}
public static bool CheckContain(string name, MotionState contain, MotionStatus result)
{
return AreCorrectResults(name, result, AllPossibilityContainAllState(contain));
}
public static bool CheckNotContain(string name, MotionState none, MotionStatus result)
{
return AreCorrectResults(name, result, AllPossibilityNotContainAllState(none));
}
private static IEnumerable<MotionState> AllPossibility()
{
return Enumerable.Range(0, (int)MotionState.ALL + 1)
.Select(x => (MotionState)x);
}
private static IEnumerable<MotionState> AllPossibilityContainAllState(MotionState contain)
{
return AllPossibility().Where(x => (x & contain) == contain);
}
private static IEnumerable<MotionState> AllPossibilityNotContainAllState(MotionState none)
{
return AllPossibility().Where(x => (x & none) == MotionState.UNKNOWN);
}
private static IEnumerable<MotionState> ConditionalPossibiltiy(MotionState contain, MotionState none)
{
return AllPossibility().Where(x => (x & contain) == contain &&
(x & none) == MotionState.UNKNOWN);
}
private static bool AreCorrectResults(string name, MotionStatus result, IEnumerable<MotionState> possibilities)
{
return NumberCorrectResults(name, result, possibilities) == possibilities.Count();
}
private static int NumberCorrectResults(string name, MotionStatus result, IEnumerable<MotionState> possibilities)
{
return possibilities.Select(x => MotionStatusExtractor.Extract(name, x))
.Where(x => x == result)
.Count();
}
}
fileFormatVersion: 2
guid: 49ca8807c8e90e644b82eac88447687e
timeCreated: 1517880293
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -24,6 +24,7 @@ namespace MotionAnalysis
JESUS = 0x10000,
HEADPHONE_LEFT = 0x20000,
HEADPHONE_RIGHT = 0x40000,
ON_THE_TABLE = 0x80000
ON_THE_TABLE = 0x80000,
ALL = 0xFFFFF
}
}
\ No newline at end of file
......@@ -25,58 +25,58 @@ namespace StatusConvert
{
"PushUpLeft", new Dictionary<string, MotionState>
{
{ "prepare", MotionState.HURRAY &
{ "prepare", MotionState.HURRAY |
MotionState.HAND_MOVE_UP_LEFT },
{ "done", MotionState.HURRAY &
{ "done", MotionState.HURRAY |
MotionState.HAND_MOVE_DOWN_LEFT }
}
},
{
"PushUpRight", new Dictionary<string, MotionState>
{
{ "prepare", MotionState.HURRAY &
{ "prepare", MotionState.HURRAY |
MotionState.HAND_MOVE_UP_RIGHT },
{ "done", MotionState.HURRAY &
{ "done", MotionState.HURRAY |
MotionState.HAND_MOVE_DOWN_RIGHT }
}
},
{
"JumpPushUpLeft", new Dictionary<string, MotionState>
{
{ "prepare", MotionState.JUMP_PREPARE &
MotionState.HURRAY &
{ "prepare", MotionState.JUMP_PREPARE |
MotionState.HURRAY |
MotionState.HAND_MOVE_UP_LEFT },
{ "done", MotionState.JUMP_DONE &
MotionState.HURRAY &
{ "done", MotionState.JUMP_DONE |
MotionState.HURRAY |
MotionState.HAND_MOVE_DOWN_LEFT }
}
},
{
"JumpPushUpRight", new Dictionary<string, MotionState>
{
{ "prepare", MotionState.JUMP_PREPARE &
MotionState.HURRAY &
{ "prepare", MotionState.JUMP_PREPARE |
MotionState.HURRAY |
MotionState.HAND_MOVE_UP_RIGHT },
{ "done", MotionState.JUMP_DONE &
MotionState.HURRAY &
{ "done", MotionState.JUMP_DONE |
MotionState.HURRAY |
MotionState.HAND_MOVE_DOWN_RIGHT }
}
},
{
"GuardLeft", new Dictionary<string, MotionState>
{
{ "prepare", MotionState.GUARD_BASE_LEFT &
{ "prepare", MotionState.GUARD_BASE_LEFT |
MotionState.HAND_MOVE_UP_LEFT },
{ "done", MotionState.GUARD_BASE_LEFT &
{ "done", MotionState.GUARD_BASE_LEFT |
MotionState.HAND_MOVE_DOWN_LEFT }
}
},
{
"GuardRight", new Dictionary<string, MotionState>
{
{ "prepare", MotionState.GUARD_BASE_RIGHT &
{ "prepare", MotionState.GUARD_BASE_RIGHT |
MotionState.HAND_MOVE_UP_RIGHT },
{ "done", MotionState.GUARD_BASE_RIGHT &
{ "done", MotionState.GUARD_BASE_RIGHT |
MotionState.HAND_MOVE_DOWN_RIGHT }
}
}
......
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