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

Write a test for the class "InputManager"

parent f7a0414a
......@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1}
m_IndirectSpecularColor: {r: 0.37311992, g: 0.38074034, b: 0.35872713, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
......@@ -1346,6 +1346,7 @@ GameObject:
- component: {fileID: 750753106}
- component: {fileID: 750753107}
- component: {fileID: 750753108}
- component: {fileID: 750753109}
m_Layer: 5
m_Name: InGameManagers
m_TagString: Untagged
......@@ -1427,6 +1428,17 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 397b5aecede4d754abd2fba781e08f97, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &750753109
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 750753102}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ef433fec09662034988a41dd58bf8b48, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &765048384
GameObject:
m_ObjectHideFlags: 0
......
using UnityEngine;
public class ButtonStatus : MonoBehaviour
{
InputManager Manager;
// Use this for initialization
void Start ()
{
Manager = transform.GetComponent<InputManager>();
}
// Update is called once per frame
void Update ()
{
Manager.IsButtonDown = Input.GetKey(KeyCode.Space) ||
Input.GetKey(KeyCode.Joystick1Button0);
}
}
fileFormatVersion: 2
guid: 80c0267e119acbf45a7e4a2f7da153c0
timeCreated: 1517759155
guid: ef433fec09662034988a41dd58bf8b48
timeCreated: 1517984561
licenseType: Free
MonoImporter:
externalObjects: {}
......
......@@ -5,13 +5,17 @@ using UnityEngine;
public class InputManager : MonoBehaviour
{
private bool IsButtonDownPrev { get; set; }
private bool IsButtonDown { get; set; }
private bool IsButtonDownPrev
{ get; set; }
public bool IsButtonDown
{ private get; set; }
private MotionState PrevMotionState { get; set; }
public MotionState CurrentMotionState { private get; set; }
private MotionState PrevMotionState
{ get; set; }
public MotionState CurrentMotionState
{ private get; set; }
public InputStatus ShortButtonStat
public InputStatus ShortButtonStat
{
get
{
......@@ -22,7 +26,7 @@ public class InputManager : MonoBehaviour
}
}
public InputStatus LongButtonStat
public InputStatus LongButtonStat
{
get
{
......@@ -39,7 +43,7 @@ public class InputManager : MonoBehaviour
}
}
public InputStatus ShortMotionStat
public InputStatus ShortMotionStat
{
get
{
......@@ -64,7 +68,7 @@ public class InputManager : MonoBehaviour
}
}
public InputStatus LongMotionStat
public InputStatus LongMotionStat
{
get
{
......@@ -94,8 +98,6 @@ public class InputManager : MonoBehaviour
{
IsButtonDownPrev = IsButtonDown;
PrevMotionState = CurrentMotionState;
IsButtonDown = ButtonStatusGetter.IsButtonDown;
}
public InputStatus MotionToInput(string name, string type)
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.TestTools;
using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
using StatusConvert;
using NUnit.Framework;
using System.Collections;
// keyboard event => next frame => ButtonStat
using MotionAnalysis;
class InputManagerTests
{
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator EmptyTest()
public IEnumerator ShortButtonStat_Should_None_State_When_Release_After_Release()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.IsButtonDown = false;
yield return null;
input.IsButtonDown = false;
var expected = InputStatus.None;
var actual = input.ShortButtonStat;
Assert.AreEqual(expected, actual, "ShortButtonStat should be none state when button was released after released");
}
[UnityTest]
public IEnumerator ShortButtonStat_Should_Entered_State_When_Press_After_Release()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.IsButtonDown = false;
yield return null;
input.IsButtonDown = true;
var expected = InputStatus.Entered;
var actual = input.ShortButtonStat;
Assert.AreEqual(expected, actual, "ShortButtonStat should be entered state when button was pressed after released");
}
[UnityTest]
public IEnumerator LongButtonStat_Should_None_State_When_Release_After_Release()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.IsButtonDown = false;
yield return null;
input.IsButtonDown = false;
var expected = InputStatus.None;
var actual = input.LongButtonStat;
Assert.AreEqual(expected, actual, "LongButtonStat should be none state when button was released after released");
}
[UnityTest]
public IEnumerator LongButtonStat_Should_Entered_State_When_Press_After_Release()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.IsButtonDown = false;
yield return null;
input.IsButtonDown = true;
var expected = InputStatus.Entered;
var actual = input.LongButtonStat;
Assert.AreEqual(expected, actual, "LongButtonStat should be entered state when button was pressed after released");
}
[UnityTest]
public IEnumerator LongButtonStat_Should_Stoped_State_When_Release_After_Press()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.IsButtonDown = true;
yield return null;
input.IsButtonDown = false;
var expected = InputStatus.Stopped;
var actual = input.LongButtonStat;
Assert.AreEqual(expected, actual, "LongButtonStat should be stoped state when button was released after pressed");
}
[UnityTest]
public IEnumerator LongButtonStat_Should_Continuing_State_When_Press_After_Press()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.IsButtonDown = true;
yield return null;
input.IsButtonDown = true;
var expected = InputStatus.Continuing;
var actual = input.LongButtonStat;
Assert.AreEqual(expected, actual, "LongButtonStat should be continuing state when button was pressed after pressed");
}
[UnityTest]
public IEnumerator ShortMotionStat_Should_None_State_When_None_After_None()
{
// Use the Assert class to test conditions.
// yield to skip a frame
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
var expected = InputStatus.None;
var actual = input.ShortMotionStat;
Assert.AreEqual(expected, actual, "ShortMotionStat should be none state when motion was none after none by clap");
}
[UnityTest]
public IEnumerator ShortMotionStat_Should_Entered_State_When_Done_After_Prepared_By_Clap()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.CLAP_PREPARE;
yield return null;
input.CurrentMotionState = MotionState.CLAP_DONE;
var expected = InputStatus.Entered;
var actual = input.ShortMotionStat;
Assert.AreEqual(expected, actual, "ShortMotionStat should be entered state when motion was done after prepared by clap");
}
[UnityTest]
public IEnumerator ShortButtonStat_Equal_None_When_After_One_Keyboard_Event()
public IEnumerator LongMotionStat_Should_None_State_When_None_After_None_By_Jesus()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
var expected = InputStatus.None;
var actual = input.LongMotionStat;
Assert.AreEqual(expected, actual, "LongMotionStat should be none state when motion was none after none by jesus");
}
[UnityTest]
public IEnumerator LongMotionStat_Should_Entered_State_When_Prepared_After_None_By_Jesus()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
yield return null;
input.CurrentMotionState = MotionState.JESUS;
var expected = InputStatus.Entered;
var actual = input.LongMotionStat;
Assert.AreEqual(expected, actual, "LongMotionStat should be entered state when motion was prepared after none by jesus");
}
[UnityTest]
public IEnumerator LongMotionStat_Should_None_State_When_None_After_Done_By_Jesus()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.JESUS;
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
var expected = InputStatus.None;
var actual = input.LongMotionStat;
Assert.AreEqual(expected, actual, "LongMotionStat should be none state when motion was none after done by jesus");
}
[UnityTest]
public IEnumerator LongMotionStat_Should_Entered_State_When_Prepared_After_Prepared_By_Jesus()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.JESUS;
yield return null;
input.CurrentMotionState = MotionState.JESUS;
var expected = InputStatus.Entered;
var actual = input.LongMotionStat;
Assert.AreEqual(expected, actual, "LongMotionStat should be entered state when motion was prepared after prepared by jesus");
}
[UnityTest]
public IEnumerator LongMotionStat_Should_Entered_State_When_Done_After_Done_By_Jesus()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.JESUS;
yield return null;
input.CurrentMotionState = MotionState.JESUS;
var expected = InputStatus.Entered;
var actual = input.LongMotionStat;
Assert.AreEqual(expected, actual, "LongMotionStat should be entered state when motion was done after done by jesus");
}
[UnityTest]
public IEnumerator Jesus_Should_None_State_When_None_After_None()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
var expected = InputStatus.None;
var actual = input.MotionToInput("Jesus", "long");
Assert.AreEqual(expected, actual, "Jesus should be none state when motion was none after none");
}
[UnityTest]
public IEnumerator Jesus_Should_Entered_State_When_Prepared_After_None()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
yield return null;
input.CurrentMotionState = MotionState.JESUS;
var expected = InputStatus.Entered;
var actual = input.MotionToInput("Jesus", "long");
Assert.AreEqual(expected, actual, "Jesus should be entered state when motion was prepared after none");
}
[UnityTest]
public IEnumerator Jesus_Should_Stopped_State_When_None_After_Done()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.JESUS;
yield return null;
input.CurrentMotionState = MotionState.UNKNOWN;
var expected = InputStatus.Stopped;
var actual = input.MotionToInput("Jesus", "long");
Assert.AreEqual(expected, actual, "Jesus should be stopped state when motion was none after done");
}
[UnityTest]
public IEnumerator Jesus_Should_Continuing_State_When_Prepared_After_Prepared()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.JESUS;
yield return null;
input.CurrentMotionState = MotionState.JESUS;
var expected = InputStatus.Continuing;
var actual = input.MotionToInput("Jesus", "long");
Assert.AreEqual(expected, actual, "Jesus should be continuing state when motion was prepared after prepared");
}
[UnityTest]
public IEnumerator Jesus_Should_Continuing_State_When_Done_After_Done()
{
var obj = new GameObject();
var input = obj.AddComponent<InputManager>();
yield return null;
input.CurrentMotionState = MotionState.JESUS;
yield return null;
input.CurrentMotionState = MotionState.JESUS;
var expected = InputStatus.Continuing;
var actual = input.MotionToInput("Jesus", "long");
Assert.AreEqual(expected, actual, "Jesus should be continuing state when motion was done after done");
}
}
using UnityEngine;
namespace StatusConvert
{
public static class ButtonStatusGetter
{
public static bool IsButtonDown
{
get
{
return Input.GetKey(KeyCode.Space) ||
Input.GetKey(KeyCode.Joystick1Button0);
}
}
}
}
\ No newline at end of file
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