Skip to content

Commit

Permalink
feat: update tests and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ChieloNewctle committed Oct 26, 2023
1 parent 2748dc6 commit 177b39d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ jobs:
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo build --verbose
- run: cargo test --verbose
- run: cargo build --all-features --verbose
- run: cargo test --all-features --verbose
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
//! ```
//!
//! ```rust
//! # #[cfg(feature = "trie")] {
//! use general_sam::{sam::GeneralSAM, trie::Trie};
//!
//! let mut trie = Trie::default();
Expand All @@ -82,6 +83,7 @@
//!
//! assert!(!sam.get_root_state().feed_chars("bye").is_accepting());
//! assert!(sam.get_root_state().feed_chars("bye").is_nil());
//! # }
//! ```
//!
//! # References
Expand Down
26 changes: 19 additions & 7 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use rand::{
distributions::{Alphanumeric, DistString},
rngs::StdRng,
Rng, SeedableRng,
};

use crate::{sam::GeneralSAM, trie::Trie, SAM_ROOT_NODE_ID};
use crate::sam::GeneralSAM;

#[test]
fn test_example_from_chars() {
Expand Down Expand Up @@ -40,8 +34,11 @@ fn test_example_from_bytes() {
assert!(!state.is_accepting() && state.is_nil() && !state.is_root());
}

#[cfg(feature = "trie")]
#[test]
fn test_example_from_trie() {
use crate::trie::Trie;

let mut trie = Trie::default();

trie.insert_iter("hello".chars());
Expand Down Expand Up @@ -120,7 +117,10 @@ fn test_chinese_chars() {
println!("state \"你好\": {:?}", state.node_id);
}

#[cfg(feature = "trie")]
fn test_trie_suffix(vocab: &[&str]) {
use crate::trie::Trie;

let mut trie = Trie::default();
vocab.iter().for_each(|word| {
trie.insert_iter(word.chars());
Expand Down Expand Up @@ -160,20 +160,32 @@ fn test_trie_suffix(vocab: &[&str]) {
});
}

#[cfg(feature = "trie")]
#[test]
fn test_chiense_trie_suffix() {
let vocab = ["歌曲", "聆听歌曲", "播放歌曲", "歌词", "查看歌词"];
test_trie_suffix(&vocab);
}

#[cfg(feature = "trie")]
#[test]
fn test_simple_trie_suffix() {
let vocab = ["ac", "bb", "b", "cc", "aabb", "a", "ba", "c", "aa"];
test_trie_suffix(&vocab);
}

#[cfg(feature = "trie")]
#[test]
fn test_topo_and_suf_len_sorted_order() {
use rand::{
distributions::{Alphanumeric, DistString},
rngs::StdRng,
Rng, SeedableRng,
};

use crate::trie::Trie;
use crate::SAM_ROOT_NODE_ID;

let mut rng = StdRng::seed_from_u64(1134759173975);
for _ in 0..10000 {
let mut trie = Trie::default();
Expand Down

0 comments on commit 177b39d

Please sign in to comment.