-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathtest_alphabet.rs
37 lines (30 loc) · 1.05 KB
/
test_alphabet.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use algo::strings::{alphabet, Alphabet, Count};
const ABRA: &'static str = include_str!("../res/strings/abra.txt");
const PI: &'static str = include_str!("../res/strings/pi.txt");
#[test]
fn alphabet() {
let s = "NowIsTheTimeForAllGoodMen";
let encoded = alphabet::BASE64.to_indices(s);
let decoded = alphabet::BASE64.to_chars(&encoded);
assert_eq!(s, decoded);
let s = "AACGAACGGTTTACCCCG";
let encoded = alphabet::DNA.to_indices(s);
let decoded = alphabet::DNA.to_chars(&encoded);
assert_eq!(s, decoded);
let s = "01234567890123456789";
let encoded = alphabet::DECIMAL.to_indices(s);
let decoded = alphabet::DECIMAL.to_chars(&encoded);
assert_eq!(s, decoded);
}
#[test]
fn count() {
use std::convert::TryFrom;
let alphabet = Alphabet::try_from("ABCDR").unwrap();
let r = Count::compute(&alphabet, ABRA);
assert_eq!(vec![5, 2, 1, 1, 2], r);
let r = Count::compute(&alphabet::DECIMAL, PI);
assert_eq!(
vec![9999, 10137, 9908, 10026, 9971, 10026, 10028, 10025, 9978, 9902],
r
);
}