-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathInputModifierComponentShould.cs
More file actions
153 lines (136 loc) · 5.22 KB
/
Copy pathInputModifierComponentShould.cs
File metadata and controls
153 lines (136 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using DCL.SDKComponents.InputModifier.Components;
using NUnit.Framework;
namespace DCL.SDKComponents.InputModifier.Tests
{
public class InputModifierComponentShould
{
public enum ModifierFlag
{
Walk,
Jog,
Run,
Jump,
Emote,
DoubleJump,
Gliding,
All,
}
[Test]
public void BeEverythingEnabled_ByDefault()
{
var component = new InputModifierComponent();
Assert.IsTrue(component.EverythingEnabled);
}
[TestCase(ModifierFlag.Walk)]
[TestCase(ModifierFlag.Jog)]
[TestCase(ModifierFlag.Run)]
[TestCase(ModifierFlag.Jump)]
[TestCase(ModifierFlag.Emote)]
[TestCase(ModifierFlag.DoubleJump)]
[TestCase(ModifierFlag.Gliding)]
[TestCase(ModifierFlag.All)]
public void NotBeEverythingEnabled_WhenAnyFlagDisabled(ModifierFlag flag)
{
var component = new InputModifierComponent();
Set(ref component, flag, true);
Assert.IsFalse(component.EverythingEnabled);
}
[TestCase(ModifierFlag.Walk)]
[TestCase(ModifierFlag.Jog)]
[TestCase(ModifierFlag.Run)]
[TestCase(ModifierFlag.Jump)]
[TestCase(ModifierFlag.Emote)]
[TestCase(ModifierFlag.DoubleJump)]
[TestCase(ModifierFlag.Gliding)]
public void ReportEveryFlagDisabled_WhenDisableAllIsSet(ModifierFlag flag)
{
// DisableAll must dominate every individual flag getter.
var component = new InputModifierComponent { DisableAll = true };
Assert.IsTrue(Get(in component, flag));
}
[TestCase(ModifierFlag.Walk)]
[TestCase(ModifierFlag.Jog)]
[TestCase(ModifierFlag.Run)]
[TestCase(ModifierFlag.Jump)]
[TestCase(ModifierFlag.Emote)]
[TestCase(ModifierFlag.DoubleJump)]
[TestCase(ModifierFlag.Gliding)]
public void SetOnlyTheTargetedFlag_WhenDisabledIndividually(ModifierFlag flag)
{
// Each setter must map to its own bit and leave the others untouched.
var component = new InputModifierComponent();
Set(ref component, flag, true);
foreach (ModifierFlag other in System.Enum.GetValues(typeof(ModifierFlag)))
{
if (other == flag) continue;
Assert.IsFalse(Get(in component, other), $"{other} must stay enabled when only {flag} is disabled");
}
}
[Test]
public void ClearOnlyTheTargetedFlag_WhenSetBackToFalse()
{
var component = new InputModifierComponent();
component.DisableWalk = true;
component.DisableGliding = true;
component.DisableWalk = false;
Assert.IsFalse(component.DisableWalk);
Assert.IsTrue(component.DisableGliding);
}
[Test]
public void BeEverythingEnabled_AfterRemoveAllModifiers()
{
var component = new InputModifierComponent();
component.DisableWalk = true;
component.DisableGliding = true;
component.DisableDoubleJump = true;
component.RemoveAllModifiers();
Assert.IsTrue(component.EverythingEnabled);
Assert.IsFalse(component.DisableWalk);
Assert.IsFalse(component.DisableGliding);
Assert.IsFalse(component.DisableDoubleJump);
}
private static void Set(ref InputModifierComponent component, ModifierFlag flag, bool value)
{
switch (flag)
{
case ModifierFlag.Walk:
component.DisableWalk = value;
break;
case ModifierFlag.Jog:
component.DisableJog = value;
break;
case ModifierFlag.Run:
component.DisableRun = value;
break;
case ModifierFlag.Jump:
component.DisableJump = value;
break;
case ModifierFlag.Emote:
component.DisableEmote = value;
break;
case ModifierFlag.DoubleJump:
component.DisableDoubleJump = value;
break;
case ModifierFlag.Gliding:
component.DisableGliding = value;
break;
case ModifierFlag.All:
component.DisableAll = value;
break;
}
}
private static bool Get(in InputModifierComponent component, ModifierFlag flag) =>
flag switch
{
ModifierFlag.Walk => component.DisableWalk,
ModifierFlag.Jog => component.DisableJog,
ModifierFlag.Run => component.DisableRun,
ModifierFlag.Jump => component.DisableJump,
ModifierFlag.Emote => component.DisableEmote,
ModifierFlag.DoubleJump => component.DisableDoubleJump,
ModifierFlag.Gliding => component.DisableGliding,
ModifierFlag.All => component.DisableAll,
_ => false,
};
}
}