Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant ToQuantity methods #791

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/Humanizer.Tests.Shared/ToQuantityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ToQuantityTests
public void ToQuantity(string word, int quantity, string expected)
{
Assert.Equal(expected, word.ToQuantity(quantity));
Assert.Equal(expected, word.ToQuantity((long)quantity));
}

[Theory]
Expand All @@ -40,7 +39,6 @@ public void ToQuantity(string word, int quantity, string expected)
public void ToQuantityWithNoQuantity(string word, int quantity, string expected)
{
Assert.Equal(expected, word.ToQuantity(quantity, ShowQuantityAs.None));
Assert.Equal(expected, word.ToQuantity((long)quantity, ShowQuantityAs.None));
}

[Theory]
Expand All @@ -57,9 +55,7 @@ public void ToQuantityWithNoQuantity(string word, int quantity, string expected)
[InlineData("processes", 1, "1 process")]
public void ToQuantityNumeric(string word, int quantity, string expected)
{
// ReSharper disable once RedundantArgumentDefaultValue
Assert.Equal(expected, word.ToQuantity(quantity, ShowQuantityAs.Numeric));
Assert.Equal(expected, word.ToQuantity((long)quantity, ShowQuantityAs.Numeric));
}

[Theory]
Expand All @@ -78,7 +74,6 @@ public void ToQuantityNumeric(string word, int quantity, string expected)
public void ToQuantityWords(string word, int quantity, string expected)
{
Assert.Equal(expected, word.ToQuantity(quantity, ShowQuantityAs.Words));
Assert.Equal(expected, word.ToQuantity((long)quantity, ShowQuantityAs.Words));
}

[Theory]
Expand All @@ -96,7 +91,6 @@ public void ToQuantityWords(string word, int quantity, string expected)
public void ToQuantityWordsWithCurrentCultureFormatting(string word, int quantity, string format, string expected)
{
Assert.Equal(expected, word.ToQuantity(quantity, format));
Assert.Equal(expected, word.ToQuantity((long)quantity, format));
}

[Theory]
Expand All @@ -114,7 +108,6 @@ public void ToQuantityWordsWithCustomCultureFormatting(string word, int quantity
var culture = new CultureInfo(cultureCode);

Assert.Equal(expected, word.ToQuantity(quantity, format, culture), GetStringComparer(culture));
Assert.Equal(expected, word.ToQuantity((long)quantity, format, culture), GetStringComparer(culture));
}

internal static StringComparer GetStringComparer(CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,6 @@ namespace Humanizer
}
public class static ToQuantityExtensions
{
public static string ToQuantity(this string input, int quantity, Humanizer.ShowQuantityAs showQuantityAs = 1) { }
public static string ToQuantity(this string input, int quantity, string format, System.IFormatProvider formatProvider = null) { }
public static string ToQuantity(this string input, long quantity, Humanizer.ShowQuantityAs showQuantityAs = 1) { }
public static string ToQuantity(this string input, long quantity, string format, System.IFormatProvider formatProvider = null) { }
}
Expand Down
38 changes: 1 addition & 37 deletions src/Humanizer/ToQuantityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,7 @@ public enum ShowQuantityAs
/// </summary>
public static class ToQuantityExtensions
{
/// <summary>
/// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word
/// </summary>
/// <param name="input">The word to be prefixed</param>
/// <param name="quantity">The quantity of the word</param>
/// <param name="showQuantityAs">How to show the quantity. Numeric by default</param>
/// <example>
/// "request".ToQuantity(0) => "0 requests"
/// "request".ToQuantity(1) => "1 request"
/// "request".ToQuantity(2) => "2 requests"
/// "men".ToQuantity(2) => "2 men"
/// "process".ToQuantity(1200, ShowQuantityAs.Words) => "one thousand two hundred processes"
/// </example>
/// <returns></returns>
public static string ToQuantity(this string input, int quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric)
{
return input.ToQuantity(quantity, showQuantityAs, format: null, formatProvider: null);
}

/// <summary>
/// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word
/// </summary>
/// <param name="input">The word to be prefixed</param>
/// <param name="quantity">The quantity of the word</param>
/// <param name="format">A standard or custom numeric format string.</param>
/// <param name="formatProvider">An object that supplies culture-specific formatting information.</param>
/// <example>
/// "request".ToQuantity(0) => "0 requests"
/// "request".ToQuantity(10000, format: "N0") => "10,000 requests"
/// "request".ToQuantity(1, format: "N0") => "1 request"
/// </example>
/// <returns></returns>
public static string ToQuantity(this string input, int quantity, string format, IFormatProvider formatProvider = null)
{
return input.ToQuantity(quantity, showQuantityAs: ShowQuantityAs.Numeric, format: format, formatProvider: formatProvider);
}


/// <summary>
/// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word
/// </summary>
Expand Down