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

Cria módulo de testes e ajusta visibilidade dos módulos #32

Merged
merged 2 commits into from
Nov 18, 2023
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
2 changes: 1 addition & 1 deletion brado/src/docs/cpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn generate_digit(
sum as u8
}

pub fn is_repeated(digits: &[u8]) -> bool {
fn is_repeated(digits: &[u8]) -> bool {
let a_set: HashSet<u8> = HashSet::from_iter(digits.iter().cloned());
a_set.len() == 1
}
Expand Down
1 change: 1 addition & 0 deletions brado/src/docs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod cnpj;
pub mod common;
pub mod cpf;
pub mod doc;
pub use doc::Document;
89 changes: 4 additions & 85 deletions brado/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,85 +1,4 @@
pub mod docs;

#[cfg(test)]
mod cpf_tests {
use super::*;
use crate::docs::doc::Document;

#[test]
fn validate_cpf_1() {
let cpf_doc: Document = Document::new("11111111111");
assert_eq!(false, docs::cpf::validate(&cpf_doc, false, false));
}

#[test]
fn validate_cpf_2() {
let cpf_doc: Document = Document::new("111.111.111-11");
assert_eq!(false, docs::cpf::validate(&cpf_doc, true, false));
}

#[test]
fn validate_cpf_3() {
let cpf_doc: Document = Document::new("63929247011");
assert_eq!(true, docs::cpf::validate(&cpf_doc, false, true));
}

#[test]
fn validate_cpf_4() {
let cpf_doc: Document = Document::new("639.292.470-11");
assert_eq!(true, docs::cpf::validate(&cpf_doc, true, false));
}

#[test]
fn validate_str_cpf_1() {
let bare_cpf = "11111111111";
assert_eq!(false, docs::cpf::validate_str(bare_cpf, false, false));
}

#[test]
fn validate_str_cpf_2() {
let bare_cpf = "111.111.111-11";
assert_eq!(false, docs::cpf::validate_str(bare_cpf, true, false));
}

#[test]
fn validate_str_cpf_3() {
let bare_cpf = "63929247011";
assert_eq!(true, docs::cpf::validate_str(bare_cpf, false, true));
}

#[test]
fn validate_str_cpf_4() {
let bare_cpf = "639.292.470-11";
assert_eq!(true, docs::cpf::validate_str(&bare_cpf, true, false));
}
}

#[cfg(test)]
mod cnpj_tests {
use super::*;
use crate::docs::doc::Document;

#[test]
fn validate_cnpj_1() {
let cnpj_doc: Document = Document::new("05200851000100");
assert_eq!(true, docs::cnpj::validate(&cnpj_doc, false));
}

#[test]
fn validate_cnpj_2() {
let cnpj_doc: Document = Document::new("05.200.851/0001-00");
assert_eq!(true, docs::cnpj::validate(&cnpj_doc, true));
}

#[test]
fn validate_str_cnpj_1() {
let bare_cnpj = "05200851000100";
assert_eq!(true, docs::cnpj::validate_str(&bare_cnpj, false));
}

#[test]
fn validate_str_cnpj_2() {
let bare_cnpj = "05.200.851/0001-00";
assert_eq!(true, docs::cnpj::validate_str(&bare_cnpj, true));
}
}
mod docs;
pub use crate::docs::cnpj;
pub use crate::docs::cpf;
pub use crate::docs::Document;
29 changes: 29 additions & 0 deletions brado/tests/cnpj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cfg(test)]
mod cnpj_tests {
use brado;
use brado::Document;

#[test]
fn validate_cnpj_1() {
let cnpj_doc: Document = Document::new("05200851000100");
assert_eq!(true, brado::cnpj::validate(&cnpj_doc, false));
}

#[test]
fn validate_cnpj_2() {
let cnpj_doc: Document = Document::new("05.200.851/0001-00");
assert_eq!(true, brado::cnpj::validate(&cnpj_doc, true));
}

#[test]
fn validate_str_cnpj_1() {
let bare_cnpj = "05200851000100";
assert_eq!(true, brado::cnpj::validate_str(&bare_cnpj, false));
}

#[test]
fn validate_str_cnpj_2() {
let bare_cnpj = "05.200.851/0001-00";
assert_eq!(true, brado::cnpj::validate_str(&bare_cnpj, true));
}
}
53 changes: 53 additions & 0 deletions brado/tests/cpf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#[cfg(test)]
mod cpf_tests {
use brado;
use brado::Document;

#[test]
fn validate_cpf_1() {
let cpf_doc: Document = Document::new("11111111111");
assert_eq!(false, brado::cpf::validate(&cpf_doc, false, false));
}

#[test]
fn validate_cpf_2() {
let cpf_doc: Document = Document::new("111.111.111-11");
assert_eq!(false, brado::cpf::validate(&cpf_doc, true, false));
}

#[test]
fn validate_cpf_3() {
let cpf_doc: Document = Document::new("63929247011");
assert_eq!(true, brado::cpf::validate(&cpf_doc, false, true));
}

#[test]
fn validate_cpf_4() {
let cpf_doc: Document = Document::new("639.292.470-11");
assert_eq!(true, brado::cpf::validate(&cpf_doc, true, false));
}

#[test]
fn validate_str_cpf_1() {
let bare_cpf = "11111111111";
assert_eq!(false, brado::cpf::validate_str(bare_cpf, false, false));
}

#[test]
fn validate_str_cpf_2() {
let bare_cpf = "111.111.111-11";
assert_eq!(false, brado::cpf::validate_str(bare_cpf, true, false));
}

#[test]
fn validate_str_cpf_3() {
let bare_cpf = "63929247011";
assert_eq!(true, brado::cpf::validate_str(bare_cpf, false, true));
}

#[test]
fn validate_str_cpf_4() {
let bare_cpf = "639.292.470-11";
assert_eq!(true, brado::cpf::validate_str(&bare_cpf, true, false));
}
}