add tests

This commit is contained in:
askiiart 2025-01-13 22:44:10 -06:00
parent 6c7563455f
commit 7e40f48064
Signed by untrusted user who does not match committer: askiiart
GPG key ID: 6A32977DAF31746A
2 changed files with 31 additions and 0 deletions

View file

@ -3,3 +3,4 @@ pub mod anybase;
pub mod base4;
pub mod core;
pub mod bytes;
mod tests;

30
src/tests.rs Normal file
View file

@ -0,0 +1,30 @@
#[test]
fn test_anybase_base4() {
use crate::{anybase, base4};
let text = "i love cats".to_string();
let encoded = anybase::encode(text.clone(), 4, anybase::char_length(4));
assert_eq!(base4::encode(text), encoded);
let decoded = anybase::decode(encoded.clone(), 4, anybase::char_length(4));
assert_eq!(base4::decode(encoded), decoded);
}
#[test]
fn test_anybase_encode() {
use crate::anybase;
let text = "i love cats".to_string();
let base = 10;
let char_length = anybase::char_length(base);
assert_eq!("meow mewo; mrrp mreow mrrp nyaaaa~ mreow mreow meow nyaaaa~; meow mrow meow mrrp mreow meow mrrp mewo", anybase::encode(text, base, char_length));
}
#[test]
fn test_anybase_decode() {
use crate::anybase;
let text = "meow mewo; mrrp mreow mrrp nyaaaa~ mreow mreow meow nyaaaa~; meow mrow meow mrrp mreow meow mrrp mewo".to_string();
let base = 10;
let char_length = anybase::char_length(base);
assert_eq!("i love cats", anybase::decode(text, base, char_length));
}