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

First iteration of custom seed #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ name = "fakeit"
harness = false

[dependencies]
rand = "0.6.5"
libmath = "0.2.1"
uuid = { version = "0.8", features = ["v1", "v4"] }
simplerand = "1.2.0"
simplerand = "1.5.1"
lazy_static = "1.5.0"
91 changes: 79 additions & 12 deletions src/address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::data::address;
use crate::generator::Generator;
use crate::generator;
use crate::misc;
use crate::name;
// use ::std::string::String;

pub struct Info {
address: String,
Expand Down Expand Up @@ -30,41 +31,41 @@ pub fn info() -> Info {
pub fn street() -> String {
match misc::random::<i64>(1, 2) {
1 => {
return format!(
format!(
"{} {} {} {}",
street_number(),
street_prefix(),
street_name(),
street_suffix()
)
}
2 => return format!("{} {} {}", street_number(), street_name(), street_suffix()),
_ => format!("impossible"),
2 => format!("{} {} {}", street_number(), street_name(), street_suffix()),
_ => "impossible".to_string(),
}
}

pub fn street_number() -> String {
misc::replace_with_numbers(misc::random_data(address::NUMBER).to_string())
generator::get_base_generator().street_number()
}

pub fn street_prefix() -> String {
misc::random_data(address::STREET_PREFIX).to_string()
generator::get_base_generator().street_prefix()
}

pub fn street_name() -> String {
misc::random_data(address::STREET_NAME).to_string()
generator::get_base_generator().street_name()
}

pub fn street_suffix() -> String {
misc::random_data(address::STREET_SUFFIX).to_string()
generator::get_base_generator().street_suffix()
}

pub fn city() -> String {
match misc::random::<i64>(1, 3) {
1 => return format!("{}{}", name::first(), street_suffix()),
2 => return format!("{}{}", name::last(), street_suffix()),
3 => return format!("{} {}", street_prefix(), name::last()),
_ => format!("impossible"),
1 => format!("{}{}", name::first(), street_suffix()),
2 => format!("{}{}", name::last(), street_suffix()),
3 => format!("{} {}", street_prefix(), name::last()),
_ => "impossible".to_string(),
}
}

Expand Down Expand Up @@ -93,6 +94,7 @@ pub fn latitude() -> f32 {
}

pub fn latitude_in_range(min: f32, max: f32) -> f32 {
#[allow(clippy::manual_range_contains)]
if min > max || min < -90.0 || min > 90.0 || max < -90.0 || max > 90.0 {
return latitude();
}
Expand All @@ -105,18 +107,79 @@ pub fn longitude() -> f32 {
}

pub fn longitude_in_range(min: f32, max: f32) -> f32 {
#[allow(clippy::manual_range_contains)]
if min > max || min < -180.0 || min > 180.0 || max < -180.0 || max > 180.0 {
return latitude();
}

misc::random::<f32>(min, max)
}

impl Generator {
pub fn street(&self) -> String {
match self.rng.rand_range(1, 2) {
1 => {
format!(
"{} {} {} {}",
self.street_number(),
self.street_prefix(),
self.street_name(),
self.street_suffix()
)
}
2 => format!(
"{} {} {}",
self.street_number(),
self.street_name(),
self.street_suffix()
),
_ => "impossible".to_string(),
}
}

pub fn street_number(&self) -> String {
let random_data = self.random_data(address::NUMBER).to_string();
self.replace_with_numbers(random_data)
}

pub fn street_prefix(&self) -> String {
self.random_data(address::STREET_PREFIX).to_string()
}

pub fn street_name(&self) -> String {
self.random_data(address::STREET_NAME).to_string()
}

pub fn street_suffix(&self) -> String {
self.random_data(address::STREET_SUFFIX).to_string()
}
}

#[cfg(test)]
mod tests {
use crate::address;
use crate::generator::Generator;
use crate::testify::exec_mes;

#[test]
fn gen_street() {
let g = Generator::new(1);
let result = g.street();

let g = Generator::new(1);
let result2 = g.street();

assert_eq!(result, result2);
}

#[test]
fn street_diff() {
let result = address::street();
let result2 = address::street();

assert_ne!(result, result2);
}

#[test]
fn street() {
exec_mes("address::street", || address::street());
Expand All @@ -125,6 +188,10 @@ mod tests {
#[test]
fn street_number() {
exec_mes("address::street_number", || address::street_number());

let result1 = address::street_number();
let result2 = address::street_number();
assert_ne!(result1, result2);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/company.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use ::std::string::String;

pub fn company() -> String {
match misc::random::<i64>(1, 3) {
1 => return format!("{}, {} and {}", name::last(), name::last(), name::last()),
2 => return format!("{}-{}", name::last(), name::last()),
3 => return format!("{} {}", name::last(), company_suffix()),
_ => format!("impossible"),
1 => format!("{}, {} and {}", name::last(), name::last(), name::last()),
2 => format!("{}-{}", name::last(), name::last()),
3 => format!("{} {}", name::last(), company_suffix()),
_ => "impossible".to_string(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn email() -> String {
name::first(),
name::last(),
name::last(),
misc::random_data(internet::DOMAIN_SUFFIX).to_string()
misc::random_data(internet::DOMAIN_SUFFIX)
)
.to_lowercase()
}
Expand Down
20 changes: 10 additions & 10 deletions src/data/address.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[allow(dead_code)]
pub static NUMBER: &'static [&str] = &["#####", "####", "###"];
pub static NUMBER: &[&str] = &["#####", "####", "###"];

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

#[allow(dead_code)]
pub static STREET_NAME: &'static [&str] = &[
pub static STREET_NAME: &[&str] = &[
"Alley",
"Avenue",
"Branch",
Expand Down Expand Up @@ -235,21 +235,21 @@ pub static STREET_NAME: &'static [&str] = &[
];

#[allow(dead_code)]
pub static STREET_SUFFIX: &'static [&str] = &[
pub static STREET_SUFFIX: &[&str] = &[
"town", "ton", "land", "ville", "berg", "burgh", "borough", "bury", "view", "port", "mouth",
"stad", "furt", "chester", "mouth", "fort", "haven", "side", "shire",
];

#[allow(dead_code)]
pub static CITY: &'static [&str] = &[
pub static CITY: &[&str] = &[
"{address.street_prefix} {name.first}{address.street_suffix}",
"{address.street_prefix} {name.first}",
"{name.first}{address.street_suffix}",
"{name.last}{address.street_suffix}",
];

#[allow(dead_code)]
pub static STATE: &'static [&str] = &[
pub static STATE: &[&str] = &[
"Alabama",
"Alaska",
"Arizona",
Expand Down Expand Up @@ -303,18 +303,18 @@ pub static STATE: &'static [&str] = &[
];

#[allow(dead_code)]
pub static STATE_ABR: &'static [&str] = &[
pub static STATE_ABR: &[&str] = &[
"AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID",
"IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE",
"NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC",
"SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY", "AE", "AA", "AP",
];

#[allow(dead_code)]
pub static ZIP: &'static [&str] = &["#####"];
pub static ZIP: &[&str] = &["#####"];

#[allow(dead_code)]
pub static COUNTRY: &'static [&str] = &[
pub static COUNTRY: &[&str] = &[
"Afghanistan",
"Albania",
"Algeria",
Expand Down Expand Up @@ -563,7 +563,7 @@ pub static COUNTRY: &'static [&str] = &[
];

#[allow(dead_code)]
pub static COUNTRY_ABR: &'static [&str] = &[
pub static COUNTRY_ABR: &[&str] = &[
"AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS",
"BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN",
"BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM",
Expand Down
12 changes: 6 additions & 6 deletions src/data/animal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[allow(dead_code)]
pub static PETNAME: &'static [&str] = &[
pub static PETNAME: &[&str] = &[
"Alfalfa",
"Archie",
"Attila",
Expand Down Expand Up @@ -88,7 +88,7 @@ pub static PETNAME: &'static [&str] = &[
];

#[allow(dead_code)]
pub static ANIMAL: &'static [&str] = &[
pub static ANIMAL: &[&str] = &[
"alligator",
"alpaca",
"ant",
Expand Down Expand Up @@ -232,7 +232,7 @@ pub static ANIMAL: &'static [&str] = &[
];

#[allow(dead_code)]
pub static TYPE: &'static [&str] = &[
pub static TYPE: &[&str] = &[
"amphibians",
"birds",
"fish",
Expand All @@ -242,12 +242,12 @@ pub static TYPE: &'static [&str] = &[
];

#[allow(dead_code)]
pub static FARM: &'static [&str] = &[
pub static FARM: &[&str] = &[
"Chicken", "Cow", "Donkey", "Duck", "Goat", "Goose", "Horse", "Llama", "Pig", "Sheep", "Turkey",
];

#[allow(dead_code)]
pub static CAT: &'static [&str] = &[
pub static CAT: &[&str] = &[
"Abyssinian",
"Aegean",
"American Bobtail",
Expand Down Expand Up @@ -347,7 +347,7 @@ pub static CAT: &'static [&str] = &[
];

#[allow(dead_code)]
pub static DOG: &'static [&str] = &[
pub static DOG: &[&str] = &[
"Affenpinscher",
"African",
"Airedale",
Expand Down
10 changes: 5 additions & 5 deletions src/data/beer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[allow(dead_code)]
pub static NAME: &'static [&str] = &[
pub static NAME: &[&str] = &[
"Pliny The Elder",
"Founders Kentucky Breakfast",
"Trappistes Rochefort 10",
Expand Down Expand Up @@ -53,7 +53,7 @@ pub static NAME: &'static [&str] = &[
];

#[allow(dead_code)]
pub static HOP: &'static [&str] = &[
pub static HOP: &[&str] = &[
"Ahtanum",
"Amarillo",
"Bitter Gold",
Expand Down Expand Up @@ -108,7 +108,7 @@ pub static HOP: &'static [&str] = &[
];

#[allow(dead_code)]
pub static YEAST: &'static [&str] = &[
pub static YEAST: &[&str] = &[
"1007 - German Ale",
"1010 - American Wheat",
"1028 - London Ale",
Expand Down Expand Up @@ -161,7 +161,7 @@ pub static YEAST: &'static [&str] = &[
];

#[allow(dead_code)]
pub static MALT: &'static [&str] = &[
pub static MALT: &[&str] = &[
"Black malt",
"Caramel",
"Carapils",
Expand All @@ -181,7 +181,7 @@ pub static MALT: &'static [&str] = &[
];

#[allow(dead_code)]
pub static STYLE: &'static [&str] = &[
pub static STYLE: &[&str] = &[
"Light Lager",
"Pilsner",
"European Amber Lager",
Expand Down
4 changes: 2 additions & 2 deletions src/data/color.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[allow(dead_code)]
pub static SAFE: &'static [&str] = &[
pub static SAFE: &[&str] = &[
"black", "maroon", "green", "navy", "olive", "purple", "teal", "lime", "blue", "silver",
"gray", "yellow", "fuchsia", "aqua", "white",
];

#[allow(dead_code)]
pub static FULL: &'static [&str] = &[
pub static FULL: &[&str] = &[
"AliceBlue",
"AntiqueWhite",
"Aqua",
Expand Down
Loading