mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-22 10:07:37 +00:00
* [Mouse Jump] - moving common code to MouseJump.Common project - #25482 * [Mouse Jump] - fixing warnings in MouseJump.Common - #25482 * [MouseJump] - cherrypick 5653b4 - Exclude MouseJump Common tests from the checks # Conflicts: # src/modules/MouseUtils/MouseJump.Common.UnitTests/MouseJump.Common.UnitTests.csproj * [mOuSEjUMP] - cherry pick 61aab9 - Fix ci build issues # Conflicts: # src/modules/MouseUtils/MouseJump.Common.UnitTests/MouseJump.Common.UnitTests.csproj * [Mouse Jump] - remove project type guids - #25482 * [Mouse Jump] - simplify mousejump *.csproj files - #25482 * [Mouse Jump] - fixing broken tests - #25482 * [Mouse Jump] - fixing broken build - #25482 * [Mouse Jump] - editing MouseJump.Common.UnitTests.csproj - #25482 * [Mouse Jump] - editing MouseJump.Common.csproj (UseWindowsForms=true) - #25482 * [Mouse Jump] - fixing spellcheck - #25482 * [MouseJump] - enabled implicit usings - #25482 * [Mouse Jump] - re-add csproj attributes - #27511 * ci: Fix signing of Common dll --------- Co-authored-by: Clayton <mike.clayton@delinian.com>
106 lines
3.6 KiB
C#
106 lines
3.6 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using MouseJump.Common.Models.Drawing;
|
|
|
|
namespace MouseJump.Common.UnitTests.Models.Drawing;
|
|
|
|
[TestClass]
|
|
public static class SizeInfoTests
|
|
{
|
|
[TestClass]
|
|
public sealed class ScaleToFitTests
|
|
{
|
|
public sealed class TestCase
|
|
{
|
|
public TestCase(SizeInfo obj, SizeInfo bounds, SizeInfo expectedResult)
|
|
{
|
|
this.Obj = obj;
|
|
this.Bounds = bounds;
|
|
this.ExpectedResult = expectedResult;
|
|
}
|
|
|
|
public SizeInfo Obj { get; }
|
|
|
|
public SizeInfo Bounds { get; }
|
|
|
|
public SizeInfo ExpectedResult { get; }
|
|
}
|
|
|
|
public static IEnumerable<object[]> GetTestCases()
|
|
{
|
|
// identity tests
|
|
yield return new object[] { new TestCase(new(512, 384), new(512, 384), new(512, 384)), };
|
|
yield return new object[] { new TestCase(new(1024, 768), new(1024, 768), new(1024, 768)), };
|
|
|
|
// general tests
|
|
yield return new object[] { new TestCase(new(512, 384), new(2048, 1536), new(2048, 1536)), };
|
|
yield return new object[] { new TestCase(new(2048, 1536), new(1024, 768), new(1024, 768)), };
|
|
|
|
// scale to fit width
|
|
yield return new object[] { new TestCase(new(512, 384), new(2048, 3072), new(2048, 1536)), };
|
|
|
|
// scale to fit height
|
|
yield return new object[] { new TestCase(new(512, 384), new(4096, 1536), new(2048, 1536)), };
|
|
}
|
|
|
|
[TestMethod]
|
|
[DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)]
|
|
public void RunTestCases(TestCase data)
|
|
{
|
|
var actual = data.Obj.ScaleToFit(data.Bounds);
|
|
var expected = data.ExpectedResult;
|
|
Assert.AreEqual(expected.Width, actual.Width);
|
|
Assert.AreEqual(expected.Height, actual.Height);
|
|
}
|
|
}
|
|
|
|
[TestClass]
|
|
public sealed class ScaleToFitRatioTests
|
|
{
|
|
public sealed class TestCase
|
|
{
|
|
public TestCase(SizeInfo obj, SizeInfo bounds, decimal expectedResult)
|
|
{
|
|
this.Obj = obj;
|
|
this.Bounds = bounds;
|
|
this.ExpectedResult = expectedResult;
|
|
}
|
|
|
|
public SizeInfo Obj { get; }
|
|
|
|
public SizeInfo Bounds { get; }
|
|
|
|
public decimal ExpectedResult { get; }
|
|
}
|
|
|
|
public static IEnumerable<object[]> GetTestCases()
|
|
{
|
|
// identity tests
|
|
yield return new object[] { new TestCase(new(512, 384), new(512, 384), 1), };
|
|
yield return new object[] { new TestCase(new(1024, 768), new(1024, 768), 1), };
|
|
|
|
// general tests
|
|
yield return new object[] { new TestCase(new(512, 384), new(2048, 1536), 4), };
|
|
yield return new object[] { new TestCase(new(2048, 1536), new(1024, 768), 0.5M), };
|
|
|
|
// scale to fit width
|
|
yield return new object[] { new TestCase(new(512, 384), new(2048, 3072), 4), };
|
|
|
|
// scale to fit height
|
|
yield return new object[] { new TestCase(new(512, 384), new(4096, 1536), 4), };
|
|
}
|
|
|
|
[TestMethod]
|
|
[DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)]
|
|
public void RunTestCases(TestCase data)
|
|
{
|
|
var actual = data.Obj.ScaleToFitRatio(data.Bounds);
|
|
var expected = data.ExpectedResult;
|
|
Assert.AreEqual(expected, actual);
|
|
}
|
|
}
|
|
}
|