Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Adds Portuguese #18

Merged
merged 19 commits into from
Feb 27, 2016
Merged
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
22 changes: 19 additions & 3 deletions Numsense.UnitTests.CSharp/NumeralTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public void FarsiIsSingleton()
{
var expected = Numeral.Farsi;
var actual = Numeral.Farsi;
Assert.Same(expected, actual);
}

Assert.Same(expected, actual);
}

public void PolishIsCorrect()
{
Expand Down Expand Up @@ -93,7 +94,22 @@ public void DutchIsSingleton()
var actual = Numeral.Dutch;
Assert.Same(expected, actual);
}


[Fact]
public void PortugueseIsCorrect()
{
var actual = Numeral.Portuguese;
Assert.IsAssignableFrom<PortugueseNumeralConverter>(actual);
}

[Fact]
public void PortugueseIsSingleton()
{
var expected = Numeral.Portuguese;
var actual = Numeral.Portuguese;
Assert.Same(expected, actual);
}

[Fact]
public void RussianIsCorrect()
{
Expand Down
2 changes: 1 addition & 1 deletion Numsense.UnitTests.CSharp/Numsense.UnitTests.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
2 changes: 1 addition & 1 deletion Numsense.UnitTests/EnglishExamples.fs
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@ let ``tryParseEnglish returns correct result`` (english, expected) =
"two-billion-one-hundred-forty-seven-million-four-hundred-eighty-three-thousand-six-hundred-forty-seven")>]
let ``toEnglish returns correct result`` (i, expected) =
let actual = Numeral.toEnglish i
expected =! actual
expected =! actual
15 changes: 15 additions & 0 deletions Numsense.UnitTests/NumeralProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ let ``negative Dutch is the inverse of positive Dutch`` x =
sprintf "min %s" (Numeral.toDutch x) =! actualDutch
Some -x =! actualInteger

[<Property(QuietOnSuccess = true)>]
let ``tryParsePortuguese is the inverse of toPortuguese`` x =
test <@ Some x = (x |> Numeral.toPortuguese |> Numeral.tryParsePortuguese) @>

[<Property(QuietOnSuccess = true)>]
let ``negative Portuguese is the inverse of positive Portuguese`` x =
x <> 0 ==> lazy
let x = abs x

let actualPortuguese = Numeral.toPortuguese -x
let actualInteger = Numeral.tryParsePortuguese actualPortuguese

sprintf "menos %s" (Numeral.toPortuguese x) =! actualPortuguese
Some -x =! actualInteger

[<Property(QuietOnSuccess = true)>]
let ``tryParseRussian is the inverse of toRussian`` x =
test <@ Some x = (x |> Numeral.toRussian |> Numeral.tryParseRussian) @>
Expand Down
1 change: 1 addition & 0 deletions Numsense.UnitTests/Numsense.UnitTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="PolishExamples.fs" />
<Compile Include="DutchExamples.fs" />
<Compile Include="RussianExamples.fs" />
<Compile Include="PortugueseExamples.fs" />
<Compile Include="SpanishExamples.fs" />
<Compile Include="CatalanExamples.fs" />
<Compile Include="SwedishExamples.fs" />
Expand Down
218 changes: 218 additions & 0 deletions Numsense.UnitTests/PortugueseExamples.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
module Ploeh.Numsense.PortugueseExamples

open Xunit
open Swensen.Unquote

