Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
ButtonPusher
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Button Pusher
ButtonPusher
Commits
db1b263f
Commit
db1b263f
authored
Feb 08, 2018
by
16이상민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write a test for the class "InputManager"
parent
f7a0414a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
396 additions
and
43 deletions
+396
-43
InGame.unity
Assets/Scene/InGame.unity
+13
-1
ButtonStatus.cs
Assets/Script/ButtonStatus.cs
+19
-0
ButtonStatus.cs.meta
Assets/Script/ButtonStatus.cs.meta
+2
-2
InputManager.cs
Assets/Script/InputManager.cs
+12
-10
InputManagerTests.cs
Assets/Script/Tests/InputManagerTests.cs
+350
-14
ButtonStatusGetter.cs
Assets/StatusConvert/ButtonStatusGetter.cs
+0
-16
No files found.
Assets/Scene/InGame.unity
View file @
db1b263f
...
...
@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity
:
1
m_CustomReflection
:
{
fileID
:
0
}
m_Sun
:
{
fileID
:
0
}
m_IndirectSpecularColor
:
{
r
:
0.373119
53
,
g
:
0.38074014
,
b
:
0.3587274
,
a
:
1
}
m_IndirectSpecularColor
:
{
r
:
0.373119
92
,
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
...
...
Assets/Script/ButtonStatus.cs
0 → 100644
View file @
db1b263f
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
);
}
}
Assets/S
tatusConvert/ButtonStatusGetter
.cs.meta
→
Assets/S
cript/ButtonStatus
.cs.meta
View file @
db1b263f
fileFormatVersion: 2
guid:
80c0267e119acbf45a7e4a2f7da153c0
timeCreated: 1517
759155
guid:
ef433fec09662034988a41dd58bf8b48
timeCreated: 1517
984561
licenseType: Free
MonoImporter:
externalObjects: {}
...
...
Assets/Script/InputManager.cs
View file @
db1b263f
...
...
@@ -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
)
...
...
Assets/Script/Tests/InputManagerTests.cs
View file @
db1b263f
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"
);
}
}
Assets/StatusConvert/ButtonStatusGetter.cs
deleted
100644 → 0
View file @
f7a0414a
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment