Skip to content

Commit

Permalink
fixed ConstFst ffi Trs iterator (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasDepoixSonos authored Aug 16, 2024
1 parent 914e167 commit f42e789
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion rustfst/src/trs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<W: Semiring> Trs<W> for TrsConst<W> {
}

fn to_trs_vec(&self) -> TrsVec<W> {
TrsVec(Arc::clone(&self.trs))
TrsVec(Arc::new(self.trs().to_vec()))
}

// Doesn't clone the data, only the Arc
Expand Down Expand Up @@ -116,3 +116,31 @@ impl<W: Semiring> Default for TrsConst<W> {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

mod test_trs_const {
use super::*;
use crate::prelude::TropicalWeight;
use anyhow::Result;

#[test]
fn test_to_trs_vec() -> Result<()> {
let trs = TrsConst {
trs: Arc::new(vec![
Tr::<TropicalWeight>::new(1, 1, TropicalWeight::one(), 0),
Tr::<TropicalWeight>::new(1, 1, TropicalWeight::one(), 0),
]),
pos: 1,
n: 1,
};

let tr_vec = trs.to_trs_vec();
assert_eq!(tr_vec.len(), 1);

Ok(())
}
}
}

0 comments on commit f42e789

Please sign in to comment.