Skip to content

Commit 1d2645b

Browse files
lipchevangularsen
andauthored
Removed the obsolete methods (Min/Max) from UnitMath (#1601)
Removed the obsolete methods from `UnitMath`: - `Min(IEnumerable, TUnit)` - `Min(IEnumerable, Func)` - `Max(IEnumerable, TUnit)` - `Max(IEnumerable, Func)` Co-authored-by: Andreas Gullberg Larsen <andreas.larsen84@gmail.com>
1 parent 72c8e2a commit 1d2645b

File tree

2 files changed

+0
-182
lines changed

2 files changed

+0
-182
lines changed

UnitsNet.Tests/UnitMathTests.cs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -103,52 +103,6 @@ public void MaxOfTwoLengthsReturnsTheLargestValue()
103103
Assert.Equal(LengthUnit.Meter, max.Unit);
104104
}
105105

106-
[Fact]
107-
public void MaxOfEmptySourceThrowsException()
108-
{
109-
var units = new Length[] { };
110-
111-
Assert.Throws<InvalidOperationException>(() => units.Max(LengthUnit.Centimeter));
112-
}
113-
114-
[Fact]
115-
public void MaxOfLengthsCalculatesCorrectly()
116-
{
117-
var units = new[] {Length.FromMeters(1), Length.FromCentimeters(50)};
118-
119-
Length max = units.Max(LengthUnit.Centimeter);
120-
121-
Assert.Equal(100, max.Value);
122-
Assert.Equal(LengthUnit.Centimeter, max.Unit);
123-
}
124-
125-
[Fact]
126-
public void MaxOfLengthsWithNullSelectorThrowsException()
127-
{
128-
var units = new[]
129-
{
130-
new KeyValuePair<string, Length>("1", Length.FromMeters(1)),
131-
new KeyValuePair<string, Length>("2", Length.FromCentimeters(50))
132-
};
133-
134-
Assert.Throws<ArgumentNullException>(() => units.Max((Func<KeyValuePair<string, Length>, Length>) null!, LengthUnit.Centimeter));
135-
}
136-
137-
[Fact]
138-
public void MaxOfLengthsWithSelectorCalculatesCorrectly()
139-
{
140-
var units = new[]
141-
{
142-
new KeyValuePair<string, Length>("1", Length.FromMeters(1)),
143-
new KeyValuePair<string, Length>("2", Length.FromCentimeters(50))
144-
};
145-
146-
Length max = units.Max(x => x.Value, LengthUnit.Centimeter);
147-
148-
Assert.Equal(100, max.Value);
149-
Assert.Equal(LengthUnit.Centimeter, max.Unit);
150-
}
151-
152106
[Fact]
153107
public void MinOfTwoLengthsReturnsTheSmallestValue()
154108
{
@@ -161,52 +115,6 @@ public void MinOfTwoLengthsReturnsTheSmallestValue()
161115
Assert.Equal(LengthUnit.Centimeter, min.Unit);
162116
}
163117

