From 74ce45e53a71dc0d712a15b0406026c7de91c7ac Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Mon, 21 Dec 2015 14:26:10 +0000 Subject: [PATCH 1/8] Add support for long to ToQuantity --- src/Humanizer.Tests.Shared/ToQuantityTests.cs | 10 ++++ ...provalTest.approve_public_api.approved.txt | 2 + src/Humanizer/ToQuantityExtensions.cs | 48 ++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests.Shared/ToQuantityTests.cs b/src/Humanizer.Tests.Shared/ToQuantityTests.cs index a2c41e2b6..f03e17900 100644 --- a/src/Humanizer.Tests.Shared/ToQuantityTests.cs +++ b/src/Humanizer.Tests.Shared/ToQuantityTests.cs @@ -23,6 +23,7 @@ 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] @@ -40,6 +41,7 @@ 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] @@ -58,6 +60,7 @@ 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] @@ -76,6 +79,11 @@ 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)); + } + public void ToQuantityWordsThrowsErrorIfGreaterThanInt32() + { + Assert.Throws(() => "case".ToQuantity(10000000000, ShowQuantityAs.Words)); } [Theory] @@ -93,6 +101,7 @@ 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] @@ -110,6 +119,7 @@ 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) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index 00d6b39dc..3639156e7 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -961,6 +961,8 @@ namespace Humanizer { 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) { } } public class static TruncateExtensions { diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs index 574bce730..047a8e4ae 100644 --- a/src/Humanizer/ToQuantityExtensions.cs +++ b/src/Humanizer/ToQuantityExtensions.cs @@ -67,7 +67,44 @@ public static string ToQuantity(this string input, int quantity, string format, return input.ToQuantity(quantity, showQuantityAs: ShowQuantityAs.Numeric, format: format, formatProvider: formatProvider); } - private static string ToQuantity(this string input, int quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric, string format = null, IFormatProvider formatProvider = null) + /// + /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word + /// + /// The word to be prefixed + /// The quantity of the word + /// How to show the quantity. Numeric by default + /// + /// "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" + /// + /// + public static string ToQuantity(this string input, long quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric) + { + return input.ToQuantity(quantity, showQuantityAs, format: null, formatProvider: null); + } + + /// + /// Prefixes the provided word with the number and accordingly pluralizes or singularizes the word + /// + /// The word to be prefixed + /// The quantity of the word + /// A standard or custom numeric format string. + /// An object that supplies culture-specific formatting information. + /// + /// "request".ToQuantity(0) => "0 requests" + /// "request".ToQuantity(10000, format: "N0") => "10,000 requests" + /// "request".ToQuantity(1, format: "N0") => "1 request" + /// + /// + public static string ToQuantity(this string input, long quantity, string format, IFormatProvider formatProvider = null) + { + return input.ToQuantity(quantity, showQuantityAs: ShowQuantityAs.Numeric, format: format, formatProvider: formatProvider); + } + + private static string ToQuantity(this string input, long quantity, ShowQuantityAs showQuantityAs = ShowQuantityAs.Numeric, string format = null, IFormatProvider formatProvider = null) { var transformedInput = quantity == 1 ? input.Singularize(inputIsKnownToBePlural: false) @@ -79,7 +116,14 @@ private static string ToQuantity(this string input, int quantity, ShowQuantityAs if (showQuantityAs == ShowQuantityAs.Numeric) return string.Format(formatProvider, "{0} {1}", quantity.ToString(format, formatProvider), transformedInput); - return string.Format("{0} {1}", quantity.ToWords(), transformedInput); + try + { + return string.Format("{0} {1}", Convert.ToInt32(quantity).ToWords(), transformedInput); + } + catch (OverflowException e) + { + throw new NotImplementedException("ToQuantity words doesn't support long numbers", e); + } } } } From b244f6ba27803c45e520af48bc2cbad902598efe Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Wed, 13 Jan 2016 16:55:17 +0000 Subject: [PATCH 2/8] Update Number to words to take a long --- readme.md | 2 +- src/Humanizer.v2.ncrunchsolution | 13 +++++++++ .../AfrikaansNumberToWordsConverter.cs | 8 ++++-- .../ArabicNumberToWordsConverter.cs | 8 +++++- .../BanglaNumberToWordsConverter.cs | 11 ++++++-- ...azilianPortugueseNumberToWordsConverter.cs | 8 +++++- .../DefaultNumberToWordsConverter.cs | 2 +- .../DutchNumberToWordsConverter.cs | 11 ++++++-- .../EnglishNumberToWordsConverter.cs | 28 +++++++++++++++---- .../FarsiNumberToWordsConverter.cs | 8 +++++- .../FinnishNumberToWordsConverter.cs | 11 ++++++-- .../FrenchNumberToWordsConverter.cs | 8 +++++- .../GenderedNumberToWordsConverter.cs | 4 +-- .../GenderlessNumberToWordsConverter.cs | 4 +-- .../GermanNumberToWordsConverter.cs | 8 +++++- .../HebrewNumberToWordsConverter.cs | 8 +++++- .../NumberToWords/INumberToWordsConverter.cs | 6 ++-- .../ItalianNumberToWordsConverter.cs | 8 +++++- .../NorwegianBokmalNumberToWordsConverter.cs | 9 ++++-- .../PolishNumberToWordsConverter.cs | 10 +++++-- .../RomanianNumberToWordsConverter.cs | 8 ++++-- .../RussianNumberToWordsConverter.cs | 7 ++++- .../SerbianCyrlNumberToWordsConverter.cs | 8 +++++- .../SerbianNumberToWordsConverter.cs | 7 ++++- .../SlovenianNumberToWordsConverter.cs | 14 +++++++--- .../SpanishNumberToWordsConverter.cs | 7 ++++- .../TurkishNumberToWordConverter.cs | 7 ++++- .../UkrainianNumberToWordsConverter.cs | 7 ++++- .../UzbekCyrlNumberToWordConverter.cs | 7 ++++- .../UzbekLatnNumberToWordConverter.cs | 7 ++++- 30 files changed, 207 insertions(+), 47 deletions(-) create mode 100644 src/Humanizer.v2.ncrunchsolution diff --git a/readme.md b/readme.md index 71167a747..cc710ae2d 100644 --- a/readme.md +++ b/readme.md @@ -414,7 +414,7 @@ class SomeClass string FormatSomeClass(SomeClass sc) { - return string.Format("SomeObject #{0} - {1}", sc.SomeInt, sc.SomeString); + return string.Format("SomeObject #{0} - {1}", sc.SomeInt, sc.SomeString); } var collection = new List diff --git a/src/Humanizer.v2.ncrunchsolution b/src/Humanizer.v2.ncrunchsolution new file mode 100644 index 000000000..1f9dee104 --- /dev/null +++ b/src/Humanizer.v2.ncrunchsolution @@ -0,0 +1,13 @@ + + 1 + false + false + true + UseDynamicAnalysis + UseStaticAnalysis + UseStaticAnalysis + UseStaticAnalysis + UseStaticAnalysis + + + \ No newline at end of file diff --git a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs index 2f33eb6b5..6a6b855a7 100644 --- a/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/AfrikaansNumberToWordsConverter.cs @@ -22,9 +22,13 @@ internal class AfrikaansNumberToWordsConverter : GenderlessNumberToWordsConverte {19, "negentiende"} }; - public override string Convert(int number) + public override string Convert(long number) { - return Convert(number, false); + if(number > Int32.MaxValue|| number < Int32.MinValue) + { + throw new NotImplementedException(); + } + return Convert((int)number, false); } public override string ConvertToOrdinal(int number) diff --git a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs index edce9818a..6e42e5ede 100644 --- a/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ArabicNumberToWordsConverter.cs @@ -15,8 +15,14 @@ internal class ArabicNumberToWordsConverter : GenderlessNumberToWordsConverter private static readonly string[] AppendedTwos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونلن" }; private static readonly string[] Twos = { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان" }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return "صفر"; diff --git a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs index c5e58d11b..03d4cb67e 100644 --- a/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BanglaNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Humanizer.Localisation.NumberToWords { @@ -59,8 +60,14 @@ public override string ConvertToOrdinal(int number) return Convert(number) + " তম"; } - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return UnitsMap[0]; diff --git a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs index 8b646a44d..4c89f97ed 100644 --- a/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/BrazilianPortugueseNumberToWordsConverter.cs @@ -13,8 +13,14 @@ internal class BrazilianPortugueseNumberToWordsConverter : GenderedNumberToWords private static readonly string[] PortugueseOrdinalTensMap = { "zero", "décimo", "vigésimo", "trigésimo", "quadragésimo", "quinquagésimo", "sexagésimo", "septuagésimo", "octogésimo", "nonagésimo" }; private static readonly string[] PortugueseOrdinalHundredsMap = { "zero", "centésimo", "ducentésimo", "trecentésimo", "quadringentésimo", "quingentésimo", "sexcentésimo", "septingentésimo", "octingentésimo", "noningentésimo" }; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return "zero"; diff --git a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs index ece6e9b0c..9182194b7 100644 --- a/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs @@ -20,7 +20,7 @@ public DefaultNumberToWordsConverter(CultureInfo culture) /// /// Number to be turned to words /// - public override string Convert(int number) + public override string Convert(long number) { return number.ToString(_culture); } diff --git a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs index f071b1b05..bfc1978d8 100644 --- a/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/DutchNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; namespace Humanizer.Localisation.NumberToWords @@ -31,8 +32,14 @@ class Fact new Fact {Value = 100, Name = "honderd", Prefix = "", Postfix = "", DisplayOneUnit = false} }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return UnitsMap[0]; diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index 5a5daed00..ea0b117a9 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -8,7 +8,7 @@ internal class EnglishNumberToWordsConverter : GenderlessNumberToWordsConverter private static readonly string[] UnitsMap = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; private static readonly string[] TensMap = { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; - private static readonly Dictionary OrdinalExceptions = new Dictionary + private static readonly Dictionary OrdinalExceptions = new Dictionary { {1, "first"}, {2, "second"}, @@ -20,7 +20,7 @@ internal class EnglishNumberToWordsConverter : GenderlessNumberToWordsConverter {12, "twelfth"}, }; - public override string Convert(int number) + public override string Convert(long number) { return Convert(number, false); } @@ -30,7 +30,7 @@ public override string ConvertToOrdinal(int number) return Convert(number, true); } - private string Convert(int number, bool isOrdinal) + private string Convert(long number, bool isOrdinal) { if (number == 0) return GetUnitValue(0, isOrdinal); @@ -40,6 +40,24 @@ private string Convert(int number, bool isOrdinal) var parts = new List(); + if ((number / 1000000000000000000) > 0) + { + parts.Add(string.Format("{0} quadrillion", Convert(number / 1000000000000000000))); + number %= 1000000000000000000; + } + + if ((number / 1000000000000000) > 0) + { + parts.Add(string.Format("{0} trillion", Convert(number / 1000000000000000))); + number %= 1000000000000000; + } + + if ((number / 1000000000000) > 0) + { + parts.Add(string.Format("{0} trillion", Convert(number / 1000000000000))); + number %= 1000000000000; + } + if ((number / 1000000000) > 0) { parts.Add(string.Format("{0} billion", Convert(number / 1000000000))); @@ -93,7 +111,7 @@ private string Convert(int number, bool isOrdinal) return toWords; } - private static string GetUnitValue(int number, bool isOrdinal) + private static string GetUnitValue(long number, bool isOrdinal) { if (isOrdinal) { @@ -116,7 +134,7 @@ private static string RemoveOnePrefix(string toWords) return toWords; } - private static bool ExceptionNumbersToWords(int number, out string words) + private static bool ExceptionNumbersToWords(long number, out string words) { return OrdinalExceptions.TryGetValue(number, out words); } diff --git a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs index 66d6b3f70..8f75b6a8c 100644 --- a/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FarsiNumberToWordsConverter.cs @@ -9,8 +9,14 @@ internal class FarsiNumberToWordsConverter : GenderlessNumberToWordsConverter private static readonly string[] FarsiTensMap = { "صفر", "ده", "بیست", "سی", "چهل", "پنجاه", "شصت", "هفتاد", "هشتاد", "نود" }; private static readonly string[] FarsiUnitsMap = { "صفر", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه", "ده", "یازده", "دوازده", "سیزده", "چهارده", "پانزده", "شانزده", "هفده", "هجده", "نوزده" }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number < 0) return string.Format("منفی {0}", Convert(-number)); diff --git a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs index 39cc17f53..657f5fc7c 100644 --- a/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FinnishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Humanizer.Localisation.NumberToWords { @@ -13,8 +14,14 @@ internal class FinnishNumberToWordsConverter : GenderlessNumberToWordsConverter {2, "kahdes" } }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number < 0) return string.Format("miinus {0}", Convert(-number)); diff --git a/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverter.cs index a81c91cf3..729e0752e 100644 --- a/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverter.cs @@ -15,8 +15,14 @@ internal class FrenchNumberToWordsConverter : GenderedNumberToWordsConverter {91, "quatre-vingt-onze"} }; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return UnitsMap[0]; diff --git a/src/Humanizer/Localisation/NumberToWords/GenderedNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/GenderedNumberToWordsConverter.cs index 4af91b4f3..3bd5d274c 100644 --- a/src/Humanizer/Localisation/NumberToWords/GenderedNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/GenderedNumberToWordsConverter.cs @@ -14,7 +14,7 @@ protected GenderedNumberToWordsConverter(GrammaticalGender defaultGender = Gramm /// /// /// - public string Convert(int number) + public string Convert(long number) { return Convert(number, _defaultGender); } @@ -25,7 +25,7 @@ public string Convert(int number) /// /// /// - public abstract string Convert(int number, GrammaticalGender gender); + public abstract string Convert(long number, GrammaticalGender gender); /// /// Converts the number to ordinal string using the locale's default grammatical gender diff --git a/src/Humanizer/Localisation/NumberToWords/GenderlessNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/GenderlessNumberToWordsConverter.cs index fa89f250d..7e449e133 100644 --- a/src/Humanizer/Localisation/NumberToWords/GenderlessNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/GenderlessNumberToWordsConverter.cs @@ -7,7 +7,7 @@ abstract class GenderlessNumberToWordsConverter : INumberToWordsConverter /// /// /// - public abstract string Convert(int number); + public abstract string Convert(long number); /// /// Converts the number to string ignoring the provided grammatical gender @@ -15,7 +15,7 @@ abstract class GenderlessNumberToWordsConverter : INumberToWordsConverter /// /// /// - public string Convert(int number, GrammaticalGender gender) + public string Convert(long number, GrammaticalGender gender) { return Convert(number); } diff --git a/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverter.cs index b138bb2e4..9ca130a4e 100644 --- a/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/GermanNumberToWordsConverter.cs @@ -13,8 +13,14 @@ internal class GermanNumberToWordsConverter : GenderedNumberToWordsConverter private static readonly string[] BillionOrdinalSingular = {"einmilliard", "einemilliarde"}; private static readonly string[] BillionOrdinalPlural = {"{0}milliard", "{0}milliarden"}; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return "null"; diff --git a/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs index 1155f8d48..91fbcddda 100644 --- a/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/HebrewNumberToWordsConverter.cs @@ -38,8 +38,14 @@ public HebrewNumberToWordsConverter(CultureInfo culture) _culture = culture; } - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number < 0) return string.Format("מינוס {0}", Convert(-number, gender)); diff --git a/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs index 5a4f929be..ad27f99ed 100644 --- a/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs @@ -10,7 +10,7 @@ public interface INumberToWordsConverter /// /// /// - string Convert(int number); + string Convert(long number); /// /// Converts the number to string using the provided grammatical gender @@ -18,12 +18,12 @@ public interface INumberToWordsConverter /// /// /// - string Convert(int number, GrammaticalGender gender); + string Convert(long number, GrammaticalGender gender); /// /// Converts the number to ordinal string using the locale's default grammatical gender /// - /// + /// /// string ConvertToOrdinal(int number); diff --git a/src/Humanizer/Localisation/NumberToWords/ItalianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/ItalianNumberToWordsConverter.cs index 9ffdb5ef0..67a978e37 100644 --- a/src/Humanizer/Localisation/NumberToWords/ItalianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/ItalianNumberToWordsConverter.cs @@ -5,8 +5,14 @@ namespace Humanizer.Localisation.NumberToWords { internal class ItalianNumberToWordsConverter : GenderedNumberToWordsConverter { - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number < 0) return "meno " + Convert(Math.Abs(number), gender); diff --git a/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs index 63b8bbd96..2f807c9ce 100644 --- a/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/NorwegianBokmalNumberToWordsConverter.cs @@ -21,9 +21,14 @@ internal class NorwegianBokmalNumberToWordsConverter : GenderedNumberToWordsConv {12, "tolvte"} }; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long number, GrammaticalGender gender) { - return Convert(number, false, gender); + if (number > Int32.MaxValue || number < Int32.MinValue) + { + throw new NotImplementedException(); + } + + return Convert((int)number, false, gender); } public override string ConvertToOrdinal(int number, GrammaticalGender gender) diff --git a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs index 894a90852..afa5ce45d 100644 --- a/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/PolishNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Globalization; namespace Humanizer.Localisation.NumberToWords @@ -55,8 +56,13 @@ private static int GetMappingIndex(int number) return 2; //genitive } - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number == 0) return "zero"; diff --git a/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs index 122d6fb22..f6071cf96 100644 --- a/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs @@ -5,10 +5,14 @@ namespace Humanizer.Localisation.NumberToWords { internal class RomanianNumberToWordsConverter : GenderedNumberToWordsConverter { - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long number, GrammaticalGender gender) { + if (number > Int32.MaxValue || number < Int32.MinValue) + { + throw new NotImplementedException(); + } var converter = new RomanianCardinalNumberConverter(); - return converter.Convert(number, gender); + return converter.Convert((int)number, gender); } public override string ConvertToOrdinal(int number, GrammaticalGender gender) diff --git a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs index fe1f726bc..a446a0843 100644 --- a/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/RussianNumberToWordsConverter.cs @@ -14,8 +14,13 @@ internal class RussianNumberToWordsConverter : GenderedNumberToWordsConverter private static readonly string[] TensOrdinal = { string.Empty, "десят", "двадцат", "тридцат", "сороков", "пятидесят", "шестидесят", "семидесят", "восьмидесят", "девяност" }; private static readonly string[] UnitsOrdinal = { string.Empty, "перв", "втор", "трет", "четверт", "пят", "шест", "седьм", "восьм", "девят", "десят", "одиннадцат", "двенадцат", "тринадцат", "четырнадцат", "пятнадцат", "шестнадцат", "семнадцат", "восемнадцат", "девятнадцат" }; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number == 0) return "ноль"; diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs index 208a6e118..1691f690b 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianCyrlNumberToWordsConverter.cs @@ -18,8 +18,14 @@ public SerbianCyrlNumberToWordsConverter(CultureInfo culture) _culture = culture; } - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return "нула"; diff --git a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs index f3090416a..a3eabd47c 100644 --- a/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SerbianNumberToWordsConverter.cs @@ -18,8 +18,13 @@ public SerbianNumberToWordsConverter(CultureInfo culture) _culture = culture; } - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number == 0) return "nula"; diff --git a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs index eaa48ca2c..99f400761 100644 --- a/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SlovenianNumberToWordsConverter.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Globalization; namespace Humanizer.Localisation.NumberToWords @@ -15,9 +16,14 @@ public SlovenianNumberToWordsConverter(CultureInfo culture) _culture = culture; } - public override string Convert(int number) - { - if (number == 0) + public override string Convert(long input) + { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; + if (number == 0) return "nič"; if (number < 0) diff --git a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs index 97a308a5e..5cbdc7bd8 100644 --- a/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/SpanishNumberToWordsConverter.cs @@ -28,8 +28,13 @@ internal class SpanishNumberToWordsConverter : GenderedNumberToWordsConverter {10, "décimo"} }; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number == 0) return "cero"; diff --git a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs index 73a149a4c..bf80a1754 100644 --- a/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/TurkishNumberToWordConverter.cs @@ -22,8 +22,13 @@ internal class TurkishNumberToWordConverter : GenderlessNumberToWordsConverter {'a', "ıncı"}, }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number == 0) return UnitsMap[0]; diff --git a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs index 039e7597c..c05fe9407 100644 --- a/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UkrainianNumberToWordsConverter.cs @@ -14,8 +14,13 @@ internal class UkrainianNumberToWordsConverter : GenderedNumberToWordsConverter private static readonly string[] TensOrdinal = { string.Empty, "десят", "двадцят", "тридцят", "сороков", "п'ятдесят", "шістдесят", "сімдесят", "вісімдесят", "дев'яност" }; private static readonly string[] UnitsOrdinal = { "нульов", "перш", "друг", "трет", "четверт", "п'ят", "шост", "сьом", "восьм", "дев'ят", "десят", "одинадцят", "дванадцят", "тринадцят", "чотирнадцят", "п'ятнадцят", "шістнадцят", "сімнадцят", "вісімнадцят", "дев'ятнадцят" }; - public override string Convert(int number, GrammaticalGender gender) + public override string Convert(long input, GrammaticalGender gender) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number == 0) return "нуль"; diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs index 7558b2552..bb9374109 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekCyrlNumberToWordConverter.cs @@ -12,8 +12,13 @@ internal class UzbekCyrlNumberToWordConverter : GenderlessNumberToWordsConverter private static readonly string[] OrdinalSuffixes = new string[] { "инчи", "нчи" }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number < 0) return string.Format("минус {0}", Convert(-number, true)); return Convert(number, true); diff --git a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs index f7960005b..da54f2ffe 100644 --- a/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/UzbekLatnNumberToWordConverter.cs @@ -12,8 +12,13 @@ internal class UzbekLatnNumberToWordConverter : GenderlessNumberToWordsConverter private static readonly string[] OrdinalSuffixes = new string[] { "inchi", "nchi" }; - public override string Convert(int number) + public override string Convert(long input) { + if (input > Int32.MaxValue || input < Int32.MinValue) + { + throw new NotImplementedException(); + } + var number = (int)input; if (number < 0) return string.Format("minus {0}", Convert(-number, true)); return Convert(number, true); From bb74ce669791efaabb98ba6f52508f9b7369504f Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Wed, 13 Jan 2016 16:58:24 +0000 Subject: [PATCH 3/8] Add long.ToQuantity(ShowQuantityAs.Words) --- src/Humanizer/NumberToWordsExtension.cs | 4 ++-- src/Humanizer/ToQuantityExtensions.cs | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index afab61866..45d3136e6 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -14,7 +14,7 @@ public static class NumberToWordsExtension /// Number to be turned to words /// Culture to use. If null, current thread's UI culture is used. /// - public static string ToWords(this int number, CultureInfo culture = null) + public static string ToWords(this long number, CultureInfo culture = null) { return Configurator.GetNumberToWordsConverter(culture).Convert(number); } @@ -39,7 +39,7 @@ public static string ToWords(this int number, CultureInfo culture = null) /// The grammatical gender to use for output words /// Culture to use. If null, current thread's UI culture is used. /// - public static string ToWords(this int number, GrammaticalGender gender, CultureInfo culture = null) + public static string ToWords(this long number, GrammaticalGender gender, CultureInfo culture = null) { return Configurator.GetNumberToWordsConverter(culture).Convert(number, gender); } diff --git a/src/Humanizer/ToQuantityExtensions.cs b/src/Humanizer/ToQuantityExtensions.cs index 047a8e4ae..021a62e4a 100644 --- a/src/Humanizer/ToQuantityExtensions.cs +++ b/src/Humanizer/ToQuantityExtensions.cs @@ -116,14 +116,8 @@ private static string ToQuantity(this string input, long quantity, ShowQuantityA if (showQuantityAs == ShowQuantityAs.Numeric) return string.Format(formatProvider, "{0} {1}", quantity.ToString(format, formatProvider), transformedInput); - try - { - return string.Format("{0} {1}", Convert.ToInt32(quantity).ToWords(), transformedInput); - } - catch (OverflowException e) - { - throw new NotImplementedException("ToQuantity words doesn't support long numbers", e); - } + + return string.Format("{0} {1}", quantity.ToWords(), transformedInput); } } } From 94d6566c9aaeea1a020ff7780a42b92c31e9fa41 Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Wed, 13 Jan 2016 17:05:32 +0000 Subject: [PATCH 4/8] Add extra public method for int and long --- src/Humanizer/NumberToWordsExtension.cs | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Humanizer/NumberToWordsExtension.cs b/src/Humanizer/NumberToWordsExtension.cs index 45d3136e6..cfcb189fb 100644 --- a/src/Humanizer/NumberToWordsExtension.cs +++ b/src/Humanizer/NumberToWordsExtension.cs @@ -8,6 +8,42 @@ namespace Humanizer /// public static class NumberToWordsExtension { + /// + /// 3501.ToWords() -> "three thousand five hundred and one" + /// + /// Number to be turned to words + /// Culture to use. If null, current thread's UI culture is used. + /// + public static string ToWords(this int number, CultureInfo culture = null) + { + return ((long)number).ToWords(culture); + } + + /// + /// For locales that support gender-specific forms + /// + /// + /// Russian: + /// + /// 1.ToWords(GrammaticalGender.Masculine) -> "один" + /// 1.ToWords(GrammaticalGender.Feminine) -> "одна" + /// + /// Hebrew: + /// + /// 1.ToWords(GrammaticalGender.Masculine) -> "אחד" + /// 1.ToWords(GrammaticalGender.Feminine) -> "אחת" + /// + /// + /// + /// Number to be turned to words + /// The grammatical gender to use for output words + /// Culture to use. If null, current thread's UI culture is used. + /// + public static string ToWords(this int number, GrammaticalGender gender, CultureInfo culture = null) + { + return ((long)number).ToWords(gender, culture); + } + /// /// 3501.ToWords() -> "three thousand five hundred and one" /// From b78c07067be784fb8d63696537337446201650f9 Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Wed, 13 Jan 2016 17:22:21 +0000 Subject: [PATCH 5/8] Update public_api_approved.txt --- .../PublicApiApprovalTest.approve_public_api.approved.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt index 3639156e7..a547760f3 100644 --- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt +++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt @@ -463,6 +463,8 @@ namespace Humanizer public static string ToOrdinalWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } public static string ToWords(this int number, System.Globalization.CultureInfo culture = null) { } public static string ToWords(this int number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } + public static string ToWords(this long number, System.Globalization.CultureInfo culture = null) { } + public static string ToWords(this long number, Humanizer.GrammaticalGender gender, System.Globalization.CultureInfo culture = null) { } } public class On { @@ -1101,8 +1103,8 @@ namespace Humanizer.Localisation.NumberToWords public interface INumberToWordsConverter { - string Convert(int number); - string Convert(int number, Humanizer.GrammaticalGender gender); + string Convert(long number); + string Convert(long number, Humanizer.GrammaticalGender gender); string ConvertToOrdinal(int number); string ConvertToOrdinal(int number, Humanizer.GrammaticalGender gender); } From a8441b1c7ec740201b43a7a4804d504b87852c16 Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Wed, 13 Jan 2016 17:42:50 +0000 Subject: [PATCH 6/8] Add tests for long.ToWords() and update XML comment --- .../NumberToWordsTests.cs | 26 +++++++++++++++++++ .../NumberToWords/INumberToWordsConverter.cs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Humanizer.Tests.Shared/NumberToWordsTests.cs b/src/Humanizer.Tests.Shared/NumberToWordsTests.cs index 999d1a036..9ce84c7a5 100644 --- a/src/Humanizer.Tests.Shared/NumberToWordsTests.cs +++ b/src/Humanizer.Tests.Shared/NumberToWordsTests.cs @@ -40,6 +40,32 @@ public void ToWords(int number, string expected) Assert.Equal(expected, number.ToWords()); } + [InlineData(1L, "one")] + [InlineData(11L, "eleven")] + [InlineData(111L, "one hundred and eleven")] + [InlineData(1111L, "one thousand one hundred and eleven")] + [InlineData(11111L, "eleven thousand one hundred and eleven")] + [InlineData(111111L, "one hundred and eleven thousand one hundred and eleven")] + [InlineData(1111111L, "one million one hundred and eleven thousand one hundred and eleven")] + [InlineData(11111111L, "eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(111111111L, "one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(1111111111L, "one billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(11111111111L, "eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(111111111111L, "one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(1111111111111L, "one trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(11111111111111L, "eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(111111111111111L, "one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(1111111111111111L, "one quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(11111111111111111L, "eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(111111111111111111L, "one hundred and eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(1111111111111111111L, "one quintillion one hundred and eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [InlineData(11111111111111111111L, "eleven quintillion one hundred and eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] + [Theory] + public void ToWords(long number, string expected) + { + Assert.Equal(expected, number.ToWords()); + } + [Theory] [InlineData(0, "zeroth")] [InlineData(1, "first")] diff --git a/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs index ad27f99ed..151770be1 100644 --- a/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs @@ -23,7 +23,7 @@ public interface INumberToWordsConverter /// /// Converts the number to ordinal string using the locale's default grammatical gender /// - /// + /// /// string ConvertToOrdinal(int number); From 6098bf595aa75a9b4328f4115375984da5bd24bb Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Thu, 14 Jan 2016 11:19:10 +0000 Subject: [PATCH 7/8] Removing out of range test, correcting names of large numbers --- src/Humanizer.Tests.Shared/NumberToWordsTests.cs | 1 - src/Humanizer.Tests.Shared/ToQuantityTests.cs | 4 ---- .../NumberToWords/EnglishNumberToWordsConverter.cs | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Humanizer.Tests.Shared/NumberToWordsTests.cs b/src/Humanizer.Tests.Shared/NumberToWordsTests.cs index 9ce84c7a5..5d5150614 100644 --- a/src/Humanizer.Tests.Shared/NumberToWordsTests.cs +++ b/src/Humanizer.Tests.Shared/NumberToWordsTests.cs @@ -59,7 +59,6 @@ public void ToWords(int number, string expected) [InlineData(11111111111111111L, "eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] [InlineData(111111111111111111L, "one hundred and eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] [InlineData(1111111111111111111L, "one quintillion one hundred and eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] - [InlineData(11111111111111111111L, "eleven quintillion one hundred and eleven quadrillion one hundred and eleven trillion one hundred and eleven billion one hundred and eleven million one hundred and eleven thousand one hundred and eleven")] [Theory] public void ToWords(long number, string expected) { diff --git a/src/Humanizer.Tests.Shared/ToQuantityTests.cs b/src/Humanizer.Tests.Shared/ToQuantityTests.cs index f03e17900..a85c2909d 100644 --- a/src/Humanizer.Tests.Shared/ToQuantityTests.cs +++ b/src/Humanizer.Tests.Shared/ToQuantityTests.cs @@ -81,10 +81,6 @@ 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)); } - public void ToQuantityWordsThrowsErrorIfGreaterThanInt32() - { - Assert.Throws(() => "case".ToQuantity(10000000000, ShowQuantityAs.Words)); - } [Theory] [InlineData("case", 0, null, "0 cases")] diff --git a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs index ea0b117a9..9ef477c2e 100644 --- a/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs +++ b/src/Humanizer/Localisation/NumberToWords/EnglishNumberToWordsConverter.cs @@ -42,13 +42,13 @@ private string Convert(long number, bool isOrdinal) if ((number / 1000000000000000000) > 0) { - parts.Add(string.Format("{0} quadrillion", Convert(number / 1000000000000000000))); + parts.Add(string.Format("{0} quintillion", Convert(number / 1000000000000000000))); number %= 1000000000000000000; } if ((number / 1000000000000000) > 0) { - parts.Add(string.Format("{0} trillion", Convert(number / 1000000000000000))); + parts.Add(string.Format("{0} quadrillion", Convert(number / 1000000000000000))); number %= 1000000000000000; } From 34d751f5fabe73066b1487570546dd5c312b5bd2 Mon Sep 17 00:00:00 2001 From: Robert Pethick Date: Mon, 18 Jan 2016 10:53:52 +0000 Subject: [PATCH 8/8] removing ncrunch config file --- src/Humanizer.v2.ncrunchsolution | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/Humanizer.v2.ncrunchsolution diff --git a/src/Humanizer.v2.ncrunchsolution b/src/Humanizer.v2.ncrunchsolution deleted file mode 100644 index 1f9dee104..000000000 --- a/src/Humanizer.v2.ncrunchsolution +++ /dev/null @@ -1,13 +0,0 @@ - - 1 - false - false - true - UseDynamicAnalysis - UseStaticAnalysis - UseStaticAnalysis - UseStaticAnalysis - UseStaticAnalysis - - - \ No newline at end of file