[<Theory>]
[<InlineData( "menos mil, quinhentos e sessenta e oito", -1568)>]
[<InlineData( "menos um", -1)>]
[<InlineData( "zero", 0)>]
[<InlineData( " zero", 0)>]
[<InlineData( "zero ", 0)>]
[<InlineData( " zero ", 0)>]
[<InlineData( "Zero", 0)>]
[<InlineData( "ZERO", 0)>]
[<InlineData( " zERo\t", 0)>]
[<InlineData( "um", 1)>]
[<InlineData( "UM", 1)>]
[<InlineData( "dois", 2)>]
[<InlineData( " dois", 2)>]
[<InlineData( "três", 3)>]
[<InlineData( "três ", 3)>]
[<InlineData( "quatro", 4)>]
[<InlineData( " quatro ", 4)>]
[<InlineData( "cinco", 5)>]
[<InlineData( "CiNcO", 5)>]
[<InlineData( "seis", 6)>]
[<InlineData( " seis ", 6)>]
[<InlineData( "sete", 7)>]
[<InlineData( " seTe", 7)>]
[<InlineData( "oito", 8)>]
[<InlineData( "oITO", 8)>]
[<InlineData( "nove", 9)>]
[<InlineData( "nOvE ", 9)>]
[<InlineData( "dez", 10)>]
[<InlineData( "onze", 11)>]
[<InlineData( "doze", 12)>]
[<InlineData( "treze", 13)>]
[<InlineData( "quatorze", 14)>]
[<InlineData( "catorze", 14)>]
[<InlineData( "quinze", 15)>]
[<InlineData( "dezasseis", 16)>]
[<InlineData( "dezassete", 17)>]
[<InlineData( "dezoito", 18)>]
[<InlineData( "dezanove", 19)>]
[<InlineData( "vinte", 20)>]
[<InlineData( "vinteeum", 21)>]
[<InlineData( "vinte e um", 21)>]
[<InlineData( "trinta", 30)>]
[<InlineData( "trintaequatro", 34)>]
[<InlineData( "trinta-e oito", 38)>]
[<InlineData( "quarenta", 40)>]
[<InlineData( "quarenta e-um", 41)>]
[<InlineData( "quarenta e quatro", 44)>]
[<InlineData( "cinquenta", 50)>]
[<InlineData( "cinquentaesete", 57)>]
[<InlineData( "sessenta", 60)>]
[<InlineData( "sessentaecinco", 65)>]
[<InlineData( "setenta", 70)>]
[<InlineData( "setenta e sete", 77)>]
[<InlineData( "setentaenove", 79)>]
[<InlineData( "oitenta", 80)>]
[<InlineData( "oitentaeseis", 86)>]
[<InlineData( "noventa", 90)>]
[<InlineData( "noventaetrês", 93)>]
[<InlineData( "cem", 100)>]
[<InlineData( "centoeum", 101)>]
[<InlineData( "cento e um", 101)>]
[<InlineData( "duzentos", 200)>]
[<InlineData( "duzentosetrintaesete", 237)>]
[<InlineData( "trezentosesetentaecinco", 375)>]
[<InlineData( "quatrocentosenoventa", 490)>]
[<InlineData( "quinhentosesessentaetrês", 563)>]
[<InlineData( "seiscentosedezoito", 618)>]
[<InlineData( "setecentosesetentaesete", 777)>]
[<InlineData( "oitocentosecinco", 805)>]
[<InlineData( "oitocentoseseis", 806)>]
[<InlineData( "novecentosecinquentaenove", 959)>]
[<InlineData( "mil", 1000)>]
[<InlineData( "mileum", 1001)>]
[<InlineData( "miledois", 1002)>]
[<InlineData( "milesessentaequatro", 1064)>]
[<InlineData( "doismil", 2000)>]
[<InlineData( "oitomilsetecentosevinteeum", 8721)>]
[<InlineData( "novemilcentoevinteetrês", 9123)>]
[<InlineData( "dezmil", 10000)>]
[<InlineData( "dezmilcentoeum", 10101)>]
[<InlineData( "dezmilcentoedois", 10102)>]
[<InlineData( "vinteetrêsmilquinhentosesessentaequatro", 23564)>]
[<InlineData( "oitentamiledez", 80010)>]
[<InlineData( "cemmil", 100000)>]
[<InlineData( "cemmileum", 100001)>]
[<InlineData( "trezentosedezanovemiltrezentosequarentaenove", 319349)>]
[<InlineData( "ummilhão", 1000000)>]
[<InlineData( "ummilhãoeum", 1000001)>]
[<InlineData( "doismilhõesedez", 2000010)>]
[<InlineData( "seismilhõesetrintamil", 6030000)>]
[<InlineData( "novemilhõesduzentoseummilseiscentoseoitenta", 9201680)>]
[<InlineData( "dezmilhões", 10000000)>]
[<InlineData( "dezmilhõesenove", 10000009)>]
[<InlineData( "vinteeummilhões", 21000000)>]
[<InlineData(
"quarentaesetemilhõesseiscentosesessentaeummilesessenta", 47661060)>]
[<InlineData( "cemmilhões", 100000000)>]
[<InlineData( "duzentosecincomilhões", 205000000)>]
[<InlineData( "trezentos e sete milhões", 307000000)>]
[<InlineData(
"quatrocentosesessentaeummilhõessessentamileseiscentos", 461060600)>]
[<InlineData( "milmilhões", 1000000000)>]
[<InlineData( "doismilmilhões", 2000000000)>]
[<InlineData(
"doismilequarentaenovemilhõesseiscentosecinquentamil", 2049650000)>]
[<InlineData(
"doismilcentoequarentaesetemilhõesquatrocentoseoitentaetrêsmilseiscentosequarentaesete",
System.Int32.MaxValue)>]
let ``tryParsePortuguese returns correct result`` (portuguese, expected) =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points for not repeating my mistake of naming the test function tryOfPortuguese... etc. 👍

let actual = Numeral.tryParsePortuguese portuguese
Some expected =! actual

