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

Adding benchmarks with Criterion #31

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4f398d0
No Deps Working Example with i32
Laifsyn Mar 26, 2024
0cbbd32
Staging changes on branch for dev-ing
Laifsyn Mar 28, 2024
04bf0ec
Implement Tests for to_cardinal method
Laifsyn Mar 29, 2024
4a61d9d
Implement Tests for to_cardinal method
Laifsyn Mar 29, 2024
53472fa
ammending - eliminate prepended zeros from tests
Laifsyn Mar 29, 2024
3e236dd
Fix weird merging
Laifsyn Mar 29, 2024
02195d7
More unified test for cardinal conversion
Laifsyn Mar 29, 2024
a81b310
Add Veinti Flavor and setters for Spanish fields
Laifsyn Mar 29, 2024
d29babe
Refactoro with BigFloat
Laifsyn Mar 29, 2024
df765fd
Consume Vec of Triplets instead of reading it
Laifsyn Mar 29, 2024
e41e33e
Refactor out the Integer equivalent of to_cardinal()
Laifsyn Mar 29, 2024
fe3638c
Conversion for fractional number
Laifsyn Mar 30, 2024
496f7a2
Tweak comments and error checking
Laifsyn Apr 1, 2024
8de42c2
Staging: to_ordinal implementation
Laifsyn Apr 1, 2024
c547a3a
defaults to using "veinti..." flavor instead of "veinte y..."
Laifsyn Apr 2, 2024
8f51aa6
Stage Changes: to_ordinal progress
Laifsyn Apr 3, 2024
ff4e5a1
Complete ordinal implementation
Laifsyn Apr 3, 2024
57c722c
to_year implementation
Laifsyn Apr 3, 2024
3d9b15e
Expand tests
Laifsyn Apr 4, 2024
04d2e01
update container settings
Laifsyn Apr 4, 2024
5d0a21f
Currency Implementation
Laifsyn Apr 4, 2024
fad8ceb
Add Spanish implementation to lang::Language trait
Laifsyn Apr 6, 2024
66c56aa
try to ensure enum integrity safety
Laifsyn Apr 6, 2024
b11912e
add rustfmt_skip
Laifsyn Apr 7, 2024
a057344
derive basic traits for Lang enum
Laifsyn Apr 7, 2024
0c62c2c
Add more str parsing and invert bool logic
Laifsyn Apr 7, 2024
52024f4
add Integration Test for spanish
Laifsyn Apr 7, 2024
1fd7816
Update Docs format and info
Laifsyn Apr 7, 2024
6d5e505
add Spanish Docs and fix currency logic
Laifsyn Apr 7, 2024
d197359
run Rustfmt on most files and add derives
Laifsyn Apr 7, 2024
611a17a
testing DocTests
Laifsyn Apr 8, 2024
f86b6ae
Try to improve Integration Test
Laifsyn Apr 8, 2024
a3be350
Main became too much of a mess, so un-using it
Laifsyn Apr 8, 2024
63c599a
Remove devcontainers and rustfmt
Laifsyn Apr 11, 2024
25de996
attend clippy warning in test
Laifsyn Apr 11, 2024
26eef47
undo rustfmt on bin.rs
Laifsyn Apr 11, 2024
5af4b80
Undoing rustfmt on lang.rs
Laifsyn Apr 12, 2024
21d77de
undo missed a rustfmt on lang.rs
Laifsyn Apr 12, 2024
428adfd
undo rustfmt on lib.rs
Laifsyn Apr 12, 2024
0d7ee4c
try fix trailing whitespace
Laifsyn Apr 12, 2024
6299fa3
try fix EOF
Laifsyn Apr 12, 2024
88bb1ad
delete unused main.rs
Laifsyn Apr 12, 2024
7371a47
remove cfg attribute from num2words.rs
Laifsyn Apr 12, 2024
f6aeb2d
temporarily remove derives from enum Output in output.rs
Laifsyn Apr 12, 2024
d61def7
Undo added derives to currency.rs
Laifsyn Apr 12, 2024
c72b339
update README with new language
Laifsyn Apr 12, 2024
92f21c8
Update readme to reflect spanish as option
Laifsyn Apr 12, 2024
2a8d28a
temporarily remove derives
Laifsyn Apr 12, 2024
5b7b311
First Benchmarks result - Using vanilla For Loop
Laifsyn Apr 14, 2024
b163025
Sync Bench branch with latest Spanish Impl
Laifsyn Apr 17, 2024
233ccf7
Update code for benchmark
Laifsyn Apr 22, 2024
40429a0
updated criterion.toml
Laifsyn May 27, 2024
6f6b66f
Fix numerical representation
Laifsyn May 27, 2024
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
Prev Previous commit
Next Next commit
defaults to using "veinti..." flavor instead of "veinte y..."
Laifsyn committed Apr 2, 2024
commit c547a3ad2016758387ef35047b0fd01750169fff
50 changes: 31 additions & 19 deletions src/lang/es.rs
Original file line number Diff line number Diff line change
@@ -179,28 +179,28 @@ pub mod ordinal {
pub struct Spanish {
/// Negative flavour like "bajo cero", "menos", "negativo"
neg_flavour: NegativeFlavour,
// Writes the number as "veintiocho" instead of "veinte y ocho" in case of true
veinti: bool,
// Writes the number as "veinte y ocho" instead of "veintiocho" in case of true
prefer_veinte: bool,
decimal_char: DecimalChar,
// Gender for ordinal numbers
feminine: bool,
}

impl Spanish {
#[inline(always)]
pub fn new() -> Self {
Self::default()
pub fn new(decimal_char: DecimalChar, feminine: bool) -> Self {
Self { decimal_char, feminine, ..Default::default() }
}

#[inline(always)]
pub fn set_veinti(&mut self, veinti: bool) -> &mut Self {
self.veinti = veinti;
pub fn set_veinte(&mut self, veinte: bool) -> &mut Self {
self.prefer_veinte = veinte;
self
}

#[inline(always)]
pub fn with_veinti(self, veinti: bool) -> Self {
Self { veinti, ..self }
pub fn with_veinte(self, veinte: bool) -> Self {
Self { prefer_veinte: veinte, ..self }
}

#[inline(always)]
@@ -297,12 +297,17 @@ impl Spanish {
// case `?_119` => `? ciento diecinueve`
// case `?_110` => `? ciento diez`
1 => words.push(String::from(DIECIS[units])),
2 if self.veinti && units != 0 => match units {
// case `?_021` => `? veintiuno`
2 if self.prefer_veinte && units != 0 => {
let unit_word = if units == 1 && i != 0 { "un" } else { unit_word };
words.push(format!("veinte y {unit_word}"));
}
2 => words.push(match units {
0 => String::from(DECENAS[tens]),
// case `021_...` => `? veintiún...`
1 if i != 0 => words.push(String::from("veintiún")),
_ => words.push(String::from("veinti") + unit_word),
},
1 if i != 0 => String::from("veintiún"),
// case `?_021` => `? veintiuno`
_ => format!("veinti{unit_word}"),
}),
_ => {
// case `?_142 => `? ciento cuarenta y dos`
let ten = DECENAS[tens];
@@ -416,7 +421,13 @@ impl Language for Spanish {
}

if tens != 0 || units != 0 {
let gender = || -> &str { if is_feminine { "a" } else { "o" } };
let gender = || -> &str {
if is_feminine {
"a"
} else {
"o"
}
};
let unit_word = String::from(UNIDADES[units]);

todo!("Finish the logic behind tens match statement");
@@ -580,14 +591,14 @@ mod tests {
"ciento setenta y un billones treinta y un millones cuarenta y un mil treinta y uno",
);
assert!(!es.int_to_cardinal(to(171_031_041_031)).unwrap().contains(" un "));
// with veinti flavour
let es = es.with_veinti(true);
// with veinte flavour
let es = es.with_veinte(true);

assert_eq!(
es.int_to_cardinal(to(21_021_321_021)).unwrap(),
"veintiun billones veintiun millones trescientos veintiun mil veintiuno"
"veinte y un billones veinte y un millones trescientos veinte y un mil veinte y uno"
);
assert_eq!(es.int_to_cardinal(to(22_000_000)).unwrap(), "veintidos millones");
assert_eq!(es.int_to_cardinal(to(22_000_000)).unwrap(), "veinte y dos millones");
assert_eq!(
es.int_to_cardinal(to(20_020_020)).unwrap(),
"veinte millones veinte mil veinte"
@@ -606,6 +617,7 @@ mod tests {
es.to_cardinal(BigFloat::from(0.0123456789)).unwrap(),
"cero coma cero uno dos tres cuatro cinco seis siete ocho nueve"
);
// Negative flavours
use NegativeFlavour::{Appended, BelowZero, Prepended};
let es = es.with_neg_flavour(Appended);
assert_eq!(
@@ -672,7 +684,7 @@ mod tests {
);
assert_eq!(
es.int_to_cardinal(to(801_021_001)).unwrap(),
"ochocientos uno millones veinte y uno mil uno"
"ochocientos uno millones veintiún mil uno"
);
assert_eq!(es.int_to_cardinal(to(1_000_000)).unwrap(), "un millón");
assert_eq!(es.int_to_cardinal(to(1_000_000_000)).unwrap(), "un billón");