public void Test_For_Positive_Value() { string Expected = "thirteen thousand four hundred and fifty six"; var result = NumberSpelling.ToSpell(13456); Assert.AreEqual(Expected, result); }
public void AssertNumberSpelling(NumberSpelling numberSpelling, string correctNumber, string correctUnit, Case @case) { string unit = "рубль"; string spellNumber = numberSpelling.Spell(n, ref unit, @case); Assert.AreEqual(correctNumber, spellNumber); Assert.AreEqual(correctUnit, unit); }
public HttpResponseMessage Spell(decimal n, string unit, ResponseFormat?format = null) { if (string.IsNullOrWhiteSpace(unit)) { throw new RequiredParameterIsNotSpecifiedException(nameof(unit)); } NumberSpelling numberSpelling = _analyzer.Spell(n, unit); return(Request.CreateResponse(HttpStatusCode.OK, numberSpelling, format)); }
public NumberSpelling Spell(decimal n, string unit) { try { var result = _client.Spell(n, unit); NumberSpelling numberSpelling = new NumberSpelling( new Data.DeclensionForms(result.NumberDeclension), new Data.DeclensionForms(result.UnitDeclension)); return(numberSpelling); } catch (Exception exc) { throw MorpherHelper.MapClientExceptionIfPossible(exc); } }
public void RussianNumberSpelling() { var webClient = new Mock <IWebClient>(); webClient.Setup(client => client.QueryString).Returns(new NameValueCollection()); webClient.Setup(client => client.DownloadString(It.IsAny <string>())).Returns(SpellResultText); var morpherClient = new MorpherClient(null, null, webClient.Object); var numberSpelling = new NumberSpelling(morpherClient.Russian); AssertNumberSpelling(numberSpelling, "один миллиард двести тридцать четыре миллиона пятьсот шестьдесят семь тысяч восемьсот девяносто", "рублей", Case.Nominative); AssertNumberSpelling(numberSpelling, "одного миллиарда двухсот тридцати четырёх миллионов пятисот шестидесяти семи тысяч восьмисот девяноста", "рублей", Case.Genitive); AssertNumberSpelling(numberSpelling, "одному миллиарду двумстам тридцати четырём миллионам пятистам шестидесяти семи тысячам восьмистам девяноста", "рублям", Case.Dative); AssertNumberSpelling(numberSpelling, "один миллиард двести тридцать четыре миллиона пятьсот шестьдесят семь тысяч восемьсот девяносто", "рублей", Case.Accusative); AssertNumberSpelling(numberSpelling, "одним миллиардом двумястами тридцатью четырьмя миллионами пятьюстами шестьюдесятью семью тысячами восьмьюстами девяноста", "рублями", Case.Instrumental); AssertNumberSpelling(numberSpelling, "одном миллиарде двухстах тридцати четырёх миллионах пятистах шестидесяти семи тысячах восьмистах девяноста", "рублях", Case.Prepositional); Assert.Throws <NotImplementedException>(() => { string unit = "рубль"; numberSpelling.Spell(1, ref unit, Case.Locative); }); string nullUnit = null; Assert.IsNull(numberSpelling.Spell(1, ref nullUnit, Case.Prepositional)); webClient.Verify(client => client.QueryString); webClient.Verify(client => client.DownloadString(It.IsAny <string>())); }
public void UkrainianNumberSpelling() { var webClient = new Mock <IWebClient>(); webClient.Setup(client => client.QueryString).Returns(new NameValueCollection()); webClient.Setup(client => client.DownloadString(It.IsAny <string>())).Returns(SpellText); var morpherClient = new MorpherClient(null, null, webClient.Object); var numberSpelling = new NumberSpelling(morpherClient.Ukrainian); AssertNumberSpelling(numberSpelling, "один мільярд двісті тридцять чотири мільйони п'ятсот шістдесят сім тисяч вісімсот дев'яносто", "рублів", Case.Nominative); AssertNumberSpelling(numberSpelling, "одного мільярда двохсот тридцяти чотирьох мільйонів п'ятисот шістдесяти семи тисяч восьмисот дев'яноста", "рублів", Case.Genitive); AssertNumberSpelling(numberSpelling, "одному мільярду двомстам тридцяти чотирьом мільйонам п'ятистам шістдесяти семи тисячам восьмистам дев'яноста", "рублям", Case.Dative); AssertNumberSpelling(numberSpelling, "один мільярд двісті тридцять чотири мільйони п'ятсот шістдесят сім тисяч вісімсот дев'яносто", "рублів", Case.Accusative); AssertNumberSpelling(numberSpelling, "одним мільярдом двомастами тридцятьма чотирма мільйонами п'ятьмастами шістдесятьма сьома тисячами вісьмастами дев'яноста", "рублями", Case.Instrumental); AssertNumberSpelling(numberSpelling, "одному мільярді двохстах тридцяти чотирьох мільйонах п'ятистах шістдесяти семи тисячах восьмистах дев'яноста", "рублях", Case.Prepositional); AssertNumberSpelling(numberSpelling, "один мільярд двісті тридцять чотири мільйони п'ятсот шістдесят сім тисяч вісімсот дев'яносто", "рублів", Case.Vocative); string nullUnit = null; Assert.IsNull(numberSpelling.Spell(1, ref nullUnit, Case.Prepositional)); webClient.Verify(client => client.QueryString); webClient.Verify(client => client.DownloadString(It.IsAny <string>())); }
public void Test_For_Zero_Value() { var result = NumberSpelling.ToSpell(0); Assert.AreEqual("Zero", result); }
public void Test_For_Million_Value() { var result = NumberSpelling.ToSpell(1113770); Assert.AreEqual("one million one hundred and thirteen thousand seven hundred and seventy", result); }
public void Test_For_Thousands_Value() { var result = NumberSpelling.ToSpell(7707); Assert.AreEqual("seven thousand seven hundred and seven", result); }
public void Test_For_Tens_Value() { var result = NumberSpelling.ToSpell(77); Assert.AreEqual("seventy seven", result); }
public void Test_For_Negative_Value() { var result = NumberSpelling.ToSpell(-13456); Assert.AreEqual("Negative value not allowed and should be a whole number", result); }