[<Theory>]
[<InlineData( -1586, "menos mil, quinhentos e oitenta e seis")>]
[<InlineData( -1, "menos um")>]
[<InlineData( 0, "zero")>]
[<InlineData( 1, "um")>]
[<InlineData( 2, "dois")>]
[<InlineData( 3, "três")>]
[<InlineData( 4, "quatro")>]
[<InlineData( 5, "cinco")>]
[<InlineData( 6, "seis")>]
[<InlineData( 7, "sete")>]
[<InlineData( 8, "oito")>]
[<InlineData( 9, "nove")>]
[<InlineData( 10, "dez")>]
[<InlineData( 11, "onze")>]
[<InlineData( 12, "doze")>]
[<InlineData( 13, "treze")>]
[<InlineData( 14, "catorze")>]
[<InlineData( 15, "quinze")>]
[<InlineData( 16, "dezasseis")>]
[<InlineData( 17, "dezassete")>]
[<InlineData( 18, "dezoito")>]
[<InlineData( 19, "dezanove")>]
[<InlineData( 20, "vinte")>]
[<InlineData( 21, "vinte e um")>]
[<InlineData( 30, "trinta")>]
[<InlineData( 34, "trinta e quatro")>]
[<InlineData( 40, "quarenta")>]
[<InlineData( 42, "quarenta e dois")>]
[<InlineData( 50, "cinquenta")>]
[<InlineData( 58, "cinquenta e oito")>]
[<InlineData( 60, "sessenta")>]
[<InlineData( 65, "sessenta e cinco")>]
[<InlineData( 70, "setenta")>]
[<InlineData( 79, "setenta e nove")>]
[<InlineData( 80, "oitenta")>]
[<InlineData( 86, "oitenta e seis")>]
[<InlineData( 90, "noventa")>]
[<InlineData( 93, "noventa e três")>]
[<InlineData( 100, "cem")>]
[<InlineData( 101, "cento e um")>]
[<InlineData( 110, "cento e dez")>]
[<InlineData( 114, "cento e catorze")>]
[<InlineData( 135, "cento e trinta e cinco")>]
[<InlineData( 200, "duzentos")>]
[<InlineData( 282, "duzentos e oitenta e dois")>]
[<InlineData( 331, "trezentos e trinta e um")>]
[<InlineData( 407, "quatrocentos e sete")>]
[<InlineData( 520, "quinhentos e vinte")>]
[<InlineData( 666, "seiscentos e sessenta e seis")>]
[<InlineData( 798, "setecentos e noventa e oito")>]
[<InlineData( 857, "oitocentos e cinquenta e sete")>]
[<InlineData( 999, "novecentos e noventa e nove")>]
[<InlineData( 1000, "mil")>]
[<InlineData( 1001, "mil e um")>]
[<InlineData( 1010, "mil e dez")>]
[<InlineData( 1066, "mil e sessenta e seis")>]
[<InlineData( 1337, "mil, trezentos e trinta e sete")>]
[<InlineData( 1984, "mil, novecentos e oitenta e quatro")>]
[<InlineData( 7441, "sete mil, quatrocentos e quarenta e um")>]
[<InlineData( 8513, "oito mil, quinhentos e treze")>]
[<InlineData( 908077, "novecentos e oito mil e setenta e sete")>]
[<InlineData( 1000000, "um milhão")>]
[<InlineData( 2000002, "dois milhões e dois")>]
[<InlineData( 3040506, "três milhões e quarenta mil, quinhentos e seis")>]
[<InlineData( 4025800, "quatro milhões e vinte e cinco mil e oitocentos")>]
[<InlineData( 4321000, "quatro milhões, trezentos e vinte e um mil")>]
[<InlineData( 4600819, "quatro milhões e seiscentos mil, oitocentos e dezanove")>]
[<InlineData( 5004621, "cinco milhões e quatro mil, seiscentos e vinte e um")>]
[<InlineData( 6982001, "seis milhões, novecentos e oitenta e dois mil e um")>]
[<InlineData( 7000000, "sete milhões")>]
[<InlineData( 8000220, "oito milhões, duzentos e vinte")>]
[<InlineData( 9099000, "nove milhões e noventa e nove mil")>]
[<InlineData( 10000000, "dez milhões")>]
[<InlineData( 24000000, "vinte e quatro milhões")>]
[<InlineData( 39020011, "trinta e nove milhões e vinte mil e onze")>]
[<InlineData( 40606100, "quarenta milhões, seiscentos e seis mil e cem")>]
[<InlineData( 53000000, "cinquenta e três milhões")>]
[<InlineData( 64000098, "sessenta e quatro milhões e noventa e oito")>]
[<InlineData( 70003190, "setenta milhões e três mil, cento e noventa")>]
[<InlineData( 80000000, "oitenta milhões")>]
[<InlineData( 99000099, "noventa e nove milhões e noventa e nove")>]
[<InlineData( 100000000, "cem milhões")>]
[<InlineData( 209000000, "duzentos e nove milhões")>]
[<InlineData( 398000000, "trezentos e noventa e oito milhões")>]
[<InlineData( 439011000, "quatrocentos e trinta e nove milhões e onze mil")>]
[<InlineData( 560400000, "quinhentos e sessenta milhões e quatrocentos mil")>]
[<InlineData( 600010900, "seiscentos milhões e dez mil e novecentos")>]
[<InlineData( 700000000, "setecentos milhões")>]
[<InlineData( 800116000, "oitocentos milhões, cento e dezasseis mil")>]
[<InlineData( 900800007, "novecentos milhões e oitocentos mil e sete")>]
[<InlineData(1000000000, "mil milhões")>]
[<InlineData(2121000000, "dois mil milhões, cento e vinte e um milhões")>]
[<InlineData(
System.Int32.MaxValue,
"dois mil milhões, cento e quarenta e sete milhões, quatrocentos e oitenta e três mil, seiscentos e quarenta e sete")>]