164-
[Fact]
165-
public void MinOfEmptySourceThrowsException()
166-
{
167-
var units = new Length[] { };
168-
169-
Assert.Throws<InvalidOperationException>(() => units.Min(LengthUnit.Centimeter));
170-
}
171-
172-
[Fact]
173-
public void MinOfLengthsCalculatesCorrectly()
174-
{
175-
var units = new[] {Length.FromMeters(1), Length.FromCentimeters(50)};
176-
177-
Length min = units.Min(LengthUnit.Centimeter);
178-
179-
Assert.Equal(50, min.Value);
180-
Assert.Equal(LengthUnit.Centimeter, min.Unit);
181-
}
182-
183-
[Fact]
184-
public void MinOfLengthsWithNullSelectorThrowsException()
185-
{
186-
var units = new[]
187-
{
188-
new KeyValuePair<string, Length>("1", Length.FromMeters(1)),
189-
new KeyValuePair<string, Length>("2", Length.FromCentimeters(50))
190-
};
191-
192-
Assert.Throws<ArgumentNullException>(() => units.Min((Func<KeyValuePair<string, Length>, Length>) null!, LengthUnit.Centimeter));
193-
}
194-
195-
[Fact]
196-
public void MinOfLengthsWithSelectorCalculatesCorrectly()
197-
{
198-
var units = new[]
199-
{
200-
new KeyValuePair<string, Length>("1", Length.FromMeters(1)),
201-
new KeyValuePair<string, Length>("2", Length.FromCentimeters(50))
202-
};
203-
204-
Length min = units.Min(x => x.Value, LengthUnit.Centimeter);
205-
206-
Assert.Equal(50, min.Value);
207-
Assert.Equal(LengthUnit.Centimeter, min.Unit);
208-
}
209-
210118
[Fact]
211119
public void SumOfEmptySourceReturnsZero()
212120
{

UnitsNet/UnitMath.cs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -47,51 +47,6 @@ public static TQuantity Min<TQuantity>(TQuantity val1, TQuantity val2)
4747
return val1.CompareTo(val2) == 1 ? val2 : val1;
4848
}
4949

