use crate::palette_data::CPK;
#[must_use]
pub fn cpk(atomic_num: u8) -> [u8; 3] {
CPK.get(atomic_num as usize).copied().unwrap_or(CPK[0])
}
#[cfg(test)]
mod tests {
use super::{cpk, CPK};
#[test]
fn 表长与元素表相同() {
assert_eq!(CPK.len(), omgkit_core::element::count());
}
#[test]
fn 锚点元素的颜色与各家文档一致() {
assert_eq!(cpk(1), [0xff, 0xff, 0xff], "H 白");
assert_eq!(cpk(6), [0x90, 0x90, 0x90], "C 灰");
assert_eq!(cpk(7), [0x30, 0x50, 0xf8], "N 蓝");
assert_eq!(cpk(8), [0xff, 0x0d, 0x0d], "O 红");
assert_eq!(cpk(15), [0xff, 0x80, 0x00], "P 橙");
assert_eq!(cpk(16), [0xff, 0xff, 0x30], "S 黄");
assert_eq!(cpk(17), [0x1f, 0xf0, 0x1f], "Cl 绿");
assert_eq!(cpk(35), [0xa6, 0x29, 0x29], "Br 暗红");
}
#[test]
fn 未知色只出现在表外() {
let unknown = [0xff, 0x14, 0x93];
for z in 1..=109u8 {
assert_ne!(cpk(z), unknown, "Z={z} 在 Jmol 表里,不该是未知色");
}
for z in 110..=118u8 {
assert_eq!(cpk(z), unknown, "Z={z} 不在 Jmol 表里");
}
assert_eq!(cpk(0), unknown, "通配原子不在表里");
}
#[test]
fn 越界的原子序数给未知色() {
assert_eq!(cpk(200), [0xff, 0x14, 0x93]);
assert_eq!(cpk(u8::MAX), [0xff, 0x14, 0x93]);
}
}