Skip to content

Commit a5ce322

Browse files
author
msftbot[bot]
authored
Rangeselector tests (#3926)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> <!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 --> ## Fixes Adds tests for the range selector properties. <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> Added unit tests for code interactions with the range selector properties. ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <!-- - Bugfix --> <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> No tests for the RangeSelector properties. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> Tests for the RangeSelector properties. ## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [ ] Tests for the changes have been added (for bug fixes / features) (if applicable) - [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [ ] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information
2 parents d1f334a + dcd7014 commit a5ce322

File tree

3 files changed

+387
-0
lines changed

3 files changed

+387
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Runtime.CompilerServices
6+
{
7+
// HACK (2021.05.07): Included as a workaround for multiple occurrences of
8+
// error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported
9+
// in UnitTests\UnitTests.UWP\UI\Controls\Test_RangeSelector.cs.
10+
// This is caused by using [Positional Records](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9#record-types)
11+
// which use [Init Only setters](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9#init-only-setters) under the hood for all the properties,
12+
// and currently the type is only included net5.0 and up.
13+
// The recommended action is to include the type manually. https://developercommunity.visualstudio.com/t/error-cs0518-predefined-type-systemruntimecompiler/1244809#T-N1249582
14+
internal static class IsExternalInit
15+
{
16+
}
17+
}
Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.Toolkit.Uwp;
6+
using Microsoft.Toolkit.Uwp.UI.Controls;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
using System.Threading.Tasks;
9+
10+
namespace UnitTests.UI.Controls
11+
{
12+
[TestClass]
13+
public class Test_RangeSelector : VisualUITestBase
14+
{
15+
#pragma warning disable SA1008, SA1025, SA1021
16+
[TestCategory("Initialize")]
17+
[TestMethod]
18+
19+
// If
20+
// Minimum < Maximum
21+
//
22+
// Then
23+
// Minimum dose not change
24+
// Maximum dose not change
25+
26+
// If
27+
// Minimum < Maximum
28+
// RangeStart >= Minimum
29+
// RangeStart <= Maximum
30+
// RangeStart <= RangeEnd
31+
//
32+
// Then
33+
// RangeStart does not change
34+
35+
// If
36+
// Minimum < Maximum
37+
// RangeEnd >= Minimum
38+
// RangeEnd <= Maximum
39+
// RangeEnd >= RangeStart
40+
//
41+
// Then
42+
// RangeEnd dose not change
43+
// Input:Start End Expected:Start End
44+
[DataRow( 0, 100, 0, 100)]
45+
[DataRow( 10, 90, 10, 90)]
46+
[DataRow( 50, 50, 50, 50)]
47+
[DataRow( 0, 90, 0, 90)]
48+
[DataRow( 0, 0, 0, 0)]
49+
[DataRow( 10, 100, 10, 100)]
50+
[DataRow( 100, 100, 100, 100)]
51+
52+
// If
53+
// Minimum < Maximum
54+
// RangeEnd <= Maximum
55+
// RangeEnd >= Minimum
56+
// RangeStart >= Minimum
57+
// RangeStart >= RangeEnd
58+
//
59+
// Then
60+
// RangeStart will be RangeEnd
61+
[DataRow( 90, 10, 10, 10)]
62+
[DataRow( 110, 10, 10, 10)]
63+
64+
// If
65+
// Minimum < Maximum
66+
// RangeStart <= Minimum
67+
//
68+
// Then
69+
// RangeStart will be Minimum
70+
71+
// If
72+
// Minimum < Maximum
73+
// RangeEnd <= Minimum
74+
//
75+
// Then
76+
// RangeEnd will be Minimum
77+
78+
// If
79+
// Minimum < Maximum
80+
// RangeEnd <= Minimum
81+
// RangeStart >= RangeEnd
82+
//
83+
// Then
84+
// RangeEnd will be Minimum
85+
// RangeStart will be Minimum
86+
[DataRow( -50, -50, 0, 0)]
87+
[DataRow( -90, 90, 0, 90)]
88+
[DataRow( -90, -10, 0, 0)]
89+
[DataRow( -10, -90, 0, 0)]
90+
[DataRow( 10, -90, 0, 0)]
91+
92+
// If
93+
// Minimum < Maximum
94+
// RangeEnd >= Maximum
95+
//
96+
// Then
97+
// RangeEnd will be Maximum
98+
99+
// If
100+
// Minimum < Maximum
101+
// RangeStart >= Maximum
102+
// RangeEnd >= Maximum
103+
//
104+
// Then
105+
// RangeStart will be Maximum
106+
// RangeEnd will be Maximum
107+
[DataRow( 150, 150, 100, 100)]
108+
[DataRow( 10, 190, 10, 100)]
109+
[DataRow( 110, 190, 100, 100)]
110+
[DataRow( 190, 110, 100, 100)]
111+
public Task Initialize_MinLtMax(double rangeStart, double rangeEnd, double expectedRangeStart, double expectedRangeEnd)
112+
=> Initialize(1, 0, rangeStart, rangeEnd, 100, 1, 0, expectedRangeStart, expectedRangeEnd, 100);
113+
114+
[TestCategory("Initialize")]
115+
[TestMethod]
116+
117+
// If
118+
// Minimum >= Maximum
119+
//
120+
// Then
121+
// Minimum will be Maximum
122+
// Maximum will be Maximum + 0.01
123+
124+
// If
125+
// Minimum >= Maximum
126+
// RangeStart > Maximum
127+
// RangeEnd > Maximum
128+
//
129+
// Then
130+
// RangeStart will be Maximum + 0.01
131+
// Else
132+
// RangeStart will be Maximum
133+
134+
// If
135+
// Minimum >= Maximum
136+
// RangeEnd > Maximum
137+
//
138+
// Then
139+
// RangeEnd will be Maximum + 0.01
140+
// Else
141+
// RangeEnd will be Maximum
142+
143+
// Input:Start End Expected:Start End
144+
[DataRow( 0, 0, 0, 0)]
145+
[DataRow( 0, 10, 0, 0.01)]
146+
[DataRow( 0, -10, 0, 0)]
147+
[DataRow( -10, 0, 0, 0)]
148+
[DataRow( 10, 0, 0, 0)]
149+
[DataRow( 10, 90, 0.01, 0.01)]
150+
[DataRow( 90, 10, 0.01, 0.01)]
151+
[DataRow( -90, -10, 0, 0)]
152+
[DataRow( -10, -90, 0, 0)]
153+
[DataRow( 10, -10, 0, 0)]
154+
[DataRow( -10, 10, 0, 0.01)]
155+
public Task Initialize_MinEqMax(double rangeStart, double rangeEnd, double expectedRangeStart, double expectedRangeEnd)
156+
=> Initialize(1, 0, rangeStart, rangeEnd, 0, 1, 0, expectedRangeStart, expectedRangeEnd, 0.01);
157+
158+
[TestCategory("Initialize")]
159+
[TestMethod]
160+
[DataRow( 0, 100, 0, 0.01)]
161+
[DataRow( 10, 90, 0.01, 0.01)]
162+
[DataRow( 50, 50, 0.01, 0.01)]
163+
[DataRow( 0, 0, 0, 0)]
164+
[DataRow( 100, 100, 0.01, 0.01)]
165+
166+
[DataRow( 10, 100, 0.01, 0.01)]
167+
168+
[DataRow( 90, 10, 0.01, 0.01)]
169+
[DataRow( 100, 10, 0.01, 0.01)]
170+
[DataRow( 90, 0, 0, 0)]
171+
172+
[DataRow( 100, 0, 0, 0)]
173+
174+
[DataRow( -90, -10, 0, 0)]
175+
[DataRow( -10, -90, 0, 0)]
176+
[DataRow( -50, -50, 0, 0)]
177+
178+
[DataRow( 110, 190, 0.01, 0.01)]
179+
[DataRow( 190, 110, 0.01, 0.01)]
180+
[DataRow( 150, 150, 0.01, 0.01)]
181+
public Task Initialize_MinGtMax(double rangeStart, double rangeEnd, double expectedRangeStart, double expectedRangeEnd)
182+
=> Initialize(1, 100, rangeStart, rangeEnd, 0, 1, 0, expectedRangeStart, expectedRangeEnd, 0.01);
183+
184+
[TestMethod]
185+
[TestCategory("Set Prop")]
186+
187+
// Set:Min Then:Min Start End Max
188+
[DataRow( 0, 0, 10 , 90 , 100 )]
189+
[DataRow( -10, -10, 10 , 90 , 100 )]
190+
[DataRow( 10, 10, 10 , 90 , 100 )]
191+
[DataRow( 50, 50, 50 , 90 , 100 )]
192+
[DataRow( 90, 90, 90 , 90 , 100 )]
193+
[DataRow( 100, 100, 100 , 100 , 100 )]
194+
[DataRow( 110, 110, 110.01, 110.01, 110.01)]
195+
public Task SetMinimum(double setMinimumValue, double expectedMinimum, double expectedRangeStart, double expectedRangeEnd, double expectedMaximum)
196+
=> SetProp(1, 0, 10, 90, 100, Property.Minimum, setMinimumValue, 1, expectedMinimum, expectedRangeStart, expectedRangeEnd, expectedMaximum);
197+
198+
[TestMethod]
199+
[TestCategory("Set Prop")]
200+
201+
// Set:Max Then:Min Start End Max
202+
[DataRow( 100, 0 , 10, 90, 100)]
203+
[DataRow( 110, 0 , 10, 90, 110)]
204+
[DataRow( 90, 0 , 10, 90, 90)]
205+
[DataRow( 50, 0 , 10, 50, 50)]
206+
[DataRow( 10, 0 , 10, 10, 10)]
207+
[DataRow( 0, 0 , 0, 0, 0)]
208+
[DataRow( -10, -10.01, -10, -10, -10)]
209+
public Task SetMaximum(double propInput, double expectedMinimum, double expectedRangeStart, double expectedRangeEnd, double expectedMaximum)
210+
=> SetProp(1, 0, 10, 90, 100, Property.Maximum, propInput, 1, expectedMinimum, expectedRangeStart, expectedRangeEnd, expectedMaximum);
211+
212+
[TestMethod]
213+
[TestCategory("Set Prop")]
214+
215+
// Set:Start Then:Start End
216+
[DataRow( 10, 10, 90)]
217+
[DataRow( 5, 5, 90)]
218+
[DataRow( 0, 0, 90)]
219+
[DataRow(-10, 0, 90)]
220+
[DataRow( 90, 90, 90)]
221+
[DataRow( 95, 95, 95)]
222+
[DataRow(100, 100, 100)]
223+
[DataRow(110, 100, 100)]
224+
public Task SetRangeStart(double propInput, double expectedRangeStart, double expectedRangeEnd)
225+
=> SetProp(1, 0, 10, 90, 100, Property.RangeStart, propInput, 1, 0, expectedRangeStart, expectedRangeEnd, 100);
226+
227+
[TestMethod]
228+
[TestCategory("Set Prop")]
229+
230+
// Given:Step Start End Set:Start Then:Start End
231+
[DataRow( 5, 10, 90, 10, 10, 90)]
232+
[DataRow( 5, 10, 90, 5, 5, 90)]
233+
[DataRow( 5, 10, 90, 0, 0, 90)]
234+
[DataRow( 5, 10, 90, 1, 0, 90)]
235+
[DataRow( 5, 10, 90, 2.4, 0, 90)]
236+
[DataRow( 5, 10, 90, 2.5, 0, 90)]
237+
[DataRow( 5, 10, 90, 2.6, 5, 90)]
238+
[DataRow( 5, 10, 90, 4, 5, 90)]
239+
[DataRow( 5, 10, 90, 6, 5, 90)]
240+
[DataRow( 5, 10, 90, 9, 10, 90)]
241+
[DataRow( 5, 10, 90, 100, 100, 100)]
242+
[DataRow( 5, 10, 90, 89, 90, 90)]
243+
[DataRow( 5, 10, 90, 91, 90, 90)]
244+
[DataRow( 30, 60, 70, 80, 100, 100)]
245+
[DataRow( 30, 60, 70, 74, 60, 60)]
246+
[DataRow( 30, 60, 70, 75, 60, 60)]
247+
[DataRow( 30, 60, 70, 76, 100, 100)]
248+
[DataRow( 40, 40, 60, 20, 0, 60)]
249+
[DataRow( 40, 40, 60, 50, 40, 60)]
250+
[DataRow( 40, 40, 60, 60, 100, 100)]
251+
public Task SetRangeStart_StepTest(double stepFrequency, double rangeStart, double rangeEnd, double propInput, double expectedRangeStart, double expectedRangeEnd)
252+
=> SetProp(stepFrequency, 0, rangeStart, rangeEnd, 100, Property.RangeStart, propInput, stepFrequency, 0, expectedRangeStart, expectedRangeEnd, 100);
253+
254+
[TestMethod]
255+
[TestCategory("Set Prop")]
256+
257+
// Set:End Then:Start End
258+
[DataRow( 90, 10, 90)]
259+
[DataRow( 95, 10, 95)]
260+
[DataRow( 100, 10, 100)]
261+
[DataRow( 110, 10, 100)]
262+
[DataRow( 10, 10, 10)]
263+
[DataRow( 5, 5, 5)]
264+
[DataRow( 0, 0, 0)]
265+
[DataRow( -10, 0, 0)]
266+
public Task SetRangeEnd(double propInput, double expectedRangeStart, double expectedRangeEnd)
267+
=> SetProp(1, 0, 10, 90, 100, Property.RangeEnd, propInput, 1, 0, expectedRangeStart, expectedRangeEnd, 100);
268+
269+
[TestMethod]
270+
[TestCategory("Set Prop")]
271+
272+
// Given:Step Start End Set:End Then:Start End
273+
[DataRow( 30, 60, 70, 50, 60, 60)]
274+
[DataRow( 30, 60, 70, 36, 30, 30)]
275+
[DataRow( 30, 60, 70, 35, 30, 30)]
276+
[DataRow( 30, 60, 70, 34, 30, 30)]
277+
[DataRow( 40, 40, 60, 80, 40, 100)]
278+
[DataRow( 40, 40, 60, 30, 40, 40)]
279+
[DataRow( 40, 40, 60, 0, 0, 0)]
280+
public Task SetRangeEnd_StepTest(double stepFrequency, double rangeStart, double rangeEnd, double propInput, double expectedRangeStart, double expectedRangeEnd)
281+
=> SetProp(stepFrequency, 0, rangeStart, rangeEnd, 100, Property.RangeEnd, propInput, stepFrequency, 0, expectedRangeStart, expectedRangeEnd, 100);
282+
283+
#pragma warning restore SA1025, SA1008, SA1021
284+
285+
private async Task Initialize(double stepFrequency, double minimum, double rangeStart, double rangeEnd, double maximum, double expectedStepFrequency, double expectedMinimum, double expectedRangeStart, double expectedRangeEnd, double expectedMaximum)
286+
{
287+
var initalProps = new TestRecord(stepFrequency, minimum, rangeStart, rangeEnd, maximum);
288+
var inital = await InitGetProps(initalProps);
289+
290+
Assert.AreEqual(new TestRecord(expectedStepFrequency, expectedMinimum, expectedRangeStart, expectedRangeEnd, expectedMaximum), inital.Item2);
291+
}
292+
293+
private async Task SetProp(double stepFrequency, double minimum, double rangeStart, double rangeEnd, double maximum, Property targetProp, double propInput, double expectedStepFrequency, double expectedMinimum, double expectedRangeStart, double expectedRangeEnd, double expectedMaximum)
294+
{
295+
var initalProps = new TestRecord(stepFrequency, minimum, rangeStart, rangeEnd, maximum);
296+
var inital = await InitGetProps(initalProps);
297+
Assert.AreEqual(initalProps, inital.Item2);
298+
299+
var post = await SetPropGetProps(inital.Item1, targetProp, propInput);
300+
Assert.AreEqual(new TestRecord(expectedStepFrequency, expectedMinimum, expectedRangeStart, expectedRangeEnd, expectedMaximum), post);
301+
}
302+
303+
private async Task<(RangeSelector, TestRecord)> InitGetProps(TestRecord testRecord)
304+
{
305+
var t = testRecord;
306+
return await App.DispatcherQueue.EnqueueAsync(async () =>
307+
{
308+
var ragneSelector = BuildRangeSelecor(t);
309+
await SetTestContentAsync(ragneSelector);
310+
var testRecord = BuildTestRecord(ragneSelector);
311+
return (ragneSelector, testRecord);
312+
});
313+
}
314+
315+
private async Task<TestRecord> SetPropGetProps(RangeSelector test, Property targetProp, double propInput)
316+
{
317+
return await App.DispatcherQueue.EnqueueAsync(() =>
318+
{
319+
switch (targetProp)
320+
{
321+
case Property.Minimum:
322+
test.Minimum = propInput;
323+
break;
324+
case Property.Maximum:
325+
test.Maximum = propInput;
326+
break;
327+
case Property.RangeStart:
328+
test.RangeStart = propInput;
329+
break;
330+
case Property.RangeEnd:
331+
test.RangeEnd = propInput;
332+
break;
333+
case Property.StepFrequency:
334+
test.StepFrequency = propInput;
335+
break;
336+
default:
337+
break;
338+
}
339+
340+
return BuildTestRecord(test);
341+
});
342+
}
343+
344+
private enum Property
345+
{
346+
StepFrequency,
347+
Minimum,
348+
Maximum,
349+
RangeStart,
350+
RangeEnd
351+
}
352+
353+
private record TestRecord(double StepFrequency, double Minimum, double RangeStart, double RangeEnd, double Maximum);
354+
355+
private static RangeSelector BuildRangeSelecor(TestRecord input)
356+
=> new()
357+
{
358+
StepFrequency = input.StepFrequency,
359+
Minimum = input.Minimum,
360+
Maximum = input.Maximum,
361+
RangeStart = input.RangeStart,
362+
RangeEnd = input.RangeEnd,
363+
};
364+
365+
private static TestRecord BuildTestRecord(RangeSelector r)
366+
=> new(r.StepFrequency, r.Minimum, r.RangeStart, r.RangeEnd, r.Maximum);
367+
}
368+
}

0 commit comments

Comments
 (0)