50-
/// <summary>Computes the min of a sequence of <typeparamref name="TQuantity" /> values.</summary>
51-
/// <param name="source">A sequence of <typeparamref name="TQuantity" /> values to calculate the min of.</param>
52-
/// <param name="unitType">The desired unit type for the resulting quantity</param>
53-
/// <returns>The min of the values in the sequence, represented in the specified unit type.</returns>
54-
/// <exception cref="T:System.ArgumentNullException">
55-
/// <paramref name="source">source</paramref> is null.
56-
/// </exception>
57-
/// <exception cref="T:System.InvalidOperationException"><paramref name="source">source</paramref> contains no elements.</exception>
58-
/// <exception cref="ArgumentException">
59-
/// <paramref name="source">source</paramref> contains quantity types different from <paramref name="unitType" />.
60-
/// </exception>
61-
[Obsolete("Duplicate of System.Linq.Min")]
62-
public static TQuantity Min<TQuantity, TUnitType>(this IEnumerable<TQuantity> source, TUnitType unitType)
63-
where TUnitType : struct, Enum
64-
where TQuantity : IQuantity<TUnitType>
65-
{
66-
return (TQuantity) Quantity.From(source.Min(x => x.As(unitType)), UnitKey.ForUnit(unitType));
67-
}
68-
69-
/// <summary>
70-
/// Computes the min of the sequence of <typeparamref name="TQuantity" /> values that are obtained by invoking a
71-
/// transform function on each element of the input sequence.
72-
/// </summary>
73-
/// <param name="source">A sequence of values that are used to calculate a min.</param>
74-
/// <param name="selector">A transform function to apply to each element.</param>
75-
/// <param name="unitType">The desired unit type for the resulting quantity</param>
76-
/// <typeparam name="TSource">The type of the elements of source.</typeparam>
77-
/// <typeparam name="TQuantity">The type of quantity that is produced by this operation.</typeparam>
78-
/// <typeparam name="TUnitType">The type of unit enum.</typeparam>
79-
/// <returns>The min of the projected values, represented in the specified unit type.</returns>
80-
/// <exception cref="T:System.ArgumentNullException">
81-
/// <paramref name="source">source</paramref> or <paramref name="selector">selector</paramref> is null.
82-
/// </exception>
83-
/// <exception cref="T:System.InvalidOperationException"><paramref name="source">source</paramref> contains no elements.</exception>
84-
/// <exception cref="ArgumentException">
85-
/// <paramref name="source">source</paramref> contains quantity types different from <paramref name="unitType" />.
86-
/// </exception>
87-
[Obsolete("Duplicate of System.Linq.Min")]
88-
public static TQuantity Min<TSource, TQuantity, TUnitType>(this IEnumerable<TSource> source, Func<TSource, TQuantity> selector, TUnitType unitType)
89-
where TQuantity : IQuantity<TUnitType>
90-
where TUnitType : struct, Enum
91-
{
92-
return source.Select(selector).Min(unitType);
93-
}
94-
9550
/// <summary>Returns the larger of two <typeparamref name="TQuantity" /> values.</summary>
9651
/// <typeparam name="TQuantity">The type of quantities to compare.</typeparam>
9752
/// <param name="val1">The first of two <typeparamref name="TQuantity" /> values to compare.</param>
@@ -102,51 +57,6 @@ public static TQuantity Max<TQuantity>(TQuantity val1, TQuantity val2)
10257
{
10358
return val1.CompareTo(val2) == -1 ? val2 : val1;
10459
}
105-
106-
/// <summary>Computes the max of a sequence of <typeparamref name="TQuantity" /> values.</summary>
107-
/// <param name="source">A sequence of <typeparamref name="TQuantity" /> values to calculate the max of.</param>
108-
/// <param name="unitType">The desired unit type for the resulting quantity</param>
109-
/// <returns>The max of the values in the sequence, represented in the specified unit type.</returns>
110-
/// <exception cref="T:System.ArgumentNullException">
111-
/// <paramref name="source">source</paramref> is null.
112-
/// </exception>
113-
/// <exception cref="T:System.InvalidOperationException"><paramref name="source">source</paramref> contains no elements.</exception>
114-
/// <exception cref="ArgumentException">
115-
/// <paramref name="source">source</paramref> contains quantity types different from <paramref name="unitType" />.
116-
/// </exception>
117-
[Obsolete("Duplicate of System.Linq.Max")]
118-
public static TQuantity Max<TQuantity, TUnitType>(this IEnumerable<TQuantity> source, TUnitType unitType)
119-
where TQuantity : IQuantity<TUnitType>
120-
where TUnitType : struct, Enum
121-
{
122-
return (TQuantity) Quantity.From(source.Max(x => x.As(unitType)), UnitKey.ForUnit(unitType));
123-
}
124-
125-
/// <summary>
126-
/// Computes the max of the sequence of <typeparamref name="TQuantity" /> values that are obtained by invoking a
127-
/// transform function on each element of the input sequence.
128-
/// </summary>
129-
/// <param name="source">A sequence of values that are used to calculate a max.</param>
130-
/// <param name="selector">A transform function to apply to each element.</param>
131-
/// <param name="unitType">The desired unit type for the resulting quantity</param>
132-
/// <typeparam name="TSource">The type of the elements of source.</typeparam>
133-
/// <typeparam name="TQuantity">The type of quantity that is produced by this operation.</typeparam>
134-
/// <typeparam name="TUnitType">The type of unit enum.</typeparam>
135-
/// <returns>The max of the projected values, represented in the specified unit type.</returns>
136-
/// <exception cref="T:System.ArgumentNullException">
137-
/// <paramref name="source">source</paramref> or <paramref name="selector">selector</paramref> is null.
138-
/// </exception>
139-
/// <exception cref="T:System.InvalidOperationException"><paramref name="source">source</paramref> contains no elements.</exception>
140-
/// <exception cref="ArgumentException">
141-
/// <paramref name="source">source</paramref> contains quantity types different from <paramref name="unitType" />.
142-
/// </exception>
143-
[Obsolete("Duplicate of System.Linq.Max")]
144-
public static TQuantity Max<TSource, TQuantity, TUnitType>(this IEnumerable<TSource> source, Func<TSource, TQuantity> selector, TUnitType unitType)
145-
where TQuantity : IQuantity<TUnitType>
146-
where TUnitType : struct, Enum
147-
{
148-
return source.Select(selector).Max(unitType);
149-
}
15060

15161
/// <summary>Returns <paramref name="value" /> clamped to the inclusive range of <paramref name="min" /> and <paramref name="max" />.</summary>
15262
/// <param name="value">The value to be clamped.</param>

0 commit comments

Comments
 (0)