Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ jobs:
run: cargo test --all-targets

msrv:
name: MSRV 1.31.0
name: MSRV 1.85.0
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust 1.31.0
- name: Install Rust 1.85.0
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.31.0
toolchain: 1.85.0
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: cargo check (MSRV)
Expand Down
4 changes: 3 additions & 1 deletion src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ mod tests {

#[test]
fn price() {
exec_mes("currency::short", || format!("{}", currency::price(1_f64, 123_f64)));
exec_mes("currency::short", || {
format!("{}", currency::price(1_f64, 123_f64))
});
}
}
3 changes: 1 addition & 2 deletions src/data/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
pub static NUMBER: &[&str] = &["#####", "####", "###"];

#[allow(dead_code)]
pub static STREET_PREFIX: &[&str] =
&["North", "East", "West", "South", "New", "Lake", "Port"];
pub static STREET_PREFIX: &[&str] = &["North", "East", "West", "South", "New", "Lake", "Port"];

#[allow(dead_code)]
pub static STREET_NAME: &[&str] = &[
Expand Down
2 changes: 1 addition & 1 deletion src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub const QUESTIONMARK: &str = "?";

pub fn random_data<T: Clone>(d: &[T]) -> T {
let n = rand_range(0, d.len() as i64);

d[n as usize].clone()
}

Expand Down
44 changes: 23 additions & 21 deletions src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,40 @@ pub fn credit_card_number() -> String {
misc::replace_with_numbers(misc::random_data(payment::NUMBER).to_string())
}

fn gen_random_num(length:usize) -> Vec<i32> {
let mut nums=vec![0i32;length];
fn gen_random_num(length: usize) -> Vec<i32> {
let mut nums = vec![0i32; length];
for x in &mut nums {
*x=randn(9);
*x = randn(9);
}
nums
}

pub fn credit_card_luhn_number() -> String {
let mii=randn(9);//MII (Major Industry Identifier)
let nums=gen_random_num(14);
let iin=[mii.to_string(),nums.iter().map(ToString::to_string).collect()].join("");
let mut total=0;
let mii = randn(9); //MII (Major Industry Identifier)
let nums = gen_random_num(14);
let iin = [
mii.to_string(),
nums.iter().map(ToString::to_string).collect(),
]
.join("");
let mut total = 0;

for (i,val) in iin.chars().rev().enumerate() {
if i%2!=0 {
total+=val.to_digit(10).expect("error");
}
else {
let double=val.to_digit(10).expect("error")*2;
let digits=double.to_string();
if digits.len()>1 {
for (i, val) in iin.chars().rev().enumerate() {
if i % 2 != 0 {
total += val.to_digit(10).expect("error");
} else {
let double = val.to_digit(10).expect("error") * 2;
let digits = double.to_string();
if digits.len() > 1 {
for j in digits.chars() {
total+=j.to_digit(10).expect("error");
total += j.to_digit(10).expect("error");
}
} else {
total += double;
}
else {
total+=double;
}
}
}
}
let check=10-(total % 10)%10;
let check = 10 - (total % 10) % 10;
format!("{iin}{check}")
}

Expand Down