let ``toPortuguese returns correct result`` (i, expected) =
let actual = Numeral.toPortuguese i
expected =! actual
1 change: 1 addition & 0 deletions Numsense.UnitTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
<package id="xunit.runner.console" version="2.1.0" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net45" />
</packages>
47 changes: 25 additions & 22 deletions Numsense/Numeral.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,38 @@ module Ploeh.Numsense.Numeral
let toBulgarian = Bulgarian.toBulgarianImp
let tryParseBulgarian = Bulgarian.tryParseBulgarianImp

let toDanish = Danish.toDanishImp 1
let tryParseDanish = Danish.tryParseDanishImp
let toDanish = Danish.toDanishImp 1
let tryParseDanish = Danish.tryParseDanishImp

let toEnglish = English.toEnglishImp
let tryParseEnglish = English.tryParseEnglishImp
let toEnglish = English.toEnglishImp
let tryParseEnglish = English.tryParseEnglishImp

let toFarsi = Farsi.toFarsiImp
let tryParseFarsi = Farsi.tryParseFarsiImp
let toFarsi = Farsi.toFarsiImp
let tryParseFarsi = Farsi.tryParseFarsiImp

let toPolish = Polish.toPolishImp
let tryParsePolish = Polish.tryParsePolishImp
let toPolish = Polish.toPolishImp
let tryParsePolish = Polish.tryParsePolishImp

let toDutch = Dutch.toDutchImp
let tryParseDutch = Dutch.tryParseDutchImp
let toDutch = Dutch.toDutchImp
let tryParseDutch = Dutch.tryParseDutchImp

let toRussian = Russian.toRussianImp Russian.Masculine
let tryParseRussian = Russian.tryParseRussianImp
let toRussian = Russian.toRussianImp Russian.Masculine
let tryParseRussian = Russian.tryParseRussianImp

let toSpanish = Spanish.toSpanishImp
let tryParseSpanish = Spanish.tryParseSpanishImp
let toSpanish = Spanish.toSpanishImp
let tryParseSpanish = Spanish.tryParseSpanishImp

let toCatalan = Catalan.toCatalanImp
let tryParseCatalan = Catalan.tryParseCatalanImp
let toCatalan = Catalan.toCatalanImp
let tryParseCatalan = Catalan.tryParseCatalanImp

let toSwedish = Swedish.toSwedishImp
let tryParseSwedish = Swedish.tryParseSwedishImp
let toSwedish = Swedish.toSwedishImp
let tryParseSwedish = Swedish.tryParseSwedishImp

let toRomanian = Romanian.toRomanianImp
let tryParseRomanian = Romanian.tryParseRomanianImp
let toRomanian = Romanian.toRomanianImp
let tryParseRomanian = Romanian.tryParseRomanianImp

let toGerman = German.toGermanImp
let tryParseGerman = German.tryParseGermanImp
let toGerman = German.toGermanImp
let tryParseGerman = German.tryParseGermanImp

let toPortuguese = Portuguese.toPortugueseImp
let tryParsePortuguese = Portuguese.tryParsePortugueseImp
1 change: 1 addition & 0 deletions Numsense/Numsense.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="English.fs" />
<Compile Include="Farsi.fs" />
<Compile Include="Polish.fs" />
<Compile Include="Portuguese.fs" />
<Compile Include="Dutch.fs" />
<Compile Include="Russian.fs" />
<Compile Include="Spanish.fs" />
Expand Down
Loading