use serde::Deserialize;
use crate::hub::ModelFile;
#[derive(Clone, Debug, Deserialize)]
pub struct Siblings {
pub siblings: Vec<ModelFile>,
}
impl Siblings {
pub fn new(siblings: Vec<ModelFile>) -> Self {
Self { siblings }
}
pub fn get_sibling_names(&self) -> Vec<&'_ String> {
self.siblings.iter().map(|s| s.get_rfilename()).collect()
}
}
impl PartialEq for Siblings {
fn eq(&self, other: &Self) -> bool {
self.siblings == other.siblings
}
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_siblings_new() {
let siblings = vec![ModelFile::new(
"model.json".to_string(),
Some(1),
Some("123".to_string()),
)];
let siblings = Siblings::new(siblings);
assert_eq!(siblings.siblings.len(), 1);
}
#[test]
fn test_siblings_get_sibling_names() {
let siblings = vec![
ModelFile::new("model.json".to_string(), Some(1), Some("123".to_string())),
ModelFile::new("model2.json".to_string(), Some(1), Some("123".to_string())),
ModelFile::new("model3.json".to_string(), Some(1), Some("123".to_string())),
];
let siblings = Siblings::new(siblings);
let sibling_names = siblings.get_sibling_names();
assert_eq!(sibling_names.len(), 3);
assert_eq!(sibling_names[0], "model.json");
assert_eq!(sibling_names[1], "model2.json");
assert_eq!(sibling_names[2], "model3.json");
}
#[test]
fn test_siblings_partial_eq() {
let s1 = vec![ModelFile::new(
"model.json".to_string(),
Some(1),
Some("123".to_string()),
)];
let siblings = Siblings::new(s1);
let s2 = vec![ModelFile::new(
"model.json".to_string(),
Some(1),
Some("123".to_string()),
)];
let siblings2 = Siblings::new(s2);
assert_eq!(siblings, siblings2);
}
}