update tests
This commit is contained in:
parent
9fac0f3667
commit
a9d81f015e
3 changed files with 14 additions and 14 deletions
|
@ -93,11 +93,11 @@ pub mod bytes {
|
|||
/// ```
|
||||
/// use cat2text::{anybase::bytes::encode, core::bytes::char_length};
|
||||
///
|
||||
/// let bytes = &[243];
|
||||
/// let bytes = &[243, 10];
|
||||
/// let base = 16;
|
||||
/// let char_length = char_length(base);
|
||||
///
|
||||
/// assert_eq!("meow mewo meow mrrp", encode(bytes, base, char_length));
|
||||
/// assert_eq!("mrow~ mrow meow purrrr", encode(bytes, base, char_length));
|
||||
/// ```
|
||||
pub fn encode(bytes: impl AsRef<[u8]>, base: u32, char_length: u32) -> String {
|
||||
let mut output = String::new();
|
||||
|
@ -116,12 +116,12 @@ pub mod bytes {
|
|||
/// ```
|
||||
/// use cat2text::{anybase::bytes::decode, core::bytes::char_length};
|
||||
///
|
||||
/// let text = "mrrp nyaaaa~ meow".to_string();
|
||||
/// let base = 10;
|
||||
/// let text = "mrow~ mrow meow purrrr".to_string();
|
||||
/// let base = 16;
|
||||
/// let char_length = char_length(base);
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// vec![21, 1],
|
||||
/// vec![243, 10],
|
||||
/// decode(text, base, char_length)
|
||||
/// );
|
||||
/// ```
|
||||
|
|
|
@ -40,7 +40,7 @@ pub mod bytes {
|
|||
/// ```
|
||||
/// use cat2text::base4::bytes::encode;
|
||||
///
|
||||
/// assert_eq!("meow mreow mrrp meow meow mrrp", encode(&[253..., 1]));
|
||||
/// assert_eq!("mrow mrow mrow mrrp meow meow meow mrrp", encode(&[253, 1]));
|
||||
/// ```
|
||||
pub fn encode(bytes: impl AsRef<[u8]>) -> String {
|
||||
anybase::bytes::encode(bytes, 4, char_length(4))
|
||||
|
@ -51,7 +51,7 @@ pub mod bytes {
|
|||
/// ```
|
||||
/// use cat2text::base4::bytes::decode;
|
||||
///
|
||||
/// assert_eq!(vec![9, 1], decode("meow mreow mrrp meow meow mrrp".to_string()));
|
||||
/// assert_eq!(vec![253, 1], decode("mrow mrow mrow mrrp meow meow meow mrrp".to_string()));
|
||||
/// ```
|
||||
pub fn decode(text: String) -> Vec<u8> {
|
||||
anybase::bytes::decode(text, 4, char_length(4))
|
||||
|
|
14
src/core.rs
14
src/core.rs
|
@ -3,10 +3,10 @@
|
|||
/// Converts a [`u32`] to catspeak
|
||||
///
|
||||
/// ```
|
||||
/// use cat2text::core::num_to_cat;
|
||||
/// use cat2text::base4::{alphabet, char_length};
|
||||
/// use cat2text::core::{num_to_cat, char_length};
|
||||
/// use cat2text::base4::alphabet;
|
||||
///
|
||||
/// assert_eq!("meow mreow mrrp".to_string(), num_to_cat(9, alphabet(), char_length()));
|
||||
/// assert_eq!("meow mreow mrrp".to_string(), num_to_cat(9, alphabet(), char_length(4)));
|
||||
/// ```
|
||||
pub fn num_to_cat(num: u32, alphabet: Vec<String>, char_length: u32) -> String {
|
||||
let mut num: u32 = num.clone();
|
||||
|
@ -31,12 +31,12 @@ pub fn num_to_cat(num: u32, alphabet: Vec<String>, char_length: u32) -> String {
|
|||
/// Converts catspeak to a [`u32`]
|
||||
///
|
||||
/// ```
|
||||
/// use cat2text::core::cat_to_num;
|
||||
/// use cat2text::base4::{alphabet, char_length};
|
||||
/// use cat2text::core::{cat_to_num, bytes::char_length};
|
||||
/// use cat2text::base4::alphabet;
|
||||
///
|
||||
/// let letter = vec!["meow".to_string(), "mreow".to_string(), "mrrp".to_string()];
|
||||
/// let text = vec!["meow".to_string(), "mrrp".to_string(), "mrow".to_string(), "meow".to_string()];
|
||||
///
|
||||
/// assert_eq!(9, cat_to_num(letter, alphabet(), char_length()));
|
||||
/// assert_eq!(28, cat_to_num(text, alphabet(), char_length(4)));
|
||||
/// ```
|
||||
pub fn cat_to_num(text: Vec<String>, alphabet: Vec<String>, char_length: u32) -> u32 {
|
||||
let mut nums: Vec<u32> = Vec::new();
|
||||
|
|
Loading…
Add table
Reference in a new issue