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
25a3d60c
Commit
25a3d60c
authored
Feb 18, 2018
by
16이상민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write tests for "JudgeManager"
parent
b7d28703
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1105 additions
and
356 deletions
+1105
-356
InitTestScene636545218775398421.unity
Assets/InitTestScene636545218775398421.unity
+355
-0
InitTestScene636545218775398421.unity.meta
Assets/InitTestScene636545218775398421.unity.meta
+9
-0
InitTestScene636545523835105176.unity
Assets/InitTestScene636545523835105176.unity
+355
-0
InitTestScene636545523835105176.unity.meta
Assets/InitTestScene636545523835105176.unity.meta
+9
-0
Judge.cs
Assets/JudgeModule/Judge.cs
+16
-9
NoteJudger.cs
Assets/JudgeModule/NoteJudger.cs
+6
-9
NoteManager.cs
Assets/JudgeModule/NoteManager.cs
+1
-12
Controller.cs
Assets/Script/Controller.cs
+1
-3
InGameManager.cs
Assets/Script/InGameManager.cs
+1
-1
JudgeManager.cs
Assets/Script/JudgeManager.cs
+37
-268
Note.cs
Assets/Script/Note.cs
+1
-1
JudgeManagerTests.cs
Assets/Script/Tests/JudgeManagerTests.cs
+289
-0
JudgeManagerTests.cs.meta
Assets/Script/Tests/JudgeManagerTests.cs.meta
+13
-0
NoteJudgerTests.cs
Assets/Script/Tests/NoteJudgerTests.cs
+10
-52
NoteManagerTests.cs
Assets/Script/Tests/NoteManagerTests.cs
+2
-1
No files found.
Assets/InitTestScene636545218775398421.unity
0 → 100644
View file @
25a3d60c
This diff is collapsed.
Click to expand it.
Assets/InitTestScene636545218775398421.unity.meta
0 → 100644
View file @
25a3d60c
fileFormatVersion: 2
guid: 3e4992bf17dae8e44b8880d8867b91ea
timeCreated: 1518892677
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/InitTestScene636545523835105176.unity
0 → 100644
View file @
25a3d60c
This diff is collapsed.
Click to expand it.
Assets/InitTestScene636545523835105176.unity.meta
0 → 100644
View file @
25a3d60c
fileFormatVersion: 2
guid: b5f132dad262fcc43a19502f6a0ee9e3
timeCreated: 1518923184
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/JudgeModule/Judge.cs
View file @
25a3d60c
...
...
@@ -35,19 +35,17 @@ namespace JudgeModule
public
bool
IsBreak
{
get
;
private
set
;
}
public
Color
Color
{
get
;
private
set
;
}
public
static
readonly
Judge
BAD
=
JudgeList
[
2
];
public
static
readonly
Judge
MISS
=
JudgeList
.
Last
();
public
static
readonly
Judge
BAD
=
JudgeList
[
2
];
public
static
readonly
Judge
MISS
=
JudgeList
[
3
];
public
static
readonly
Judge
Perfect
=
JudgeList
[
0
];
public
static
readonly
float
MaxButtonTimingRange
=
BadTime
;
public
static
Judge
TestJudge
(
Note
note
,
float
elapsedTime
,
bool
end
=
false
,
bool
test
=
false
)
public
static
Judge
TestJudge
(
Note
note
,
float
elapsedTime
,
bool
end
=
false
)
{
float
timing
=
end
?
note
.
EndTiming
:
note
.
StartTiming
;
float
difference
=
elapsedTime
-
timing
;
if
(
test
)
Debug
.
Log
(
difference
);
var
result
=
JudgeList
.
Where
(
x
=>
Mathf
.
Abs
(
difference
)
<
x
.
ButtonTimingRange
).
ToList
();
return
result
.
Count
==
0
?
JudgeList
.
Last
()
:
result
[
0
];
...
...
@@ -67,9 +65,18 @@ namespace JudgeModule
public
static
bool
IsNoteEnd
(
Note
note
,
float
elapsedTime
)
{
var
timing
=
elapsedTime
-
note
.
EndTiming
;
return
timing
<=
BadTime
&&
timing
>=
0
;
var
difference
=
elapsedTime
-
note
.
EndTiming
;
return
difference
<=
BadTime
&&
difference
>=
0
;
}
public
static
bool
IsNoteProgress
(
Note
note
,
float
elapsedTime
,
float
interval
)
{
var
timing
=
note
.
StartTiming
+
(
interval
*
(
note
.
JudgeCount
+
1
));
return
Mathf
.
Abs
(
elapsedTime
-
timing
)
<
PerfectTime
&&
Mathf
.
Abs
(
elapsedTime
-
timing
)
<
Mathf
.
Abs
(
elapsedTime
-
(
timing
-
interval
));
}
}
}
\ No newline at end of file
Assets/JudgeModule/NoteJudger.cs
View file @
25a3d60c
...
...
@@ -39,16 +39,13 @@ namespace JudgeModule
DeactivateNote
(
note
);
}
public
void
ContinuingNoteProc
(
Note
note
,
float
timing
)
public
void
ContinuingNoteProc
(
Note
note
,
float
timing
,
float
interval
)
{
var
isEnd
=
Judge
.
IsNoteEnd
(
note
,
timing
);
var
judge
=
Judge
.
TestJudge
(
note
,
timing
,
isEnd
);
SetJudge
(
judge
);
if
(!
isEnd
&&
judge
.
IsBreak
)
DeactivateNote
(
note
);
if
(
Judge
.
IsNoteProgress
(
note
,
timing
,
interval
))
{
SetJudge
(
Judge
.
Perfect
);
++
note
.
JudgeCount
;
}
}
public
void
CorrectlyStoppedNoteProc
(
Note
note
,
float
timing
)
...
...
Assets/JudgeModule/NoteManager.cs
View file @
25a3d60c
...
...
@@ -7,9 +7,6 @@ namespace JudgeModule
{
public
class
NoteManager
{
private
float
baseTime
;
private
bool
IsInitTime
;
private
GameObject
offset
;
private
GameObject
noteobj
;
private
GameObject
deactives
;
...
...
@@ -49,16 +46,8 @@ namespace JudgeModule
GetLastNote
=
getlastnote
;
}
public
void
Controll
(
float
current
)
public
void
Controll
(
float
timing
)
{
if
(!
IsInitTime
)
{
baseTime
=
current
;
IsInitTime
=
true
;
}
float
timing
=
current
-
baseTime
;
offset
.
transform
.
position
=
Vector3
.
left
*
timing
*
ScrollSpeed
;
RelocateControllers
(
timing
);
...
...
Assets/Script/Controller.cs
View file @
25a3d60c
...
...
@@ -9,9 +9,7 @@ public class Controller : MonoBehaviour
private
readonly
float
minAlpha
=
0.3f
;
private
readonly
float
maxAlpha
=
0.7f
;
public
int
id
;
// Update is called once per frame
void
Update
()
{
...
...
Assets/Script/InGameManager.cs
View file @
25a3d60c
...
...
@@ -168,7 +168,7 @@ public class InGameManager : MonoBehaviour {
if
(
condition
.
IsLongNoteStartCorrectly
(
note
))
judger
.
EnteredNoteProc
(
note
,
timing
);
else
if
(
condition
.
IsLongNoteHoldCorrectly
(
note
))
judger
.
ContinuingNoteProc
(
note
,
timing
);
judger
.
ContinuingNoteProc
(
note
,
timing
,
0
);
else
if
(
condition
.
IsLongNoteFinishCorrectly
(
note
,
timing
))
judger
.
CorrectlyStoppedNoteProc
(
note
,
timing
);
else
if
(
condition
.
IsLongNoteFinishIncorrectly
(
note
,
timing
))
...
...
Assets/Script/JudgeManager.cs
View file @
25a3d60c
This diff is collapsed.
Click to expand it.
Assets/Script/Note.cs
View file @
25a3d60c
...
...
@@ -2,7 +2,7 @@
{
public
Controller
Component
=
null
;
public
int
id
;
public
int
JudgeCount
;
public
float
StartTiming
{
get
;
private
set
;
}
public
float
EndTiming
{
get
;
private
set
;
}
...
...
Assets/Script/Tests/JudgeManagerTests.cs
0 → 100644
View file @
25a3d60c
using
UnityEngine.TestTools
;
using
System.Collections
;
using
UnityEngine
;
using
JudgeModule
;
using
NUnit.Framework
;
using
System.Collections.Generic
;
using
System.Linq
;
using
TestSupport
;
using
UnityEngine.UI
;
using
MotionAnalysis
;
public
class
JudgeManagerTests
{
[
UnityTest
]
public
IEnumerator
Judge_Miss_And_Note_Deactive_When_Wrong_Input_Button
()
{
var
objects
=
MakeObjects
();
var
input
=
MakeInput
();
var
manager
=
new
JudgeManager
(
input
,
()
=>
{
},
objects
,
60
);
var
maker
=
new
TestNoteMaker
();
var
controller
=
objects
[
"appear"
].
transform
.
GetChild
(
0
)
.
GetComponent
<
Controller
>();
controller
.
transform
.
SetParent
(
objects
[
"noteobj"
].
transform
);
controller
.
Instance
=
maker
.
MakeNote
(
"SMO"
,
0
);
controller
.
Instance
.
Component
=
controller
;
yield
return
null
;
input
.
IsButtonDown
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
true
;
manager
.
JudgeNote
(
controller
.
Instance
,
0
);
var
expected
=
true
;
var
actual
=
(
objects
[
"judgetext"
].
GetComponent
<
Text
>().
text
==
Judge
.
MISS
.
Name
&&
controller
.
transform
.
parent
.
name
==
"Deactives"
);
Assert
.
AreEqual
(
expected
,
actual
,
"Judge is miss and note is deactive when wrong input with button"
);
}
[
UnityTest
]
public
IEnumerator
Judge_Miss_And_Note_Deactive_When_Wrong_Input_Motion
()
{
var
objects
=
MakeObjects
();
var
input
=
MakeInput
();
var
manager
=
new
JudgeManager
(
input
,
()
=>
{
},
objects
,
60
);
var
maker
=
new
TestNoteMaker
();
var
controller
=
objects
[
"appear"
].
transform
.
GetChild
(
0
)
.
GetComponent
<
Controller
>();
controller
.
transform
.
SetParent
(
objects
[
"noteobj"
].
transform
);
controller
.
Instance
=
maker
.
MakeNote
(
"SBT"
,
0
);
controller
.
Instance
.
Component
=
controller
;
yield
return
null
;
input
.
CurrentMotionState
=
MotionState
.
CLAP_PREPARE
;
yield
return
null
;
input
.
CurrentMotionState
=
MotionState
.
CLAP_DONE
;
manager
.
JudgeNote
(
controller
.
Instance
,
0
);
var
expected
=
true
;
var
actual
=
(
objects
[
"judgetext"
].
GetComponent
<
Text
>().
text
==
Judge
.
MISS
.
Name
&&
controller
.
transform
.
parent
.
name
==
"Deactives"
);
Assert
.
AreEqual
(
expected
,
actual
,
"Judge is miss and note is deactive when wrong input with motion"
);
}
[
UnityTest
]
public
IEnumerator
Judge_Valid_When_Short
()
{
var
objects
=
MakeObjects
();
var
input
=
MakeInput
();
var
manager
=
new
JudgeManager
(
input
,
()
=>
{
},
objects
,
60
);
var
maker
=
new
TestNoteMaker
();
var
controller
=
objects
[
"appear"
].
transform
.
GetChild
(
0
)
.
GetComponent
<
Controller
>();
yield
return
null
;
input
.
IsButtonDown
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
true
;
bool
isCorrect
=
true
;
new
Dictionary
<
float
,
Judge
>
{
{
0
,
Judge
.
JudgeList
[
0
]
},
{
Judge
.
JudgeList
[
0
].
ButtonTimingRange
-
1
,
Judge
.
JudgeList
[
0
]
},
{
Judge
.
JudgeList
[
0
].
ButtonTimingRange
,
Judge
.
JudgeList
[
1
]
},
{
Judge
.
JudgeList
[
1
].
ButtonTimingRange
-
1
,
Judge
.
JudgeList
[
1
]
},
{
Judge
.
JudgeList
[
1
].
ButtonTimingRange
,
Judge
.
JudgeList
[
2
]
},
{
Judge
.
JudgeList
[
2
].
ButtonTimingRange
-
1
,
Judge
.
JudgeList
[
2
]
},
{
Judge
.
JudgeList
[
2
].
ButtonTimingRange
,
Judge
.
JudgeList
[
3
]
}
}
.
ToList
()
.
ForEach
(
x
=>
{
controller
.
transform
.
SetParent
(
objects
[
"noteobj"
].
transform
);
controller
.
Instance
=
maker
.
MakeNote
(
"SBT"
,
0
);
controller
.
Instance
.
Component
=
controller
;
manager
.
JudgeNote
(
controller
.
Instance
,
x
.
Key
);
if
(
objects
[
"judgetext"
].
GetComponent
<
Text
>().
text
!=
x
.
Value
.
Name
)
isCorrect
=
false
;
})
;
manager
.
JudgeNote
(
controller
.
Instance
,
0
);
var
expected
=
true
;
var
actual
=
isCorrect
;
Assert
.
AreEqual
(
expected
,
actual
,
"Judge is valid when short note"
);
}
[
UnityTest
]
public
IEnumerator
Judge_Valid_When_Long
()
{
var
objects
=
MakeObjects
();
var
input
=
MakeInput
();
var
manager
=
new
JudgeManager
(
input
,
()
=>
{
},
objects
,
60
);
var
maker
=
new
TestNoteMaker
();
var
controller
=
objects
[
"appear"
].
transform
.
GetChild
(
0
)
.
GetComponent
<
Controller
>();
bool
isCorrect
=
true
;
controller
.
transform
.
SetParent
(
objects
[
"noteobj"
].
transform
);
controller
.
Instance
=
maker
.
MakeNote
(
"LBT"
,
0
,
2000
);
controller
.
Instance
.
Component
=
controller
;
yield
return
null
;
input
.
IsButtonDown
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
true
;
manager
.
JudgeNote
(
controller
.
Instance
,
0
);
if
(
controller
.
Instance
.
Activated
==
false
)
isCorrect
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
true
;
manager
.
JudgeNote
(
controller
.
Instance
,
1000
);
if
(
controller
.
Instance
.
JudgeCount
==
0
)
isCorrect
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
false
;
manager
.
JudgeNote
(
controller
.
Instance
,
2000
);
if
(
controller
.
Instance
.
JudgeCount
!=
1
||
objects
[
"judgetext"
].
GetComponent
<
Text
>().
text
==
Judge
.
MISS
.
Name
)
isCorrect
=
false
;
var
expected
=
true
;
var
actual
=
isCorrect
;
Assert
.
AreEqual
(
expected
,
actual
,
"Judge is valid when long note"
);
}
[
UnityTest
]
public
IEnumerator
Judge_Invalid_When_Long
()
{
var
objects
=
MakeObjects
();
var
input
=
MakeInput
();
var
manager
=
new
JudgeManager
(
input
,
()
=>
{
},
objects
,
60
);
var
maker
=
new
TestNoteMaker
();
var
controller
=
objects
[
"appear"
].
transform
.
GetChild
(
0
)
.
GetComponent
<
Controller
>();
bool
isCorrect
=
true
;
controller
.
transform
.
SetParent
(
objects
[
"noteobj"
].
transform
);
controller
.
Instance
=
maker
.
MakeNote
(
"LBT"
,
0
,
2000
);
controller
.
Instance
.
Component
=
controller
;
yield
return
null
;
input
.
IsButtonDown
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
true
;
manager
.
JudgeNote
(
controller
.
Instance
,
0
);
if
(
controller
.
Instance
.
Activated
==
false
)
isCorrect
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
true
;
manager
.
JudgeNote
(
controller
.
Instance
,
1000
);
if
(
controller
.
Instance
.
JudgeCount
==
0
)
isCorrect
=
false
;
yield
return
null
;
input
.
IsButtonDown
=
false
;
manager
.
JudgeNote
(
controller
.
Instance
,
1800
);
if
(
controller
.
Instance
.
JudgeCount
!=
1
||
objects
[
"judgetext"
].
GetComponent
<
Text
>().
text
!=
Judge
.
MISS
.
Name
)
isCorrect
=
false
;
var
expected
=
true
;
var
actual
=
isCorrect
;
Assert
.
AreEqual
(
expected
,
actual
,
"Judge is invalid when long note"
);
}
private
Dictionary
<
string
,
GameObject
>
MakeObjects
()
{
var
offset
=
new
GameObject
(
"Offset"
);
var
noteobj
=
new
GameObject
(
"NoteObj"
);
var
deactives
=
new
GameObject
(
"Deactives"
);
var
appear
=
new
GameObject
(
"AppearNote"
);
var
disappear
=
new
GameObject
(
"DisappearNote"
);
var
judgetext
=
new
GameObject
(
"Judge"
);
offset
.
transform
.
position
=
Vector3
.
zero
;
noteobj
.
transform
.
position
=
Vector3
.
zero
;
deactives
.
transform
.
position
=
Vector3
.
zero
;
appear
.
transform
.
position
=
Vector3
.
right
*
1000
;
disappear
.
transform
.
position
=
Vector3
.
left
*
1000
;
noteobj
.
transform
.
SetParent
(
offset
.
transform
);
deactives
.
transform
.
SetParent
(
offset
.
transform
);
Enumerable
.
Range
(
0
,
20
).
ToList
().
ForEach
(
x
=>
{
var
obj
=
new
GameObject
();
obj
.
transform
.
SetParent
(
appear
.
transform
);
var
controller
=
obj
.
AddComponent
<
Controller
>();
controller
.
Instance
=
new
Note
(
0
,
0
);
});
judgetext
.
AddComponent
<
Text
>();
return
new
Dictionary
<
string
,
GameObject
>
{
{
"offset"
,
offset
},
{
"noteobj"
,
noteobj
},
{
"deactives"
,
deactives
},
{
"appear"
,
appear
},
{
"disappear"
,
disappear
},
{
"judgetext"
,
judgetext
}
};
}
private
InputManager
MakeInput
()
{
var
obj
=
new
GameObject
();
return
obj
.
AddComponent
<
InputManager
>();
}
}
\ No newline at end of file
Assets/Script/Tests/JudgeManagerTests.cs.meta
0 → 100644
View file @
25a3d60c
fileFormatVersion: 2
guid: 141ae0ccc58281c4a8177fb1b037e44f
timeCreated: 1518879354
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Script/Tests/NoteJudgerTests.cs
View file @
25a3d60c
...
...
@@ -166,9 +166,9 @@ public class NoteJudgerTests
}
[
UnityTest
]
public
IEnumerator
ContinuingNoteProc_Should_
Deactive_When_Not_End_And_Break
()
public
IEnumerator
ContinuingNoteProc_Should_
Judge_Perfect_When_Next_Timeing_In_Interval
()
{
var
settings
=
new
TestSettings
(
"LBT"
,
0
,
Judge
.
BAD
.
ButtonTimingRange
+
1
);
var
settings
=
new
TestSettings
(
"LBT"
,
0
,
1000
);
var
note
=
settings
.
note
;
...
...
@@ -181,60 +181,18 @@ public class NoteJudgerTests
yield
return
null
;
judger
.
ContinuingNoteProc
(
note
,
-(
Judge
.
BAD
.
ButtonTimingRange
+
1
))
;
note
.
Activated
=
true
;
var
expected
=
"Deactives"
;
var
actual
=
note
.
Component
.
transform
.
parent
.
name
;
Assert
.
AreEqual
(
expected
,
actual
,
"ContinuingNoteProc should deactive when not end and break"
);
}
[
UnityTest
]
public
IEnumerator
ContinuingNoteProc_Should_Not_Deactive_When_End
()
{
var
settings
=
new
TestSettings
(
"LBT"
,
0
,
1
);
var
note
=
settings
.
note
;
var
judger
=
new
NoteJudger
(
new
Dictionary
<
string
,
GameObject
>
{
{
"deactives"
,
settings
.
deactives
},
{
"judgetext"
,
settings
.
judge
}
},
()
=>
{
});
yield
return
null
;
judger
.
ContinuingNoteProc
(
note
,
note
.
EndTiming
);
float
interval
=
60f
;
float
frame
=
10f
;
var
expected
=
"NoteObj"
;
var
actual
=
note
.
Component
.
transform
.
parent
.
name
;
Assert
.
AreEqual
(
expected
,
actual
,
"ContinuingNoteProc should not deactive when end"
);
}
[
UnityTest
]
public
IEnumerator
ContinuingNoteProc_Should_Not_Deactive_When_Not_Break
()
{
var
settings
=
new
TestSettings
(
"LBT"
,
0
,
Judge
.
BAD
.
ButtonTimingRange
+
1
);
var
note
=
settings
.
note
;
for
(
float
t
=
note
.
StartTiming
+
frame
;
t
<
note
.
EndTiming
;
t
+=
frame
)
judger
.
ContinuingNoteProc
(
note
,
t
,
interval
);
var
judger
=
new
NoteJudger
(
new
Dictionary
<
string
,
GameObject
>
{
{
"deactives"
,
settings
.
deactives
},
{
"judgetext"
,
settings
.
judge
}
},
()
=>
{
});
yield
return
null
;
judger
.
ContinuingNoteProc
(
note
,
note
.
StartTiming
);
var
expected
=
"NoteObj"
;
var
actual
=
note
.
Component
.
transform
.
parent
.
name
;
var
expected
=
(
int
)(
note
.
EndTiming
/
interval
);
var
actual
=
note
.
JudgeCount
;
Assert
.
AreEqual
(
expected
,
actual
,
"ContinuingNoteProc should
not deactive when not break
"
);
Assert
.
AreEqual
(
expected
,
actual
,
"ContinuingNoteProc should
judge perfect when next timing is included in interval
"
);
}
class
TestSettings
...
...
Assets/Script/Tests/NoteManagerTests.cs
View file @
25a3d60c
...
...
@@ -113,7 +113,7 @@ public class NoteManagerTests
return
Mathf
.
Abs
(
a
-
b
)
>=
errorLimit
;
}
p
ublic
Dictionary
<
string
,
GameObject
>
MakeObjects
()
p
rivate
Dictionary
<
string
,
GameObject
>
MakeObjects
()
{
var
offset
=
new
GameObject
();
var
noteobj
=
new
GameObject
();
...
...
@@ -134,6 +134,7 @@ public class NoteManagerTests
{
var
obj
=
new
GameObject
();
obj
.
transform
.
SetParent
(
appear
.
transform
);
var
controller
=
obj
.
AddComponent
<
Controller
>();
controller
.
Instance
=
new
Note
(
0
,
0
);
});
...
...
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