|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Linq; |
4 | | -using System.Numerics; |
5 | | -using System.Threading.Tasks; |
6 | | -using BenchmarkDotNet.Attributes; |
| 1 | +using BenchmarkDotNet.Attributes; |
7 | 2 | using BenchmarkDotNet.Jobs; |
8 | 3 | using BenchmarkDotNet.Tests.XUnit; |
9 | 4 | using BenchmarkDotNet.Toolchains; |
10 | 5 | using BenchmarkDotNet.Toolchains.InProcess.Emit; |
| 6 | +using System; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.Linq; |
| 9 | +using System.Numerics; |
| 10 | +using System.Threading.Tasks; |
11 | 11 | using Xunit; |
12 | 12 | using Xunit.Abstractions; |
13 | 13 |
|
@@ -87,20 +87,85 @@ public IEnumerable<object[]> ArgumentsProvider() |
87 | 87 | public class WithArgumentsSourceInAnotherClass |
88 | 88 | { |
89 | 89 | [Benchmark] |
90 | | - [ArgumentsSource(typeof(ExternalClassWithArgumentsSource), nameof(ExternalClassWithArgumentsSource.ArgumentsProvider))] |
91 | | - public void Simple(bool boolean, int number) |
| 90 | + [ArgumentsSource(typeof(ExternalClassWithArgumentsSource), nameof(ExternalClassWithArgumentsSource.OnePrimitiveType))] |
| 91 | + public void OnePrimitiveType(int number) |
| 92 | + { |
| 93 | + if (number % 2 != 1) |
| 94 | + throw new InvalidOperationException("Incorrect values were passed"); |
| 95 | + } |
| 96 | + |
| 97 | + [Benchmark] |
| 98 | + [ArgumentsSource(typeof(ExternalClassWithArgumentsSource), nameof(ExternalClassWithArgumentsSource.TwoPrimitiveTypes))] |
| 99 | + public void TwoPrimitiveTypes(bool boolean, int number) |
92 | 100 | { |
93 | 101 | if (boolean && number != 1 || !boolean && number != 2) |
94 | 102 | throw new InvalidOperationException("Incorrect values were passed"); |
95 | 103 | } |
| 104 | + |
| 105 | + [Benchmark] |
| 106 | + [ArgumentsSource(typeof(ExternalClassWithArgumentsSource), nameof(ExternalClassWithArgumentsSource.OneNonPrimitiveType))] |
| 107 | + public void OneNonPrimitiveType(Version version) |
| 108 | + { |
| 109 | + int[] versionNumbers = { version.Major, version.Minor, version.MinorRevision, version.Build }; |
| 110 | + if (versionNumbers.Distinct().Count() != 4) |
| 111 | + throw new InvalidOperationException("Incorrect values were passed"); |
| 112 | + } |
| 113 | + |
| 114 | + [Benchmark] |
| 115 | + [ArgumentsSource(typeof(ExternalClassWithArgumentsSource), nameof(ExternalClassWithArgumentsSource.TwoNonPrimitiveTypes))] |
| 116 | + public void TwoNonPrimitiveTypes(Version version, DateTime dateTime) |
| 117 | + { |
| 118 | + int[] versionNumbers = { version.Major, version.Minor, version.MinorRevision, version.Build }; |
| 119 | + if (versionNumbers.Distinct().Count() != 4) |
| 120 | + throw new InvalidOperationException("Incorrect values were passed"); |
| 121 | + |
| 122 | + if (dateTime.Month != dateTime.Day) |
| 123 | + throw new InvalidOperationException("Incorrect values were passed"); |
| 124 | + } |
| 125 | + |
| 126 | + [Benchmark] |
| 127 | + [ArgumentsSource(typeof(ExternalClassWithArgumentsSource), nameof(ExternalClassWithArgumentsSource.OnePrimitiveAndOneNonPrimitive))] |
| 128 | + public void OnePrimitiveAndOneNonPrimitive(Version version, int number) |
| 129 | + { |
| 130 | + int[] versionNumbers = { version.Major, version.Minor, version.MinorRevision, version.Build }; |
| 131 | + if (versionNumbers.Distinct().Count() != 4) |
| 132 | + throw new InvalidOperationException("Incorrect values were passed"); |
| 133 | + |
| 134 | + if (number != version.Major) |
| 135 | + throw new InvalidOperationException("Incorrect values were passed"); |
| 136 | + } |
96 | 137 | } |
97 | 138 | public static class ExternalClassWithArgumentsSource |
98 | 139 | { |
99 | | - public static IEnumerable<object[]> ArgumentsProvider() |
| 140 | + public static IEnumerable<int> OnePrimitiveType() |
| 141 | + { |
| 142 | + yield return 3; |
| 143 | + yield return 5; |
| 144 | + } |
| 145 | + |
| 146 | + public static IEnumerable<object[]> TwoPrimitiveTypes() |
100 | 147 | { |
101 | 148 | yield return new object[] { true, 1 }; |
102 | 149 | yield return new object[] { false, 2 }; |
103 | 150 | } |
| 151 | + |
| 152 | + public static IEnumerable<Version> OneNonPrimitiveType() |
| 153 | + { |
| 154 | + yield return new Version(1, 2, 3, 4); |
| 155 | + yield return new Version(5, 6, 7, 8); |
| 156 | + } |
| 157 | + |
| 158 | + public static IEnumerable<object[]> TwoNonPrimitiveTypes() |
| 159 | + { |
| 160 | + yield return new object[] { new Version(1, 2, 3, 4), new DateTime(2011, 11, 11) }; |
| 161 | + yield return new object[] { new Version(5, 6, 7, 8), new DateTime(2002, 02, 02) }; |
| 162 | + } |
| 163 | + |
| 164 | + public static IEnumerable<object[]> OnePrimitiveAndOneNonPrimitive() |
| 165 | + { |
| 166 | + yield return new object[] { new Version(1, 2, 3, 4), 1 }; |
| 167 | + yield return new object[] { new Version(5, 6, 7, 8), 5 }; |
| 168 | + } |
104 | 169 | } |
105 | 170 |
|
106 | 171 | [Theory, MemberData(nameof(GetToolchains), DisableDiscoveryEnumeration = true)] |
@@ -775,34 +840,55 @@ public void MethodsAndPropertiesFromAnotherClassCanBeUsedAsSources(IToolchain to |
775 | 840 |
|
776 | 841 | public class ParamsSourcePointingToAnotherClass |
777 | 842 | { |
778 | | - [ParamsSource(typeof(ExternalClassWithParamsSource), nameof(ExternalClassWithParamsSource.Method))] |
| 843 | + [ParamsSource(typeof(ExternalClassWithParamsSource), nameof(ExternalClassWithParamsSource.PrimitiveTypeMethod))] |
779 | 844 | public int ParamOne { get; set; } |
780 | 845 |
|
781 | | - [ParamsSource(typeof(ExternalClassWithParamsSource), nameof(ExternalClassWithParamsSource.Property))] |
| 846 | + [ParamsSource(typeof(ExternalClassWithParamsSource), nameof(ExternalClassWithParamsSource.PrimitiveTypeProperty))] |
782 | 847 | public int ParamTwo { get; set; } |
783 | 848 |
|
| 849 | + [ParamsSource(typeof(ExternalClassWithParamsSource), nameof(ExternalClassWithParamsSource.NonPrimitiveTypeMethod))] |
| 850 | + public Version ParamThree { get; set; } |
| 851 | + |
| 852 | + [ParamsSource(typeof(ExternalClassWithParamsSource), nameof(ExternalClassWithParamsSource.NonPrimitiveTypeProperty))] |
| 853 | + public Version ParamFour { get; set; } |
| 854 | + |
784 | 855 | [Benchmark] |
785 | 856 | public void Test() |
786 | 857 | { |
787 | 858 | if (ParamOne != 123) |
788 | 859 | throw new ArgumentException("The ParamOne value is incorrect!"); |
789 | 860 | if (ParamTwo != 456) |
790 | 861 | throw new ArgumentException("The ParamTwo value is incorrect!"); |
| 862 | + if (ParamThree != new Version(1, 2, 3, 4)) |
| 863 | + throw new ArgumentException("The ParamThree value is incorrect!"); |
| 864 | + if (ParamFour != new Version(5, 6, 7, 8)) |
| 865 | + throw new ArgumentException("The ParamFour value is incorrect!"); |
791 | 866 | } |
792 | 867 | } |
793 | 868 | public static class ExternalClassWithParamsSource |
794 | 869 | { |
795 | | - public static IEnumerable<int> Method() |
| 870 | + public static IEnumerable<int> PrimitiveTypeMethod() |
796 | 871 | { |
797 | 872 | yield return 123; |
798 | 873 | } |
799 | | - public static IEnumerable<int> Property |
| 874 | + public static IEnumerable<int> PrimitiveTypeProperty |
800 | 875 | { |
801 | 876 | get |
802 | 877 | { |
803 | 878 | yield return 456; |
804 | 879 | } |
805 | 880 | } |
| 881 | + public static IEnumerable<Version> NonPrimitiveTypeMethod() |
| 882 | + { |
| 883 | + yield return new Version(1, 2, 3, 4); |
| 884 | + } |
| 885 | + public static IEnumerable<Version> NonPrimitiveTypeProperty |
| 886 | + { |
| 887 | + get |
| 888 | + { |
| 889 | + yield return new Version(5, 6, 7, 8); |
| 890 | + } |
| 891 | + } |
806 | 892 | } |
807 | 893 |
|
808 | 894 | [Theory, MemberData(nameof(GetToolchains), DisableDiscoveryEnumeration = true)] |
|
0 commit comments