namespace System.Drawing.Primitives.Tests
{
- public partial class ColorTests
+ public class ColorTests
{
public static bool SupportsReadingUpdatedSystemColors => PlatformDetection.IsWindows && !PlatformDetection.IsInAppContainer && PlatformDetection.IsNotWindowsNanoServer;
}
}
+ [Theory, MemberData(nameof(NamedArgbValues))]
+ public void FromKnownColor(string name, int alpha, int red, int green, int blue)
+ {
+ Color color = Color.FromKnownColor(Enum.Parse<KnownColor>(name));
+ Assert.Equal(alpha, color.A);
+ Assert.Equal(red, color.R);
+ Assert.Equal(green, color.G);
+ Assert.Equal(blue, color.B);
+ }
+
+ [Theory]
+ [InlineData((KnownColor)(-1))]
+ [InlineData((KnownColor)0)]
+ [InlineData(KnownColor.MenuHighlight + 1)]
+ public void FromOutOfRangeKnownColor(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Assert.Equal(0, color.A);
+ Assert.Equal(0, color.R);
+ Assert.Equal(0, color.G);
+ Assert.Equal(0, color.B);
+ }
+
+ [Theory, MemberData(nameof(AllKnownColors))]
+ public void ToKnownColor(KnownColor known) => Assert.Equal(known, Color.FromKnownColor(known).ToKnownColor());
+
+ [Theory, MemberData(nameof(AllKnownColors))]
+ public void ToKnownColorMatchesButIsNotKnown(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Color match = Color.FromArgb(color.A, color.R, color.G, color.B);
+ Assert.Equal((KnownColor)0, match.ToKnownColor());
+ }
+
+ [Theory]
+ [InlineData((KnownColor)(-1))]
+ [InlineData((KnownColor)0)]
+ [InlineData(KnownColor.MenuHighlight + 1)]
+ public void FromOutOfRangeKnownColorToKnownColor(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Assert.Equal((KnownColor)0, color.ToKnownColor());
+ }
+
+ [Fact]
+ public void IsSystemColor()
+ {
+ Assert.True(Color.FromName("ActiveBorder").IsSystemColor);
+ Assert.True(Color.FromName("WindowText").IsSystemColor);
+ Assert.False(Color.FromName("AliceBlue").IsSystemColor);
+ }
+
+ [Theory, MemberData(nameof(SystemColors))]
+ public void IsSystemColorTrue(KnownColor known) => Assert.True(Color.FromKnownColor(known).IsSystemColor);
+
+ [Theory, MemberData(nameof(NonSystemColors))]
+ public void IsSystemColorFalse(KnownColor known) => Assert.False(Color.FromKnownColor(known).IsSystemColor);
+
+ [Theory, MemberData(nameof(SystemColors))]
+ public void IsSystemColorFalseOnMatching(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Color match = Color.FromArgb(color.A, color.R, color.G, color.B);
+ Assert.False(match.IsSystemColor);
+ }
+
+ [Theory]
+ [InlineData((KnownColor)(-1))]
+ [InlineData((KnownColor)0)]
+ [InlineData(KnownColor.MenuHighlight + 1)]
+ public void IsSystemColorOutOfRangeKnown(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Assert.False(color.IsSystemColor);
+ }
+
+ [Theory, MemberData(nameof(AllKnownColors))]
+ public void IsKnownColorTrue(KnownColor known)
+ {
+ Assert.True(Color.FromKnownColor(known).IsKnownColor);
+ }
+
+ [Theory, MemberData(nameof(AllKnownColors))]
+ public void IsKnownColorMatchFalse(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Color match = Color.FromArgb(color.A, color.R, color.G, color.B);
+ Assert.False(match.IsKnownColor);
+ }
+
+ [Theory]
+ [InlineData((KnownColor)(-1))]
+ [InlineData((KnownColor)0)]
+ [InlineData(KnownColor.MenuHighlight + 1)]
+ public void IsKnownColorOutOfRangeKnown(KnownColor known)
+ {
+ Color color = Color.FromKnownColor(known);
+ Assert.False(color.IsKnownColor);
+ }
+
+ [Fact]
+ public void GetHashCodeForUnknownNamed()
+ {
+ // NetFX gives all such colors the same hash code. CoreFX makes more effort with them.
+ Color c1 = Color.FromName("SomeUnknownColorName");
+ Color c2 = Color.FromName("AnotherUnknownColorName");
+ Assert.NotEqual(c2.GetHashCode(), c1.GetHashCode());
+ Assert.Equal(c1.GetHashCode(), c1.GetHashCode());
+ }
+
+ public static readonly IEnumerable<object[]> AllKnownColors = Enum.GetValues(typeof(KnownColor)).Cast<KnownColor>()
+ .Where(kc => kc != 0)
+ .Select(kc => new object[] { kc })
+ .ToArray();
+
+ public static readonly IEnumerable<object[]> SystemColors =
+ new[]
+ {
+ KnownColor.ActiveBorder, KnownColor.ActiveCaption, KnownColor.ActiveCaptionText,
+ KnownColor.AppWorkspace, KnownColor.Control, KnownColor.ControlDark, KnownColor.ControlDarkDark,
+ KnownColor.ControlLight, KnownColor.ControlLightLight, KnownColor.ControlText, KnownColor.Desktop,
+ KnownColor.GrayText, KnownColor.Highlight, KnownColor.HighlightText, KnownColor.HotTrack,
+ KnownColor.InactiveBorder, KnownColor.InactiveCaption, KnownColor.InactiveCaptionText, KnownColor.Info,
+ KnownColor.InfoText, KnownColor.Menu, KnownColor.MenuText, KnownColor.ScrollBar, KnownColor.Window,
+ KnownColor.WindowFrame, KnownColor.WindowText, KnownColor.ButtonFace, KnownColor.ButtonHighlight,
+ KnownColor.ButtonShadow, KnownColor.GradientActiveCaption, KnownColor.GradientInactiveCaption,
+ KnownColor.MenuBar, KnownColor.MenuHighlight
+ }.Select(kc => new object[] { kc }).ToArray();
+
+ public static readonly IEnumerable<object[]> NonSystemColors =
+ new[]
+ {
+ KnownColor.Transparent, KnownColor.AliceBlue, KnownColor.AntiqueWhite, KnownColor.Aqua,
+ KnownColor.Aquamarine, KnownColor.Azure, KnownColor.Beige, KnownColor.Bisque, KnownColor.Black,
+ KnownColor.BlanchedAlmond, KnownColor.Blue, KnownColor.BlueViolet, KnownColor.Brown,
+ KnownColor.BurlyWood, KnownColor.CadetBlue, KnownColor.Chartreuse, KnownColor.Chocolate,
+ KnownColor.Coral, KnownColor.CornflowerBlue, KnownColor.Cornsilk, KnownColor.Crimson, KnownColor.Cyan,
+ KnownColor.DarkBlue, KnownColor.DarkCyan, KnownColor.DarkGoldenrod, KnownColor.DarkGray,
+ KnownColor.DarkGreen, KnownColor.DarkKhaki, KnownColor.DarkMagenta, KnownColor.DarkOliveGreen,
+ KnownColor.DarkOrange, KnownColor.DarkOrchid, KnownColor.DarkRed, KnownColor.DarkSalmon,
+ KnownColor.DarkSeaGreen, KnownColor.DarkSlateBlue, KnownColor.DarkSlateGray, KnownColor.DarkTurquoise,
+ KnownColor.DarkViolet, KnownColor.DeepPink, KnownColor.DeepSkyBlue, KnownColor.DimGray,
+ KnownColor.DodgerBlue, KnownColor.Firebrick, KnownColor.FloralWhite, KnownColor.ForestGreen,
+ KnownColor.Fuchsia, KnownColor.Gainsboro, KnownColor.GhostWhite, KnownColor.Gold, KnownColor.Goldenrod,
+ KnownColor.Gray, KnownColor.Green, KnownColor.GreenYellow, KnownColor.Honeydew, KnownColor.HotPink,
+ KnownColor.IndianRed, KnownColor.Indigo, KnownColor.Ivory, KnownColor.Khaki, KnownColor.Lavender,
+ KnownColor.LavenderBlush, KnownColor.LawnGreen, KnownColor.LemonChiffon, KnownColor.LightBlue,
+ KnownColor.LightCoral, KnownColor.LightCyan, KnownColor.LightGoldenrodYellow, KnownColor.LightGray,
+ KnownColor.LightGreen, KnownColor.LightPink, KnownColor.LightSalmon, KnownColor.LightSeaGreen,
+ KnownColor.LightSkyBlue, KnownColor.LightSlateGray, KnownColor.LightSteelBlue, KnownColor.LightYellow,
+ KnownColor.Lime, KnownColor.LimeGreen, KnownColor.Linen, KnownColor.Magenta, KnownColor.Maroon,
+ KnownColor.MediumAquamarine, KnownColor.MediumBlue, KnownColor.MediumOrchid, KnownColor.MediumPurple,
+ KnownColor.MediumSeaGreen, KnownColor.MediumSlateBlue, KnownColor.MediumSpringGreen,
+ KnownColor.MediumTurquoise, KnownColor.MediumVioletRed, KnownColor.MidnightBlue, KnownColor.MintCream,
+ KnownColor.MistyRose, KnownColor.Moccasin, KnownColor.NavajoWhite, KnownColor.Navy, KnownColor.OldLace,
+ KnownColor.Olive, KnownColor.OliveDrab, KnownColor.Orange, KnownColor.OrangeRed, KnownColor.Orchid,
+ KnownColor.PaleGoldenrod, KnownColor.PaleGreen, KnownColor.PaleTurquoise, KnownColor.PaleVioletRed,
+ KnownColor.PapayaWhip, KnownColor.PeachPuff, KnownColor.Peru, KnownColor.Pink, KnownColor.Plum,
+ KnownColor.PowderBlue, KnownColor.Purple, KnownColor.Red, KnownColor.RosyBrown, KnownColor.RoyalBlue,
+ KnownColor.SaddleBrown, KnownColor.Salmon, KnownColor.SandyBrown, KnownColor.SeaGreen,
+ KnownColor.SeaShell, KnownColor.Sienna, KnownColor.Silver, KnownColor.SkyBlue, KnownColor.SlateBlue,
+ KnownColor.SlateGray, KnownColor.Snow, KnownColor.SpringGreen, KnownColor.SteelBlue, KnownColor.Tan,
+ KnownColor.Teal, KnownColor.Thistle, KnownColor.Tomato, KnownColor.Turquoise, KnownColor.Violet,
+ KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen
+ }.Select(kc => new object[] { kc }).ToArray();
+
[DllImport("user32.dll", SetLastError = true)]
private static extern int SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues);
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using Xunit;
-
-namespace System.Drawing.Primitives.Tests
-{
- public partial class ColorTests
- {
- public static readonly IEnumerable<object[]> AllKnownColors = Enum.GetValues(typeof(KnownColor)).Cast<KnownColor>()
- .Where(kc => kc != 0)
- .Select(kc => new object[] { kc })
- .ToArray();
-
- public static readonly IEnumerable<object[]> SystemColors =
- new[]
- {
- KnownColor.ActiveBorder, KnownColor.ActiveCaption, KnownColor.ActiveCaptionText,
- KnownColor.AppWorkspace, KnownColor.Control, KnownColor.ControlDark, KnownColor.ControlDarkDark,
- KnownColor.ControlLight, KnownColor.ControlLightLight, KnownColor.ControlText, KnownColor.Desktop,
- KnownColor.GrayText, KnownColor.Highlight, KnownColor.HighlightText, KnownColor.HotTrack,
- KnownColor.InactiveBorder, KnownColor.InactiveCaption, KnownColor.InactiveCaptionText, KnownColor.Info,
- KnownColor.InfoText, KnownColor.Menu, KnownColor.MenuText, KnownColor.ScrollBar, KnownColor.Window,
- KnownColor.WindowFrame, KnownColor.WindowText, KnownColor.ButtonFace, KnownColor.ButtonHighlight,
- KnownColor.ButtonShadow, KnownColor.GradientActiveCaption, KnownColor.GradientInactiveCaption,
- KnownColor.MenuBar, KnownColor.MenuHighlight
- }.Select(kc => new object[] { kc }).ToArray();
-
- public static readonly IEnumerable<object[]> NonSystemColors =
- new[]
- {
- KnownColor.Transparent, KnownColor.AliceBlue, KnownColor.AntiqueWhite, KnownColor.Aqua,
- KnownColor.Aquamarine, KnownColor.Azure, KnownColor.Beige, KnownColor.Bisque, KnownColor.Black,
- KnownColor.BlanchedAlmond, KnownColor.Blue, KnownColor.BlueViolet, KnownColor.Brown,
- KnownColor.BurlyWood, KnownColor.CadetBlue, KnownColor.Chartreuse, KnownColor.Chocolate,
- KnownColor.Coral, KnownColor.CornflowerBlue, KnownColor.Cornsilk, KnownColor.Crimson, KnownColor.Cyan,
- KnownColor.DarkBlue, KnownColor.DarkCyan, KnownColor.DarkGoldenrod, KnownColor.DarkGray,
- KnownColor.DarkGreen, KnownColor.DarkKhaki, KnownColor.DarkMagenta, KnownColor.DarkOliveGreen,
- KnownColor.DarkOrange, KnownColor.DarkOrchid, KnownColor.DarkRed, KnownColor.DarkSalmon,
- KnownColor.DarkSeaGreen, KnownColor.DarkSlateBlue, KnownColor.DarkSlateGray, KnownColor.DarkTurquoise,
- KnownColor.DarkViolet, KnownColor.DeepPink, KnownColor.DeepSkyBlue, KnownColor.DimGray,
- KnownColor.DodgerBlue, KnownColor.Firebrick, KnownColor.FloralWhite, KnownColor.ForestGreen,
- KnownColor.Fuchsia, KnownColor.Gainsboro, KnownColor.GhostWhite, KnownColor.Gold, KnownColor.Goldenrod,
- KnownColor.Gray, KnownColor.Green, KnownColor.GreenYellow, KnownColor.Honeydew, KnownColor.HotPink,
- KnownColor.IndianRed, KnownColor.Indigo, KnownColor.Ivory, KnownColor.Khaki, KnownColor.Lavender,
- KnownColor.LavenderBlush, KnownColor.LawnGreen, KnownColor.LemonChiffon, KnownColor.LightBlue,
- KnownColor.LightCoral, KnownColor.LightCyan, KnownColor.LightGoldenrodYellow, KnownColor.LightGray,
- KnownColor.LightGreen, KnownColor.LightPink, KnownColor.LightSalmon, KnownColor.LightSeaGreen,
- KnownColor.LightSkyBlue, KnownColor.LightSlateGray, KnownColor.LightSteelBlue, KnownColor.LightYellow,
- KnownColor.Lime, KnownColor.LimeGreen, KnownColor.Linen, KnownColor.Magenta, KnownColor.Maroon,
- KnownColor.MediumAquamarine, KnownColor.MediumBlue, KnownColor.MediumOrchid, KnownColor.MediumPurple,
- KnownColor.MediumSeaGreen, KnownColor.MediumSlateBlue, KnownColor.MediumSpringGreen,
- KnownColor.MediumTurquoise, KnownColor.MediumVioletRed, KnownColor.MidnightBlue, KnownColor.MintCream,
- KnownColor.MistyRose, KnownColor.Moccasin, KnownColor.NavajoWhite, KnownColor.Navy, KnownColor.OldLace,
- KnownColor.Olive, KnownColor.OliveDrab, KnownColor.Orange, KnownColor.OrangeRed, KnownColor.Orchid,
- KnownColor.PaleGoldenrod, KnownColor.PaleGreen, KnownColor.PaleTurquoise, KnownColor.PaleVioletRed,
- KnownColor.PapayaWhip, KnownColor.PeachPuff, KnownColor.Peru, KnownColor.Pink, KnownColor.Plum,
- KnownColor.PowderBlue, KnownColor.Purple, KnownColor.Red, KnownColor.RosyBrown, KnownColor.RoyalBlue,
- KnownColor.SaddleBrown, KnownColor.Salmon, KnownColor.SandyBrown, KnownColor.SeaGreen,
- KnownColor.SeaShell, KnownColor.Sienna, KnownColor.Silver, KnownColor.SkyBlue, KnownColor.SlateBlue,
- KnownColor.SlateGray, KnownColor.Snow, KnownColor.SpringGreen, KnownColor.SteelBlue, KnownColor.Tan,
- KnownColor.Teal, KnownColor.Thistle, KnownColor.Tomato, KnownColor.Turquoise, KnownColor.Violet,
- KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen
- }.Select(kc => new object[] { kc }).ToArray();
-
- [Theory, MemberData(nameof(NamedArgbValues))]
- public void FromKnownColor(string name, int alpha, int red, int green, int blue)
- {
- Color color = Color.FromKnownColor(Enum.Parse<KnownColor>(name));
- Assert.Equal(alpha, color.A);
- Assert.Equal(red, color.R);
- Assert.Equal(green, color.G);
- Assert.Equal(blue, color.B);
- }
-
- [Theory]
- [InlineData((KnownColor)(-1))]
- [InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
- public void FromOutOfRangeKnownColor(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Assert.Equal(0, color.A);
- Assert.Equal(0, color.R);
- Assert.Equal(0, color.G);
- Assert.Equal(0, color.B);
- }
-
- [Theory, MemberData(nameof(AllKnownColors))]
- public void ToKnownColor(KnownColor known) => Assert.Equal(known, Color.FromKnownColor(known).ToKnownColor());
-
- [Theory, MemberData(nameof(AllKnownColors))]
- public void ToKnownColorMatchesButIsNotKnown(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Color match = Color.FromArgb(color.A, color.R, color.G, color.B);
- Assert.Equal((KnownColor)0, match.ToKnownColor());
- }
-
- [Theory]
- [InlineData((KnownColor)(-1))]
- [InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
- public void FromOutOfRangeKnownColorToKnownColor(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Assert.Equal((KnownColor)0, color.ToKnownColor());
- }
-
- [Fact]
- public void IsSystemColor()
- {
- Assert.True(Color.FromName("ActiveBorder").IsSystemColor);
- Assert.True(Color.FromName("WindowText").IsSystemColor);
- Assert.False(Color.FromName("AliceBlue").IsSystemColor);
- }
-
- [Theory, MemberData(nameof(SystemColors))]
- public void IsSystemColorTrue(KnownColor known) => Assert.True(Color.FromKnownColor(known).IsSystemColor);
-
- [Theory, MemberData(nameof(NonSystemColors))]
- public void IsSystemColorFalse(KnownColor known) => Assert.False(Color.FromKnownColor(known).IsSystemColor);
-
- [Theory, MemberData(nameof(SystemColors))]
- public void IsSystemColorFalseOnMatching(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Color match = Color.FromArgb(color.A, color.R, color.G, color.B);
- Assert.False(match.IsSystemColor);
- }
-
- [Theory]
- [InlineData((KnownColor)(-1))]
- [InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
- public void IsSystemColorOutOfRangeKnown(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Assert.False(color.IsSystemColor);
- }
-
- [Theory, MemberData(nameof(AllKnownColors))]
- public void IsKnownColorTrue(KnownColor known)
- {
- Assert.True(Color.FromKnownColor(known).IsKnownColor);
- }
-
- [Theory, MemberData(nameof(AllKnownColors))]
- public void IsKnownColorMatchFalse(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Color match = Color.FromArgb(color.A, color.R, color.G, color.B);
- Assert.False(match.IsKnownColor);
- }
-
- [Theory]
- [InlineData((KnownColor)(-1))]
- [InlineData((KnownColor)0)]
- [InlineData(KnownColor.MenuHighlight + 1)]
- public void IsKnownColorOutOfRangeKnown(KnownColor known)
- {
- Color color = Color.FromKnownColor(known);
- Assert.False(color.IsKnownColor);
- }
-
- [Fact]
- public void GetHashCodeForUnknownNamed()
- {
- // NetFX gives all such colors the same hash code. CoreFX makes more effort with them.
- Color c1 = Color.FromName("SomeUnknownColorName");
- Color c2 = Color.FromName("AnotherUnknownColorName");
- Assert.NotEqual(c2.GetHashCode(), c1.GetHashCode());
- Assert.Equal(c1.GetHashCode(), c1.GetHashCode());
- }
- }
-}
namespace System.Drawing.PrimitivesTest
{
- public partial class SizeFTests
+ public class SizeFTests
{
[Fact]
public void DefaultConstructorTest()
SizeF s = new SizeF(0, 0);
Assert.Equal(string.Format(CultureInfo.CurrentCulture, "{{Width={0}, Height={1}}}", s.Width, s.Height), s.ToString());
}
+
+ [Theory]
+ [InlineData(1000.234f, 0.0f)]
+ [InlineData(1000.234f, 1.0f)]
+ [InlineData(1000.234f, 2400.933f)]
+ [InlineData(1000.234f, float.MaxValue)]
+ [InlineData(1000.234f, -1.0f)]
+ [InlineData(1000.234f, -2400.933f)]
+ [InlineData(1000.234f, float.MinValue)]
+ [InlineData(float.MaxValue, 0.0f)]
+ [InlineData(float.MaxValue, 1.0f)]
+ [InlineData(float.MaxValue, 2400.933f)]
+ [InlineData(float.MaxValue, float.MaxValue)]
+ [InlineData(float.MaxValue, -1.0f)]
+ [InlineData(float.MaxValue, -2400.933f)]
+ [InlineData(float.MaxValue, float.MinValue)]
+ [InlineData(float.MinValue, 0.0f)]
+ [InlineData(float.MinValue, 1.0f)]
+ [InlineData(float.MinValue, 2400.933f)]
+ [InlineData(float.MinValue, float.MaxValue)]
+ [InlineData(float.MinValue, -1.0f)]
+ [InlineData(float.MinValue, -2400.933f)]
+ [InlineData(float.MinValue, float.MinValue)]
+ public void MultiplicationTest(float dimension, float multiplier)
+ {
+ SizeF sz1 = new SizeF(dimension, dimension);
+ SizeF mulExpected;
+
+ mulExpected = new SizeF(dimension * multiplier, dimension * multiplier);
+
+ Assert.Equal(mulExpected, sz1 * multiplier);
+ Assert.Equal(mulExpected, multiplier * sz1);
+ }
+
+ [Theory]
+ [InlineData(1111.1111f, 2222.2222f, 3333.3333f)]
+ public void MultiplicationTestWidthHeightMultiplier(float width, float height, float multiplier)
+ {
+ SizeF sz1 = new SizeF(width, height);
+ SizeF mulExpected;
+
+ mulExpected = new SizeF(width * multiplier, height * multiplier);
+
+ Assert.Equal(mulExpected, sz1 * multiplier);
+ Assert.Equal(mulExpected, multiplier * sz1);
+ }
+
+ [Theory]
+ [InlineData(0.0f, 1.0f)]
+ [InlineData(1.0f, 1.0f)]
+ [InlineData(-1.0f, 1.0f)]
+ [InlineData(1.0f, -1.0f)]
+ [InlineData(-1.0f, -1.0f)]
+ [InlineData(float.MaxValue, float.MaxValue)]
+ [InlineData(float.MaxValue, float.MinValue)]
+ [InlineData(float.MinValue, float.MaxValue)]
+ [InlineData(float.MinValue, float.MinValue)]
+ [InlineData(float.MaxValue, 1.0f)]
+ [InlineData(float.MinValue, 1.0f)]
+ [InlineData(float.MaxValue, -1.0f)]
+ [InlineData(float.MinValue, -1.0f)]
+ [InlineData(float.MinValue, 0.0f)]
+ [InlineData(1.0f, float.MinValue)]
+ [InlineData(1.0f, float.MaxValue)]
+ [InlineData(-1.0f, float.MinValue)]
+ [InlineData(-1.0f, float.MaxValue)]
+ public void DivideTestSizeFloat(float dimension, float divisor)
+ {
+ SizeF size = new SizeF(dimension, dimension);
+ SizeF expected = new SizeF(dimension / divisor, dimension / divisor);
+ Assert.Equal(expected, size / divisor);
+ }
+
+ [Theory]
+ [InlineData(-111.111f, 222.222f, 333.333f)]
+ public void DivideTestSizeFloatWidthHeightDivisor(float width, float height, float divisor)
+ {
+ SizeF size = new SizeF(width, height);
+ SizeF expected = new SizeF(width / divisor, height / divisor);
+ Assert.Equal(expected, size / divisor);
+ }
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Globalization;
-using Xunit;
-
-namespace System.Drawing.PrimitivesTest
-{
- public partial class SizeFTests
- {
- [Theory]
- [InlineData(1000.234f, 0.0f)]
- [InlineData(1000.234f, 1.0f)]
- [InlineData(1000.234f, 2400.933f)]
- [InlineData(1000.234f, float.MaxValue)]
- [InlineData(1000.234f, -1.0f)]
- [InlineData(1000.234f, -2400.933f)]
- [InlineData(1000.234f, float.MinValue)]
- [InlineData(float.MaxValue, 0.0f)]
- [InlineData(float.MaxValue, 1.0f)]
- [InlineData(float.MaxValue, 2400.933f)]
- [InlineData(float.MaxValue, float.MaxValue)]
- [InlineData(float.MaxValue, -1.0f)]
- [InlineData(float.MaxValue, -2400.933f)]
- [InlineData(float.MaxValue, float.MinValue)]
- [InlineData(float.MinValue, 0.0f)]
- [InlineData(float.MinValue, 1.0f)]
- [InlineData(float.MinValue, 2400.933f)]
- [InlineData(float.MinValue, float.MaxValue)]
- [InlineData(float.MinValue, -1.0f)]
- [InlineData(float.MinValue, -2400.933f)]
- [InlineData(float.MinValue, float.MinValue)]
- public void MultiplicationTest(float dimension, float multiplier)
- {
- SizeF sz1 = new SizeF(dimension, dimension);
- SizeF mulExpected;
-
- mulExpected = new SizeF(dimension * multiplier, dimension * multiplier);
-
- Assert.Equal(mulExpected, sz1 * multiplier);
- Assert.Equal(mulExpected, multiplier * sz1);
- }
-
- [Theory]
- [InlineData(1111.1111f, 2222.2222f, 3333.3333f)]
- public void MultiplicationTestWidthHeightMultiplier(float width, float height, float multiplier)
- {
- SizeF sz1 = new SizeF(width, height);
- SizeF mulExpected;
-
- mulExpected = new SizeF(width * multiplier, height * multiplier);
-
- Assert.Equal(mulExpected, sz1 * multiplier);
- Assert.Equal(mulExpected, multiplier * sz1);
- }
-
- [Theory]
- [InlineData(0.0f, 1.0f)]
- [InlineData(1.0f, 1.0f)]
- [InlineData(-1.0f, 1.0f)]
- [InlineData(1.0f, -1.0f)]
- [InlineData(-1.0f, -1.0f)]
- [InlineData(float.MaxValue, float.MaxValue)]
- [InlineData(float.MaxValue, float.MinValue)]
- [InlineData(float.MinValue, float.MaxValue)]
- [InlineData(float.MinValue, float.MinValue)]
- [InlineData(float.MaxValue, 1.0f)]
- [InlineData(float.MinValue, 1.0f)]
- [InlineData(float.MaxValue, -1.0f)]
- [InlineData(float.MinValue, -1.0f)]
- [InlineData(float.MinValue, 0.0f)]
- [InlineData(1.0f, float.MinValue)]
- [InlineData(1.0f, float.MaxValue)]
- [InlineData(-1.0f, float.MinValue)]
- [InlineData(-1.0f, float.MaxValue)]
- public void DivideTestSizeFloat(float dimension, float divisor)
- {
- SizeF size = new SizeF(dimension, dimension);
- SizeF expected = new SizeF(dimension / divisor, dimension / divisor);
- Assert.Equal(expected, size / divisor);
- }
-
- [Theory]
- [InlineData(-111.111f, 222.222f, 333.333f)]
- public void DivideTestSizeFloatWidthHeightDivisor(float width, float height, float divisor)
- {
- SizeF size = new SizeF(width, height);
- SizeF expected = new SizeF(width / divisor, height / divisor);
- Assert.Equal(expected, size / divisor);
- }
- }
-}
namespace System.Drawing.PrimitivesTests
{
- public partial class SizeTests
+ public class SizeTests
{
[Fact]
public void DefaultConstructorTest()
Size sz = new Size(0, 0);
Assert.Equal(string.Format(CultureInfo.CurrentCulture, "{{Width={0}, Height={1}}}", sz.Width, sz.Height), sz.ToString());
}
+
+ [Theory]
+ [InlineData(1000, 0)]
+ [InlineData(1000, 1)]
+ [InlineData(1000, 2400)]
+ [InlineData(1000, int.MaxValue)]
+ [InlineData(1000, -1)]
+ [InlineData(1000, -2400)]
+ [InlineData(1000, int.MinValue)]
+ [InlineData(int.MaxValue, 0)]
+ [InlineData(int.MaxValue, 1)]
+ [InlineData(int.MaxValue, 2400)]
+ [InlineData(int.MaxValue, int.MaxValue)]
+ [InlineData(int.MaxValue, -1)]
+ [InlineData(int.MaxValue, -2400)]
+ [InlineData(int.MaxValue, int.MinValue)]
+ [InlineData(int.MinValue, 0)]
+ [InlineData(int.MinValue, 1)]
+ [InlineData(int.MinValue, 2400)]
+ [InlineData(int.MinValue, int.MaxValue)]
+ [InlineData(int.MinValue, -1)]
+ [InlineData(int.MinValue, -2400)]
+ [InlineData(int.MinValue, int.MinValue)]
+ public void MultiplicationTestSizeInt(int dimension, int multiplier)
+ {
+ Size sz1 = new Size(dimension, dimension);
+ Size mulExpected;
+
+ unchecked
+ {
+ mulExpected = new Size(dimension * multiplier, dimension * multiplier);
+ }
+
+ Assert.Equal(mulExpected, sz1 * multiplier);
+ Assert.Equal(mulExpected, multiplier * sz1);
+ }
+
+ [Theory]
+ [InlineData(1000, 2000, 3000)]
+ public void MultiplicationTestSizeIntWidthHeightMultiplier(int width, int height, int multiplier)
+ {
+ Size sz1 = new Size(width, height);
+ Size mulExpected;
+
+ unchecked
+ {
+ mulExpected = new Size(width * multiplier, height * multiplier);
+ }
+
+ Assert.Equal(mulExpected, sz1 * multiplier);
+ Assert.Equal(mulExpected, multiplier * sz1);
+ }
+
+
+ [Theory]
+ [InlineData(1000, 0.0f)]
+ [InlineData(1000, 1.0f)]
+ [InlineData(1000, 2400.933f)]
+ [InlineData(1000, float.MaxValue)]
+ [InlineData(1000, -1.0f)]
+ [InlineData(1000, -2400.933f)]
+ [InlineData(1000, float.MinValue)]
+ [InlineData(int.MaxValue, 0.0f)]
+ [InlineData(int.MaxValue, 1.0f)]
+ [InlineData(int.MaxValue, 2400.933f)]
+ [InlineData(int.MaxValue, float.MaxValue)]
+ [InlineData(int.MaxValue, -1.0f)]
+ [InlineData(int.MaxValue, -2400.933f)]
+ [InlineData(int.MaxValue, float.MinValue)]
+ [InlineData(int.MinValue, 0.0f)]
+ [InlineData(int.MinValue, 1.0f)]
+ [InlineData(int.MinValue, 2400.933f)]
+ [InlineData(int.MinValue, float.MaxValue)]
+ [InlineData(int.MinValue, -1.0f)]
+ [InlineData(int.MinValue, -2400.933f)]
+ [InlineData(int.MinValue, float.MinValue)]
+ public void MultiplicationTestSizeFloat(int dimension, float multiplier)
+ {
+ Size sz1 = new Size(dimension, dimension);
+ SizeF mulExpected;
+
+ mulExpected = new SizeF(dimension * multiplier, dimension * multiplier);
+
+ Assert.Equal(mulExpected, sz1 * multiplier);
+ Assert.Equal(mulExpected, multiplier * sz1);
+ }
+
+ [Theory]
+ [InlineData(1000, 2000, 30.33f)]
+ public void MultiplicationTestSizeFloatWidthHeightMultiplier(int width, int height, float multiplier)
+ {
+ Size sz1 = new Size(width, height);
+ SizeF mulExpected;
+
+ mulExpected = new SizeF(width * multiplier, height * multiplier);
+
+ Assert.Equal(mulExpected, sz1 * multiplier);
+ Assert.Equal(mulExpected, multiplier * sz1);
+ }
+
+
+ [Fact]
+ public void DivideByZeroChecks()
+ {
+ Size size = new Size(100, 100);
+ Assert.Throws<DivideByZeroException>(() => size / 0);
+
+ SizeF expectedSizeF = new SizeF(float.PositiveInfinity, float.PositiveInfinity);
+ Assert.Equal(expectedSizeF, size / 0.0f);
+ }
+
+ [Theory]
+ [InlineData(0, 1)]
+ [InlineData(1, 1)]
+ [InlineData(-1, 1)]
+ [InlineData(1, -1)]
+ [InlineData(-1, -1)]
+ [InlineData(int.MaxValue, int.MaxValue)]
+ [InlineData(int.MaxValue, int.MinValue)]
+ [InlineData(int.MinValue, int.MaxValue)]
+ [InlineData(int.MinValue, int.MinValue)]
+ [InlineData(int.MaxValue, 1)]
+ [InlineData(int.MinValue, 1)]
+ [InlineData(int.MaxValue, -1)]
+ public void DivideTestSizeInt(int dimension, int divisor)
+ {
+ Size size = new Size(dimension, dimension);
+ Size expected;
+
+ expected = new Size(dimension / divisor, dimension / divisor);
+
+ Assert.Equal(expected, size / divisor);
+ }
+
+ [Theory]
+ [InlineData(1111, 2222, 3333)]
+ public void DivideTestSizeIntWidthHeightDivisor(int width, int height, int divisor)
+ {
+ Size size = new Size(width, height);
+ Size expected;
+
+ expected = new Size(width / divisor, height / divisor);
+
+ Assert.Equal(expected, size / divisor);
+ }
+
+ [Theory]
+ [InlineData(0, 1.0f)]
+ [InlineData(1, 1.0f)]
+ [InlineData(-1, 1.0f)]
+ [InlineData(1, -1.0f)]
+ [InlineData(-1, -1.0f)]
+ [InlineData(int.MaxValue, float.MaxValue)]
+ [InlineData(int.MaxValue, float.MinValue)]
+ [InlineData(int.MinValue, float.MaxValue)]
+ [InlineData(int.MinValue, float.MinValue)]
+ [InlineData(int.MaxValue, 1.0f)]
+ [InlineData(int.MinValue, 1.0f)]
+ [InlineData(int.MaxValue, -1.0f)]
+ [InlineData(int.MinValue, -1.0f)]
+ public void DivideTestSizeFloat(int dimension, float divisor)
+ {
+ SizeF size = new SizeF(dimension, dimension);
+ SizeF expected;
+
+ expected = new SizeF(dimension / divisor, dimension / divisor);
+ Assert.Equal(expected, size / divisor);
+ }
+
+ [Theory]
+ [InlineData(1111, 2222, -333.33f)]
+ public void DivideTestSizeFloatWidthHeightDivisor(int width, int height, float divisor)
+ {
+ SizeF size = new SizeF(width, height);
+ SizeF expected;
+
+ expected = new SizeF(width / divisor, height / divisor);
+ Assert.Equal(expected, size / divisor);
+ }
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Globalization;
-using Xunit;
-
-namespace System.Drawing.PrimitivesTests
-{
- public partial class SizeTests
- {
- [Theory]
- [InlineData(1000, 0)]
- [InlineData(1000, 1)]
- [InlineData(1000, 2400)]
- [InlineData(1000, int.MaxValue)]
- [InlineData(1000, -1)]
- [InlineData(1000, -2400)]
- [InlineData(1000, int.MinValue)]
- [InlineData(int.MaxValue, 0)]
- [InlineData(int.MaxValue, 1)]
- [InlineData(int.MaxValue, 2400)]
- [InlineData(int.MaxValue, int.MaxValue)]
- [InlineData(int.MaxValue, -1)]
- [InlineData(int.MaxValue, -2400)]
- [InlineData(int.MaxValue, int.MinValue)]
- [InlineData(int.MinValue, 0)]
- [InlineData(int.MinValue, 1)]
- [InlineData(int.MinValue, 2400)]
- [InlineData(int.MinValue, int.MaxValue)]
- [InlineData(int.MinValue, -1)]
- [InlineData(int.MinValue, -2400)]
- [InlineData(int.MinValue, int.MinValue)]
- public void MultiplicationTestSizeInt(int dimension, int multiplier)
- {
- Size sz1 = new Size(dimension, dimension);
- Size mulExpected;
-
- unchecked
- {
- mulExpected = new Size(dimension * multiplier, dimension * multiplier);
- }
-
- Assert.Equal(mulExpected, sz1 * multiplier);
- Assert.Equal(mulExpected, multiplier * sz1);
- }
-
- [Theory]
- [InlineData(1000, 2000, 3000)]
- public void MultiplicationTestSizeIntWidthHeightMultiplier(int width, int height, int multiplier)
- {
- Size sz1 = new Size(width, height);
- Size mulExpected;
-
- unchecked
- {
- mulExpected = new Size(width * multiplier, height * multiplier);
- }
-
- Assert.Equal(mulExpected, sz1 * multiplier);
- Assert.Equal(mulExpected, multiplier * sz1);
- }
-
-
- [Theory]
- [InlineData(1000, 0.0f)]
- [InlineData(1000, 1.0f)]
- [InlineData(1000, 2400.933f)]
- [InlineData(1000, float.MaxValue)]
- [InlineData(1000, -1.0f)]
- [InlineData(1000, -2400.933f)]
- [InlineData(1000, float.MinValue)]
- [InlineData(int.MaxValue, 0.0f)]
- [InlineData(int.MaxValue, 1.0f)]
- [InlineData(int.MaxValue, 2400.933f)]
- [InlineData(int.MaxValue, float.MaxValue)]
- [InlineData(int.MaxValue, -1.0f)]
- [InlineData(int.MaxValue, -2400.933f)]
- [InlineData(int.MaxValue, float.MinValue)]
- [InlineData(int.MinValue, 0.0f)]
- [InlineData(int.MinValue, 1.0f)]
- [InlineData(int.MinValue, 2400.933f)]
- [InlineData(int.MinValue, float.MaxValue)]
- [InlineData(int.MinValue, -1.0f)]
- [InlineData(int.MinValue, -2400.933f)]
- [InlineData(int.MinValue, float.MinValue)]
- public void MultiplicationTestSizeFloat(int dimension, float multiplier)
- {
- Size sz1 = new Size(dimension, dimension);
- SizeF mulExpected;
-
- mulExpected = new SizeF(dimension * multiplier, dimension * multiplier);
-
- Assert.Equal(mulExpected, sz1 * multiplier);
- Assert.Equal(mulExpected, multiplier * sz1);
- }
-
- [Theory]
- [InlineData(1000, 2000, 30.33f)]
- public void MultiplicationTestSizeFloatWidthHeightMultiplier(int width, int height, float multiplier)
- {
- Size sz1 = new Size(width, height);
- SizeF mulExpected;
-
- mulExpected = new SizeF(width * multiplier, height * multiplier);
-
- Assert.Equal(mulExpected, sz1 * multiplier);
- Assert.Equal(mulExpected, multiplier * sz1);
- }
-
-
- [Fact]
- public void DivideByZeroChecks()
- {
- Size size = new Size(100, 100);
- Assert.Throws<DivideByZeroException>(() => size / 0);
-
- SizeF expectedSizeF = new SizeF(float.PositiveInfinity, float.PositiveInfinity);
- Assert.Equal(expectedSizeF, size / 0.0f);
- }
-
- [Theory]
- [InlineData(0, 1)]
- [InlineData(1, 1)]
- [InlineData(-1, 1)]
- [InlineData(1, -1)]
- [InlineData(-1, -1)]
- [InlineData(int.MaxValue, int.MaxValue)]
- [InlineData(int.MaxValue, int.MinValue)]
- [InlineData(int.MinValue, int.MaxValue)]
- [InlineData(int.MinValue, int.MinValue)]
- [InlineData(int.MaxValue, 1)]
- [InlineData(int.MinValue, 1)]
- [InlineData(int.MaxValue, -1)]
- public void DivideTestSizeInt(int dimension, int divisor)
- {
- Size size = new Size(dimension, dimension);
- Size expected;
-
- expected = new Size(dimension / divisor, dimension / divisor);
-
- Assert.Equal(expected, size / divisor);
- }
-
- [Theory]
- [InlineData(1111, 2222, 3333)]
- public void DivideTestSizeIntWidthHeightDivisor(int width, int height, int divisor)
- {
- Size size = new Size(width, height);
- Size expected;
-
- expected = new Size(width / divisor, height / divisor);
-
- Assert.Equal(expected, size / divisor);
- }
-
- [Theory]
- [InlineData(0, 1.0f)]
- [InlineData(1, 1.0f)]
- [InlineData(-1, 1.0f)]
- [InlineData(1, -1.0f)]
- [InlineData(-1, -1.0f)]
- [InlineData(int.MaxValue, float.MaxValue)]
- [InlineData(int.MaxValue, float.MinValue)]
- [InlineData(int.MinValue, float.MaxValue)]
- [InlineData(int.MinValue, float.MinValue)]
- [InlineData(int.MaxValue, 1.0f)]
- [InlineData(int.MinValue, 1.0f)]
- [InlineData(int.MaxValue, -1.0f)]
- [InlineData(int.MinValue, -1.0f)]
- public void DivideTestSizeFloat(int dimension, float divisor)
- {
- SizeF size = new SizeF(dimension, dimension);
- SizeF expected;
-
- expected = new SizeF(dimension / divisor, dimension / divisor);
- Assert.Equal(expected, size / divisor);
- }
-
- [Theory]
- [InlineData(1111, 2222, -333.33f)]
- public void DivideTestSizeFloatWidthHeightDivisor(int width, int height, float divisor)
- {
- SizeF size = new SizeF(width, height);
- SizeF expected;
-
- expected = new SizeF(width / divisor, height / divisor);
- Assert.Equal(expected, size / divisor);
- }
- }
-}
\ No newline at end of file
<Link>Common\System\Runtime\Serialization\Utils.cs</Link>
</Compile>
</ItemGroup>
- <ItemGroup Condition="'$(TargetsNetCoreApp)' == 'true'">
- <Compile Include="SizeFTests.netcoreapp.cs" />
- <Compile Include="ColorTests.netcoreapp.cs" />
- <Compile Include="SizeTests.netcoreapp.cs" />
- </ItemGroup>
</Project>
<Compile Include="GregorianCalendar\GregorianCalendarToDateTime.cs" />
<Compile Include="GregorianCalendar\GregorianCalendarToFourDigitYear.cs" />
<Compile Include="GregorianCalendar\GregorianCalendarTwoDigitYearMax.cs" />
+ <Compile Include="ISOWeek\ISOWeekTests.cs" />
<Compile Include="JapaneseCalendar\JapaneseCalendarAddMonths.cs" />
<Compile Include="JapaneseCalendar\JapaneseCalendarToFourDigitYear.cs" />
<Compile Include="JapaneseCalendar\JapaneseCalendarTwoDigitYearMax.cs" />
<Compile Include="$(CommonTestPath)System\RandomDataGenerator.cs" />
<!-- Helpers -->
</ItemGroup>
- <ItemGroup Condition="'$(TargetsNetCoreApp)' == 'true'">
- <Compile Include="ISOWeek\ISOWeekTests.netcoreapp.cs" />
- </ItemGroup>
</Project>
\ No newline at end of file
<PropertyGroup>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
</PropertyGroup>
- <ItemGroup Condition="'$(TargetsNetCoreApp)' == 'true'">
- <Compile Include="AppendPrependTests.cs" />
- <Compile Include="TakeLastTests.cs" />
- <Compile Include="SkipLastTests.cs" />
- <Compile Include="ZipTests.netcoreapp.cs" />
- </ItemGroup>
<ItemGroup>
<Compile Include="AggregateTests.cs" />
<Compile Include="AllTests.cs" />
<Compile Include="AnyTests.cs" />
+ <Compile Include="AppendPrependTests.cs" />
<Compile Include="AverageTests.cs" />
<Compile Include="CastTests.cs" />
<Compile Include="ConcatTests.cs" />
<Compile Include="SequenceEqualTests.cs" />
<Compile Include="SingleOrDefaultTests.cs" />
<Compile Include="SingleTests.cs" />
+ <Compile Include="SkipLastTests.cs" />
<Compile Include="SkipTests.cs" />
<Compile Include="SkipWhileTests.cs" />
<Compile Include="SumTests.cs" />
+ <Compile Include="TakeLastTests.cs" />
<Compile Include="TakeTests.cs" />
<Compile Include="TakeWhileTests.cs" />
<Compile Include="ThenByDescendingTests.cs" />
namespace System.Linq.Tests
{
- public partial class ZipTests : EnumerableBasedTests
+ public class ZipTests : EnumerableBasedTests
{
[Fact]
public void CorrectResults()
var count = (new int[] { 0, 1, 2 }).AsQueryable().Zip((new int[] { 10, 11, 12 }).AsQueryable(), (n1, n2) => n1 + n2).Count();
Assert.Equal(3, count);
}
+
+ [Fact]
+ public void Zip2_CorrectResults()
+ {
+ int[] first = new int[] { 1, 2, 3 };
+ int[] second = new int[] { 2, 5, 9 };
+ var expected = new (int, int)[] { (1, 2), (2, 5), (3, 9) };
+ Assert.Equal(expected, first.AsQueryable().Zip(second.AsQueryable()));
+ }
+
+ [Fact]
+ public void Zip2_FirstIsNull()
+ {
+ IQueryable<int> first = null;
+ int[] second = new int[] { 2, 5, 9 };
+ AssertExtensions.Throws<ArgumentNullException>("source1", () => first.Zip(second.AsQueryable()));
+ }
+
+ [Fact]
+ public void Zip2_SecondIsNull()
+ {
+ int[] first = new int[] { 1, 2, 3 };
+ IQueryable<int> second = null;
+ AssertExtensions.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Zip(second));
+ }
+
+ [Fact]
+ public void Zip2()
+ {
+ int count = (new int[] { 0, 1, 2 }).AsQueryable().Zip((new int[] { 10, 11, 12 }).AsQueryable()).Count();
+ Assert.Equal(3, count);
+ }
+
+ [Fact]
+ public void TupleNames()
+ {
+ int[] first = new int[] { 1 };
+ int[] second = new int[] { 2 };
+ var tuple = first.AsQueryable().Zip(second.AsQueryable()).First();
+ Assert.Equal(tuple.Item1, tuple.First);
+ Assert.Equal(tuple.Item2, tuple.Second);
+ }
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using Xunit;
-
-namespace System.Linq.Tests
-{
- public partial class ZipTests
- {
- [Fact]
- public void Zip2_CorrectResults()
- {
- int[] first = new int[] { 1, 2, 3 };
- int[] second = new int[] { 2, 5, 9 };
- var expected = new (int, int)[] { (1, 2), (2, 5), (3, 9) };
- Assert.Equal(expected, first.AsQueryable().Zip(second.AsQueryable()));
- }
-
- [Fact]
- public void Zip2_FirstIsNull()
- {
- IQueryable<int> first = null;
- int[] second = new int[] { 2, 5, 9 };
- AssertExtensions.Throws<ArgumentNullException>("source1", () => first.Zip(second.AsQueryable()));
- }
-
- [Fact]
- public void Zip2_SecondIsNull()
- {
- int[] first = new int[] { 1, 2, 3 };
- IQueryable<int> second = null;
- AssertExtensions.Throws<ArgumentNullException>("source2", () => first.AsQueryable().Zip(second));
- }
-
- [Fact]
- public void Zip2()
- {
- int count = (new int[] { 0, 1, 2 }).AsQueryable().Zip((new int[] { 10, 11, 12 }).AsQueryable()).Count();
- Assert.Equal(3, count);
- }
-
- [Fact]
- public void TupleNames()
- {
- int[] first = new int[] { 1 };
- int[] second = new int[] { 2 };
- var tuple = first.AsQueryable().Zip(second.AsQueryable()).First();
- Assert.Equal(tuple.Item1, tuple.First);
- Assert.Equal(tuple.Item2, tuple.Second);
- }
- }
-}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Collections;
using System.Collections.Generic;
using Xunit;
namespace System.Linq.Tests
{
- public partial class SelectManyTests : EnumerableTests
+ public class SelectManyTests : EnumerableTests
{
[Fact]
public void EmptySource()
}
}
+ [Theory]
+ [InlineData(10)]
+ public void EvaluateSelectorOncePerItem(int count)
+ {
+ int[] timesCalledMap = new int[count];
+
+ IEnumerable<int> source = Enumerable.Range(0, 10);
+ IEnumerable<int> iterator = source.SelectMany(index =>
+ {
+ timesCalledMap[index]++;
+ return new[] { index };
+ });
+
+ // Iteration
+ foreach (int index in iterator)
+ {
+ Assert.Equal(Enumerable.Repeat(1, index + 1), timesCalledMap.Take(index + 1));
+ Assert.Equal(Enumerable.Repeat(0, timesCalledMap.Length - index - 1), timesCalledMap.Skip(index + 1));
+ }
+
+ Array.Clear(timesCalledMap, 0, timesCalledMap.Length);
+
+ // ToArray
+ iterator.ToArray();
+ Assert.Equal(Enumerable.Repeat(1, timesCalledMap.Length), timesCalledMap);
+
+ Array.Clear(timesCalledMap, 0, timesCalledMap.Length);
+
+ // ToList
+ iterator.ToList();
+ Assert.Equal(Enumerable.Repeat(1, timesCalledMap.Length), timesCalledMap);
+
+ Array.Clear(timesCalledMap, 0, timesCalledMap.Length);
+
+ // ToHashSet
+ iterator.ToHashSet();
+ Assert.Equal(Enumerable.Repeat(1, timesCalledMap.Length), timesCalledMap);
+ }
+
public static IEnumerable<object[]> GetToArrayDataSources()
{
// Marker at the end
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using Xunit;
-
-namespace System.Linq.Tests
-{
- public partial class SelectManyTests : EnumerableTests
- {
- [Theory]
- [InlineData(10)]
- public void EvaluateSelectorOncePerItem(int count)
- {
- int[] timesCalledMap = new int[count];
-
- IEnumerable<int> source = Enumerable.Range(0, 10);
- IEnumerable<int> iterator = source.SelectMany(index =>
- {
- timesCalledMap[index]++;
- return new[] { index };
- });
-
- // Iteration
- foreach (int index in iterator)
- {
- Assert.Equal(Enumerable.Repeat(1, index + 1), timesCalledMap.Take(index + 1));
- Assert.Equal(Enumerable.Repeat(0, timesCalledMap.Length - index - 1), timesCalledMap.Skip(index + 1));
- }
-
- Array.Clear(timesCalledMap, 0, timesCalledMap.Length);
-
- // ToArray
- iterator.ToArray();
- Assert.Equal(Enumerable.Repeat(1, timesCalledMap.Length), timesCalledMap);
-
- Array.Clear(timesCalledMap, 0, timesCalledMap.Length);
-
- // ToList
- iterator.ToList();
- Assert.Equal(Enumerable.Repeat(1, timesCalledMap.Length), timesCalledMap);
-
- Array.Clear(timesCalledMap, 0, timesCalledMap.Length);
-
- // ToHashSet
- iterator.ToHashSet();
- Assert.Equal(Enumerable.Repeat(1, timesCalledMap.Length), timesCalledMap);
- }
- }
-}
<Compile Include="RepeatTests.cs" />
<Compile Include="ReverseTests.cs" />
<Compile Include="SelectManyTests.cs" />
- <Compile Include="SelectManyTests.netcoreapp.cs" />
<Compile Include="SelectTests.cs" />
<Compile Include="SequenceEqualTests.cs" />
<Compile Include="ShortCircuitingTests.cs" />
<Compile Include="UnionTests.cs" />
<Compile Include="WhereTests.cs" />
<Compile Include="ZipTests.cs" />
- <Compile Include="ZipTests.netcoreapp.cs" />
<Compile Include="$(CommonTestPath)System\Linq\SkipTakeData.cs">
<Link>Common\System\Linq\SkipTakeData.cs</Link>
</Compile>
namespace System.Linq.Tests
{
- public partial class ZipTests : EnumerableTests
+ public class ZipTests : EnumerableTests
{
[Fact]
public void ImplicitTypeParameters()
Assert.Equal(expected, first.RunOnce().Zip(second.RunOnce(), func));
}
+
+ [Fact]
+ public void Zip2_ImplicitTypeParameters()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3 };
+ IEnumerable<int> second = new int[] { 2, 5, 9 };
+ IEnumerable<(int, int)> expected = new (int,int)[] { (1,2), (2,5), (3,9) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_ExplicitTypeParameters()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3 };
+ IEnumerable<int> second = new int[] { 2, 5, 9 };
+ IEnumerable<(int, int)> expected = new (int,int)[] { (1,2), (2,5), (3,9) };
+
+ Assert.Equal(expected, first.Zip<int, int>(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstIsNull()
+ {
+ IEnumerable<int> first = null;
+ IEnumerable<int> second = new int[] { 2, 5, 9 };
+
+ AssertExtensions.Throws<ArgumentNullException>("first", () => first.Zip<int, int>(second));
+ }
+
+ [Fact]
+ public void Zip2_SecondIsNull()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3 };
+ IEnumerable<int> second = null;
+
+ AssertExtensions.Throws<ArgumentNullException>("second", () => first.Zip<int, int>(second));
+ }
+
+ [Fact]
+ public void Zip2_ExceptionThrownFromFirstsEnumerator()
+ {
+ ThrowsOnMatchEnumerable<int> first = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 3, 3 }, 2);
+ IEnumerable<int> second = new int[] { 2, 4, 6 };
+ IEnumerable<(int, int)> expected = new (int,int)[] { (1,2), (3,4), (3,6) };
+
+ Assert.Equal(expected, first.Zip(second));
+
+ first = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 2, 3 }, 2);
+
+ IEnumerable<(int, int)> zip = first.Zip(second);
+
+ Assert.Throws<Exception>(() => zip.ToList());
+ }
+
+ [Fact]
+ public void Zip2_ExceptionThrownFromSecondsEnumerator()
+ {
+ ThrowsOnMatchEnumerable<int> second = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 3, 3 }, 2);
+ IEnumerable<int> first = new int[] { 2, 4, 6 };
+ IEnumerable<(int, int)> expected = new (int,int)[] { (2,1), (4,3), (6,3) };
+
+ Assert.Equal(expected, first.Zip(second));
+
+ second = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 2, 3 }, 2);
+
+ IEnumerable<(int, int)> zip = first.Zip(second);
+
+ Assert.Throws<Exception>(() => zip.ToList());
+ }
+
+ [Fact]
+ public void Zip2_FirstAndSecondEmpty()
+ {
+ IEnumerable<int> first = new int[] { };
+ IEnumerable<int> second = new int[] { };
+ IEnumerable<(int, int)> expected = new (int, int)[] { };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstEmptySecondSingle()
+ {
+ IEnumerable<int> first = new int[] { };
+ IEnumerable<int> second = new int[] { 2 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstEmptySecondMany()
+ {
+ IEnumerable<int> first = new int[] { };
+ IEnumerable<int> second = new int[] { 2, 4, 8 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_SecondEmptyFirstSingle()
+ {
+ IEnumerable<int> first = new int[] { 1 };
+ IEnumerable<int> second = new int[] { };
+ IEnumerable<(int, int)> expected = new (int, int)[] { };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_SecondEmptyFirstMany()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3 };
+ IEnumerable<int> second = new int[] { };
+ IEnumerable<(int, int)> expected = new (int, int)[] { };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstAndSecondSingle()
+ {
+ IEnumerable<int> first = new int[] { 1 };
+ IEnumerable<int> second = new int[] { 2 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstAndSecondEqualSize()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3 };
+ IEnumerable<int> second = new int[] { 2, 3, 4 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 3), (3, 4) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_SecondOneMoreThanFirst()
+ {
+ IEnumerable<int> first = new int[] { 1, 2 };
+ IEnumerable<int> second = new int[] { 2, 4, 8 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+
+ [Fact]
+ public void Zip2_SecondManyMoreThanFirst()
+ {
+ IEnumerable<int> first = new int[] { 1, 2 };
+ IEnumerable<int> second = new int[] { 2, 4, 8, 16 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstOneMoreThanSecond()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3 };
+ IEnumerable<int> second = new int[] { 2, 4 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_FirstManyMoreThanSecond()
+ {
+ IEnumerable<int> first = new int[] { 1, 2, 3, 4 };
+ IEnumerable<int> second = new int[] { 2, 4 };
+ IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
+
+ Assert.Equal(expected, first.Zip(second));
+ }
+
+ [Fact]
+ public void Zip2_RunOnce()
+ {
+ IEnumerable<int?> first = new[] { 1, (int?)null, 3 };
+ IEnumerable<int> second = new[] { 2, 4, 6, 8 };
+ IEnumerable<(int?, int)> expected = new (int?, int)[] { (1, 2), (null, 4), (3, 6) };
+
+ Assert.Equal(expected, first.RunOnce().Zip(second.RunOnce()));
+ }
+
+ [Fact]
+ public void Zip2_NestedTuple()
+ {
+ IEnumerable<int> first = new[] { 1, 3, 5 };
+ IEnumerable<int> second = new[] { 2, 4, 6 };
+ IEnumerable<(int, int)> third = new[] { (1, 2), (3, 4), (5, 6) };
+
+ Assert.Equal(third, first.Zip(second));
+
+ IEnumerable<string> fourth = new[] { "one", "two", "three" };
+
+ IEnumerable<((int, int), string)> final = new[] { ((1, 2), "one"), ((3, 4), "two"), ((5, 6), "three") };
+ Assert.Equal(final, third.Zip(fourth));
+ }
+
+ [Fact]
+ public void Zip2_TupleNames()
+ {
+ var t = new[] { 1, 2, 3 }.Zip(new[] { 2, 4, 6 }).First();
+ Assert.Equal(t.Item1, t.First);
+ Assert.Equal(t.Item2, t.Second);
+ }
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using Xunit;
-
-namespace System.Linq.Tests
-{
- public partial class ZipTests
- {
- [Fact]
- public void Zip2_ImplicitTypeParameters()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3 };
- IEnumerable<int> second = new int[] { 2, 5, 9 };
- IEnumerable<(int, int)> expected = new (int,int)[] { (1,2), (2,5), (3,9) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_ExplicitTypeParameters()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3 };
- IEnumerable<int> second = new int[] { 2, 5, 9 };
- IEnumerable<(int, int)> expected = new (int,int)[] { (1,2), (2,5), (3,9) };
-
- Assert.Equal(expected, first.Zip<int, int>(second));
- }
-
- [Fact]
- public void Zip2_FirstIsNull()
- {
- IEnumerable<int> first = null;
- IEnumerable<int> second = new int[] { 2, 5, 9 };
-
- AssertExtensions.Throws<ArgumentNullException>("first", () => first.Zip<int, int>(second));
- }
-
- [Fact]
- public void Zip2_SecondIsNull()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3 };
- IEnumerable<int> second = null;
-
- AssertExtensions.Throws<ArgumentNullException>("second", () => first.Zip<int, int>(second));
- }
-
- [Fact]
- public void Zip2_ExceptionThrownFromFirstsEnumerator()
- {
- ThrowsOnMatchEnumerable<int> first = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 3, 3 }, 2);
- IEnumerable<int> second = new int[] { 2, 4, 6 };
- IEnumerable<(int, int)> expected = new (int,int)[] { (1,2), (3,4), (3,6) };
-
- Assert.Equal(expected, first.Zip(second));
-
- first = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 2, 3 }, 2);
-
- IEnumerable<(int, int)> zip = first.Zip(second);
-
- Assert.Throws<Exception>(() => zip.ToList());
- }
-
- [Fact]
- public void Zip2_ExceptionThrownFromSecondsEnumerator()
- {
- ThrowsOnMatchEnumerable<int> second = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 3, 3 }, 2);
- IEnumerable<int> first = new int[] { 2, 4, 6 };
- IEnumerable<(int, int)> expected = new (int,int)[] { (2,1), (4,3), (6,3) };
-
- Assert.Equal(expected, first.Zip(second));
-
- second = new ThrowsOnMatchEnumerable<int>(new int[] { 1, 2, 3 }, 2);
-
- IEnumerable<(int, int)> zip = first.Zip(second);
-
- Assert.Throws<Exception>(() => zip.ToList());
- }
-
- [Fact]
- public void Zip2_FirstAndSecondEmpty()
- {
- IEnumerable<int> first = new int[] { };
- IEnumerable<int> second = new int[] { };
- IEnumerable<(int, int)> expected = new (int, int)[] { };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_FirstEmptySecondSingle()
- {
- IEnumerable<int> first = new int[] { };
- IEnumerable<int> second = new int[] { 2 };
- IEnumerable<(int, int)> expected = new (int, int)[] { };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_FirstEmptySecondMany()
- {
- IEnumerable<int> first = new int[] { };
- IEnumerable<int> second = new int[] { 2, 4, 8 };
- IEnumerable<(int, int)> expected = new (int, int)[] { };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_SecondEmptyFirstSingle()
- {
- IEnumerable<int> first = new int[] { 1 };
- IEnumerable<int> second = new int[] { };
- IEnumerable<(int, int)> expected = new (int, int)[] { };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_SecondEmptyFirstMany()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3 };
- IEnumerable<int> second = new int[] { };
- IEnumerable<(int, int)> expected = new (int, int)[] { };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_FirstAndSecondSingle()
- {
- IEnumerable<int> first = new int[] { 1 };
- IEnumerable<int> second = new int[] { 2 };
- IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_FirstAndSecondEqualSize()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3 };
- IEnumerable<int> second = new int[] { 2, 3, 4 };
- IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 3), (3, 4) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_SecondOneMoreThanFirst()
- {
- IEnumerable<int> first = new int[] { 1, 2 };
- IEnumerable<int> second = new int[] { 2, 4, 8 };
- IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
-
- [Fact]
- public void Zip2_SecondManyMoreThanFirst()
- {
- IEnumerable<int> first = new int[] { 1, 2 };
- IEnumerable<int> second = new int[] { 2, 4, 8, 16 };
- IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_FirstOneMoreThanSecond()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3 };
- IEnumerable<int> second = new int[] { 2, 4 };
- IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_FirstManyMoreThanSecond()
- {
- IEnumerable<int> first = new int[] { 1, 2, 3, 4 };
- IEnumerable<int> second = new int[] { 2, 4 };
- IEnumerable<(int, int)> expected = new (int, int)[] { (1, 2), (2, 4) };
-
- Assert.Equal(expected, first.Zip(second));
- }
-
- [Fact]
- public void Zip2_RunOnce()
- {
- IEnumerable<int?> first = new[] { 1, (int?)null, 3 };
- IEnumerable<int> second = new[] { 2, 4, 6, 8 };
- IEnumerable<(int?, int)> expected = new (int?, int)[] { (1, 2), (null, 4), (3, 6) };
-
- Assert.Equal(expected, first.RunOnce().Zip(second.RunOnce()));
- }
-
- [Fact]
- public void Zip2_NestedTuple()
- {
- IEnumerable<int> first = new[] { 1, 3, 5 };
- IEnumerable<int> second = new[] { 2, 4, 6 };
- IEnumerable<(int, int)> third = new[] { (1, 2), (3, 4), (5, 6) };
-
- Assert.Equal(third, first.Zip(second));
-
- IEnumerable<string> fourth = new[] { "one", "two", "three" };
-
- IEnumerable<((int, int), string)> final = new[] { ((1, 2), "one"), ((3, 4), "two"), ((5, 6), "three") };
- Assert.Equal(final, third.Zip(fourth));
- }
-
- [Fact]
- public void Zip2_TupleNames()
- {
- var t = new[] { 1, 2, 3 }.Zip(new[] { 2, 4, 6 }).First();
- Assert.Equal(t.Item1, t.First);
- Assert.Equal(t.Item2, t.Second);
- }
- }
-}
<Compile Include="MemoryMarshal\CreateSpan.cs" />
<Compile Include="MemoryMarshal\CreateReadOnlySpan.cs" />
<Compile Include="$(CommonPath)..\tests\System\RealFormatterTestsBase.netcoreapp.cs" Link="ParsersAndFormatters\Formatter\RealFormatterTestsBase.netcoreapp.cs" />
- <Compile Include="ParsersAndFormatters\Formatter\RealFormatterTests.netcoreapp.cs" />
+ <Compile Include="ParsersAndFormatters\Formatter\RealFormatterTests.cs" />
<Compile Include="$(CommonPath)..\tests\System\RealParserTestsBase.netcoreapp.cs" Link="ParsersAndFormatters\Parser\RealParserTestsBase.netcoreapp.cs" />
- <Compile Include="ParsersAndFormatters\Parser\RealParserTests.netcoreapp.cs" />
+ <Compile Include="ParsersAndFormatters\Parser\RealParserTests.cs" />
<Compile Include="ReadOnlySpan\Contains.byte.cs" />
<Compile Include="ReadOnlySpan\Contains.T.cs" />
<Compile Include="Span\Reflection.cs" />
namespace System.Collections.ObjectModel.Tests
{
- public abstract partial class KeyedCollectionTests<TKey, TValue>
+ public abstract class KeyedCollectionTests<TKey, TValue>
where TValue : IComparable<TValue> where TKey : IEquatable<TKey>
{
private static readonly bool s_keyNullable = default(TKey)
}
}
}
+
+ [Theory]
+ [MemberData(nameof(ContainsKeyData))]
+ public void TryGetValue(
+ int collectionSize,
+ Named<KeyedCollectionGetKeyedValue<TKey, TValue>>
+ generateKeyedItem)
+ {
+ TKey[] keys;
+ IKeyedItem<TKey, TValue>[] items;
+ IKeyedItem<TKey, TValue>[] itemsWithKeys;
+ var collection =
+ new TestKeyedCollectionOfIKeyedItem<TKey, TValue>();
+ collection.AddItems(
+ generateKeyedItem.Value.Bind(
+ GenerateValue,
+ GetKeyForItem),
+ ki => ki.Key,
+ collectionSize,
+ out keys,
+ out items,
+ out itemsWithKeys);
+ IKeyedItem<TKey, TValue> itemNotIn =
+ generateKeyedItem.Value(GenerateValue, GetKeyForItem);
+
+ TKey keyNotIn = itemNotIn.Key;
+ if (keyNotIn == null)
+ {
+ IKeyedItem<TKey, TValue> item;
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(keyNotIn, out item));
+ }
+ else
+ {
+ IKeyedItem<TKey, TValue> item;
+ Assert.False(collection.TryGetValue(keyNotIn, out item));
+ }
+ foreach (TKey k in keys)
+ {
+ IKeyedItem<TKey, TValue> item;
+ TKey key = k;
+ if (key == null)
+ {
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(key, out item));
+ continue;
+ }
+ Assert.True(collection.TryGetValue(key, out item));
+ Assert.Equal(item.Key, key);
+ }
+ }
}
public abstract class IListTestKeyedCollection<TKey, TValue> :
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Linq;
-using Tests.Collections;
-using Xunit;
-
-namespace System.Collections.ObjectModel.Tests
-{
- public abstract partial class KeyedCollectionTests<TKey, TValue>
- {
- [Theory]
- [MemberData(nameof(ContainsKeyData))]
- public void TryGetValue(
- int collectionSize,
- Named<KeyedCollectionGetKeyedValue<TKey, TValue>>
- generateKeyedItem)
- {
- TKey[] keys;
- IKeyedItem<TKey, TValue>[] items;
- IKeyedItem<TKey, TValue>[] itemsWithKeys;
- var collection =
- new TestKeyedCollectionOfIKeyedItem<TKey, TValue>();
- collection.AddItems(
- generateKeyedItem.Value.Bind(
- GenerateValue,
- GetKeyForItem),
- ki => ki.Key,
- collectionSize,
- out keys,
- out items,
- out itemsWithKeys);
- IKeyedItem<TKey, TValue> itemNotIn =
- generateKeyedItem.Value(GenerateValue, GetKeyForItem);
-
- TKey keyNotIn = itemNotIn.Key;
- if (keyNotIn == null)
- {
- IKeyedItem<TKey, TValue> item;
- AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(keyNotIn, out item));
- }
- else
- {
- IKeyedItem<TKey, TValue> item;
- Assert.False(collection.TryGetValue(keyNotIn, out item));
- }
- foreach (TKey k in keys)
- {
- IKeyedItem<TKey, TValue> item;
- TKey key = k;
- if (key == null)
- {
- AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(key, out item));
- continue;
- }
- Assert.True(collection.TryGetValue(key, out item));
- Assert.Equal(item.Key, key);
- }
- }
- }
-}
<Compile Include="System\ComponentModel\PropertyChangingEventArgsTests.cs" />
<Compile Include="System\ComponentModel\TypeConverterAttributeTests.cs" />
<Compile Include="System\ComponentModel\TypeDescriptionProviderAttributeTests.cs" />
+ <Compile Include="System\Windows\Markup\ValueSerializerAttributeTests.cs" />
<Compile Include="KeyedCollection\TestMethods.cs" />
<Compile Include="KeyedCollection\ConcreteTestClasses.cs" />
<Compile Include="KeyedCollection\Utils.cs" />
<Link>Common\System\Diagnostics\DebuggerAttributes.cs</Link>
</Compile>
</ItemGroup>
- <ItemGroup Condition="'$(TargetsNetCoreApp)' == 'true'">
- <Compile Include="KeyedCollection\TestMethods.netcoreapp.cs" />
- <Compile Include="System\Collections\ObjectModel\KeyedCollectionTests.netcoreapp.cs" />
- <Compile Include="System\Windows\Markup\ValueSerializerAttributeTests.cs" />
- </ItemGroup>
<ItemGroup>
<Compile Include="KeyedCollection\Serialization.cs" />
<Compile Include="ReadOnlyDictionary\ReadOnlyDictionary_SerializationTests.cs" />
namespace System.Collections.ObjectModel.Tests
{
- public partial class KeyedCollectionTests
+ public class KeyedCollectionTests
{
[Fact]
public void Ctor_Default()
AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.SetItem(index, "first"));
}
+ public static IEnumerable<object[]> TryGetValue_TestData()
+ {
+ yield return new object[] { null, "first_key", true, "first" };
+ yield return new object[] { null, "FIRST_KEY", false, null };
+ yield return new object[] { null, "NoSuchKey", false, null };
+ yield return new object[] { StringComparer.OrdinalIgnoreCase, "first_key", true, "first" };
+ yield return new object[] { StringComparer.OrdinalIgnoreCase, "FIRST_KEY", true, "first" };
+ yield return new object[] { StringComparer.OrdinalIgnoreCase, "NoSuchKey", false, null };
+ }
+
+ [Theory]
+ [MemberData(nameof(TryGetValue_TestData))]
+ public void TryGetValue_Invoke_ReturnsExpected(IEqualityComparer<string> comparer, string key, bool expected, string expectedItem)
+ {
+ var collection = new StringKeyedCollection<string>(comparer, 3);
+ collection.GetKeyForItemHandler = i => i + "_key";
+
+ // Without dictionary.
+ collection.InsertItem(0, "first");
+ Assert.Equal(expected, collection.TryGetValue(key, out string item));
+ Assert.Equal(expectedItem, item);
+
+ // With dictionary.
+ collection.InsertItem(0, "second");
+ collection.InsertItem(0, "third");
+ collection.InsertItem(0, "fourth");
+ Assert.Equal(expected, collection.TryGetValue(key, out item));
+ Assert.Equal(expectedItem, item);
+ }
+
+ [Theory]
+ [InlineData(3, true, 2)]
+ [InlineData(4, false, 0)]
+ public void TryGetValue_NullKeyForItemResult_Success(int dictionaryCreationThreshold, bool expected, int expectedItem)
+ {
+ var collection = new StringKeyedCollection<int>(null, dictionaryCreationThreshold);
+ collection.GetKeyForItemHandler = i => i.ToString();
+ collection.Add(1);
+ collection.Add(2);
+ collection.Add(3);
+ collection.Add(4);
+
+ // Don't get even numbers.
+ collection.GetKeyForItemHandler = i => i % 2 == 0 ? null : i.ToString();
+
+ // Get null key.
+ Assert.Equal(expected, collection.TryGetValue("2", out int item));
+ Assert.Equal(expectedItem, item);
+
+ // Get non null key.
+ Assert.True(collection.TryGetValue("1", out item));
+ Assert.Equal(1, item);
+ }
+
+ [Theory]
+ [InlineData(3, false, 0)]
+ [InlineData(4, true, 3)]
+ public void TryGetValue_DifferentKeyForItemResult_Success(int dictionaryCreationThreshold, bool expected, int expectedItem)
+ {
+ var collection = new StringKeyedCollection<int>(null, dictionaryCreationThreshold);
+ collection.GetKeyForItemHandler = i => i.ToString();
+ collection.Add(1);
+ collection.Add(2);
+ collection.Add(3);
+ collection.Add(4);
+
+ collection.GetKeyForItemHandler = i => (i * 2).ToString();
+
+ Assert.Equal(expected, collection.TryGetValue("6", out int item));
+ Assert.Equal(expectedItem, item);
+ }
+
+ [Fact]
+ public void TryGetValue_NullKey_ThrowsArgumentNullException()
+ {
+ var collection = new StringKeyedCollection<string>();
+ string item = "item";
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(null, out item));
+ Assert.Equal("item", item);
+ }
+
private class StringKeyedCollection<TItem> : KeyedCollection<string, TItem>
{
public StringKeyedCollection() : base()
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using Xunit;
-
-namespace System.Collections.ObjectModel.Tests
-{
- public partial class KeyedCollectionTests
- {
- public static IEnumerable<object[]> TryGetValue_TestData()
- {
- yield return new object[] { null, "first_key", true, "first" };
- yield return new object[] { null, "FIRST_KEY", false, null };
- yield return new object[] { null, "NoSuchKey", false, null };
- yield return new object[] { StringComparer.OrdinalIgnoreCase, "first_key", true, "first" };
- yield return new object[] { StringComparer.OrdinalIgnoreCase, "FIRST_KEY", true, "first" };
- yield return new object[] { StringComparer.OrdinalIgnoreCase, "NoSuchKey", false, null };
- }
-
- [Theory]
- [MemberData(nameof(TryGetValue_TestData))]
- public void TryGetValue_Invoke_ReturnsExpected(IEqualityComparer<string> comparer, string key, bool expected, string expectedItem)
- {
- var collection = new StringKeyedCollection<string>(comparer, 3);
- collection.GetKeyForItemHandler = i => i + "_key";
-
- // Without dictionary.
- collection.InsertItem(0, "first");
- Assert.Equal(expected, collection.TryGetValue(key, out string item));
- Assert.Equal(expectedItem, item);
-
- // With dictionary.
- collection.InsertItem(0, "second");
- collection.InsertItem(0, "third");
- collection.InsertItem(0, "fourth");
- Assert.Equal(expected, collection.TryGetValue(key, out item));
- Assert.Equal(expectedItem, item);
- }
-
- [Theory]
- [InlineData(3, true, 2)]
- [InlineData(4, false, 0)]
- public void TryGetValue_NullKeyForItemResult_Success(int dictionaryCreationThreshold, bool expected, int expectedItem)
- {
- var collection = new StringKeyedCollection<int>(null, dictionaryCreationThreshold);
- collection.GetKeyForItemHandler = i => i.ToString();
- collection.Add(1);
- collection.Add(2);
- collection.Add(3);
- collection.Add(4);
-
- // Don't get even numbers.
- collection.GetKeyForItemHandler = i => i % 2 == 0 ? null : i.ToString();
-
- // Get null key.
- Assert.Equal(expected, collection.TryGetValue("2", out int item));
- Assert.Equal(expectedItem, item);
-
- // Get non null key.
- Assert.True(collection.TryGetValue("1", out item));
- Assert.Equal(1, item);
- }
-
- [Theory]
- [InlineData(3, false, 0)]
- [InlineData(4, true, 3)]
- public void TryGetValue_DifferentKeyForItemResult_Success(int dictionaryCreationThreshold, bool expected, int expectedItem)
- {
- var collection = new StringKeyedCollection<int>(null, dictionaryCreationThreshold);
- collection.GetKeyForItemHandler = i => i.ToString();
- collection.Add(1);
- collection.Add(2);
- collection.Add(3);
- collection.Add(4);
-
- collection.GetKeyForItemHandler = i => (i * 2).ToString();
-
- Assert.Equal(expected, collection.TryGetValue("6", out int item));
- Assert.Equal(expectedItem, item);
- }
-
- [Fact]
- public void TryGetValue_NullKey_ThrowsArgumentNullException()
- {
- var collection = new StringKeyedCollection<string>();
- string item = "item";
- AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(null, out item));
- Assert.Equal("item", item);
- }
- }
-}