Skip to content

Commit bea03e3

Browse files
committed
Address codefactor issues
1 parent e3eb21d commit bea03e3

2 files changed

Lines changed: 35 additions & 34 deletions

File tree

test/xUnit/csharp/test_Prediction.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public SuggestionPackage GetSuggestion(string clientId, PredictionContext contex
9090

9191
// You can get the user input from the AST.
9292
var userInput = context.InputAst.Extent.Text;
93-
var entries = new List<PredictiveSuggestion> {
93+
var entries = new List<PredictiveSuggestion>
94+
{
9495
new PredictiveSuggestion($"'{userInput}' from '{clientId}' - TEST-1 from {Name}"),
9596
new PredictiveSuggestion($"'{userInput}' from '{clientId}' - TeSt-2 from {Name}"),
9697
};
@@ -101,19 +102,19 @@ public SuggestionPackage GetSuggestion(string clientId, PredictionContext contex
101102

102103
public static class CommandPredictionTests
103104
{
104-
private const string client = "PredictionTest";
105-
private const uint session = 56;
105+
private const string Client = "PredictionTest";
106+
private const uint Session = 56;
106107

107108
[Fact]
108109
public static void PredictInput()
109110
{
110-
const string input = "Hello world";
111+
const string Input = "Hello world";
111112
MyPredictor slow = MyPredictor.SlowPredictor;
112113
MyPredictor fast = MyPredictor.FastPredictor;
113-
Ast ast = Parser.ParseInput(input, out Token[] tokens, out _);
114+
Ast ast = Parser.ParseInput(Input, out Token[] tokens, out _);
114115

115116
// Returns null when no predictor implementation registered
116-
List<PredictionResult> results = CommandPrediction.PredictInput(client, ast, tokens).Result;
117+
List<PredictionResult> results = CommandPrediction.PredictInput(Client, ast, tokens).Result;
117118
Assert.Null(results);
118119

119120
try
@@ -126,35 +127,35 @@ public static void PredictInput()
126127
// cannot finish before the specified timeout.
127128
// The specified timeout is exaggerated to make the test reliable.
128129
// xUnit must spin up a lot tasks, which makes the test unreliable when the time difference between 'delay' and 'timeout' is small.
129-
results = CommandPrediction.PredictInput(client, ast, tokens, millisecondsTimeout: 1000).Result;
130+
results = CommandPrediction.PredictInput(Client, ast, tokens, millisecondsTimeout: 1000).Result;
130131
Assert.Single(results);
131132

132133
PredictionResult res = results[0];
133134
Assert.Equal(fast.Id, res.Id);
134-
Assert.Equal(session, res.Session);
135+
Assert.Equal(Session, res.Session);
135136
Assert.Equal(2, res.Suggestions.Count);
136-
Assert.Equal($"'{input}' from '{client}' - TEST-1 from {fast.Name}", res.Suggestions[0].SuggestionText);
137-
Assert.Equal($"'{input}' from '{client}' - TeSt-2 from {fast.Name}", res.Suggestions[1].SuggestionText);
137+
Assert.Equal($"'{Input}' from '{Client}' - TEST-1 from {fast.Name}", res.Suggestions[0].SuggestionText);
138+
Assert.Equal($"'{Input}' from '{Client}' - TeSt-2 from {fast.Name}", res.Suggestions[1].SuggestionText);
138139

139140
// Expect the results from both 'slow' and 'fast' predictors
140141
// Same here -- the specified timeout is exaggerated to make the test reliable.
141142
// xUnit must spin up a lot tasks, which makes the test unreliable when the time difference between 'delay' and 'timeout' is small.
142-
results = CommandPrediction.PredictInput(client, ast, tokens, millisecondsTimeout: 4000).Result;
143+
results = CommandPrediction.PredictInput(Client, ast, tokens, millisecondsTimeout: 4000).Result;
143144
Assert.Equal(2, results.Count);
144145

145146
PredictionResult res1 = results[0];
146147
Assert.Equal(slow.Id, res1.Id);
147-
Assert.Equal(session, res1.Session);
148+
Assert.Equal(Session, res1.Session);
148149
Assert.Equal(2, res1.Suggestions.Count);
149-
Assert.Equal($"'{input}' from '{client}' - TEST-1 from {slow.Name}", res1.Suggestions[0].SuggestionText);
150-
Assert.Equal($"'{input}' from '{client}' - TeSt-2 from {slow.Name}", res1.Suggestions[1].SuggestionText);
150+
Assert.Equal($"'{Input}' from '{Client}' - TEST-1 from {slow.Name}", res1.Suggestions[0].SuggestionText);
151+
Assert.Equal($"'{Input}' from '{Client}' - TeSt-2 from {slow.Name}", res1.Suggestions[1].SuggestionText);
151152

152153
PredictionResult res2 = results[1];
153154
Assert.Equal(fast.Id, res2.Id);
154-
Assert.Equal(session, res2.Session);
155+
Assert.Equal(Session, res2.Session);
155156
Assert.Equal(2, res2.Suggestions.Count);
156-
Assert.Equal($"'{input}' from '{client}' - TEST-1 from {fast.Name}", res2.Suggestions[0].SuggestionText);
157-
Assert.Equal($"'{input}' from '{client}' - TeSt-2 from {fast.Name}", res2.Suggestions[1].SuggestionText);
157+
Assert.Equal($"'{Input}' from '{Client}' - TEST-1 from {fast.Name}", res2.Suggestions[0].SuggestionText);
158+
Assert.Equal($"'{Input}' from '{Client}' - TeSt-2 from {fast.Name}", res2.Suggestions[1].SuggestionText);
158159
}
159160
finally
160161
{
@@ -178,10 +179,10 @@ public static void Feedback()
178179
var history = new[] { "hello", "world" };
179180
var ids = new HashSet<Guid> { slow.Id, fast.Id };
180181

181-
CommandPrediction.OnCommandLineAccepted(client, history);
182-
CommandPrediction.OnSuggestionDisplayed(slow.Id, session, 2);
183-
CommandPrediction.OnSuggestionDisplayed(fast.Id, session, -1);
184-
CommandPrediction.OnSuggestionAccepted(slow.Id, session, "Yeah");
182+
CommandPrediction.OnCommandLineAccepted(Client, history);
183+
CommandPrediction.OnSuggestionDisplayed(slow.Id, Session, 2);
184+
CommandPrediction.OnSuggestionDisplayed(fast.Id, Session, -1);
185+
CommandPrediction.OnSuggestionAccepted(slow.Id, Session, "Yeah");
185186

186187
// The calls to 'StartEarlyProcessing' and 'OnSuggestionAccepted' are queued in thread pool,
187188
// so we wait a bit to make sure the calls are done.
@@ -191,21 +192,21 @@ public static void Feedback()
191192
}
192193

193194
Assert.Equal(2, slow.History.Count);
194-
Assert.Equal($"{client}-{history[0]}", slow.History[0]);
195-
Assert.Equal($"{client}-{history[1]}", slow.History[1]);
195+
Assert.Equal($"{Client}-{history[0]}", slow.History[0]);
196+
Assert.Equal($"{Client}-{history[1]}", slow.History[1]);
196197

197198
Assert.Equal(2, fast.History.Count);
198-
Assert.Equal($"{client}-{history[0]}", fast.History[0]);
199-
Assert.Equal($"{client}-{history[1]}", fast.History[1]);
199+
Assert.Equal($"{Client}-{history[0]}", fast.History[0]);
200+
Assert.Equal($"{Client}-{history[1]}", fast.History[1]);
200201

201202
Assert.Single(slow.DisplayedSuggestions);
202-
Assert.Equal($"{session}-2", slow.DisplayedSuggestions[0]);
203+
Assert.Equal($"{Session}-2", slow.DisplayedSuggestions[0]);
203204

204205
Assert.Single(fast.DisplayedSuggestions);
205-
Assert.Equal($"{session}--1", fast.DisplayedSuggestions[0]);
206+
Assert.Equal($"{Session}--1", fast.DisplayedSuggestions[0]);
206207

207208
Assert.Single(slow.AcceptedSuggestions);
208-
Assert.Equal($"{session}-Yeah", slow.AcceptedSuggestions[0]);
209+
Assert.Equal($"{Session}-Yeah", slow.AcceptedSuggestions[0]);
209210

210211
Assert.Empty(fast.AcceptedSuggestions);
211212
}

test/xUnit/csharp/test_Subsystem.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ public static void RegisterSubsystem()
9595
Assert.Null(impl.FunctionsToDefine);
9696
Assert.Equal(SubsystemKind.CommandPredictor, impl.Kind);
9797

98-
const string client = "SubsystemTest";
99-
const string input = "Hello world";
100-
var predCxt = PredictionContext.Create(input);
101-
var results = impl.GetSuggestion(client, predCxt, CancellationToken.None);
102-
Assert.Equal($"'{input}' from '{client}' - TEST-1 from {impl.Name}", results.SuggestionEntries[0].SuggestionText);
103-
Assert.Equal($"'{input}' from '{client}' - TeSt-2 from {impl.Name}", results.SuggestionEntries[1].SuggestionText);
98+
const string Client = "SubsystemTest";
99+
const string Input = "Hello world";
100+
var predCxt = PredictionContext.Create(Input);
101+
var results = impl.GetSuggestion(Client, predCxt, CancellationToken.None);
102+
Assert.Equal($"'{Input}' from '{Client}' - TEST-1 from {impl.Name}", results.SuggestionEntries[0].SuggestionText);
103+
Assert.Equal($"'{Input}' from '{Client}' - TeSt-2 from {impl.Name}", results.SuggestionEntries[1].SuggestionText);
104104

105105
// Now validate the all-subsystem-implementation collection.
106106
ReadOnlyCollection<ICommandPredictor> impls = SubsystemManager.GetSubsystems<ICommandPredictor>();

0 commit comments

Comments
 (0)