use crate::confidence::Confidence;
use crate::memory_kind::MemoryKindTag;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SourceKind {
Profile,
Observation,
SelfReport,
ParticipantReport,
Document,
Registry,
Policy,
AgentInstruction,
ExternalAuthority,
PendingVerification,
LibrarianAssignment,
}
impl SourceKind {
#[must_use]
pub const fn confidence_bound(self) -> Confidence {
match self {
Self::Observation | Self::Policy | Self::LibrarianAssignment => Confidence::ONE,
Self::Profile | Self::Registry | Self::AgentInstruction => Confidence::from_u16(62_258),
Self::SelfReport | Self::Document | Self::ExternalAuthority => {
Confidence::from_u16(58_982)
}
Self::ParticipantReport => Confidence::from_u16(55_705),
Self::PendingVerification => Confidence::from_u16(39_321),
}
}
#[must_use]
pub const fn admits(self, kind: MemoryKindTag) -> bool {
if matches!(kind, MemoryKindTag::Inferential) {
return false;
}
match self {
Self::Profile
| Self::Document
| Self::Registry
| Self::ExternalAuthority
| Self::LibrarianAssignment => matches!(kind, MemoryKindTag::Semantic),
Self::Observation | Self::SelfReport => {
matches!(kind, MemoryKindTag::Semantic | MemoryKindTag::Episodic)
}
Self::ParticipantReport => matches!(kind, MemoryKindTag::Episodic),
Self::Policy => matches!(kind, MemoryKindTag::Procedural),
Self::AgentInstruction => {
matches!(kind, MemoryKindTag::Procedural | MemoryKindTag::Semantic)
}
Self::PendingVerification => {
matches!(
kind,
MemoryKindTag::Semantic | MemoryKindTag::Episodic | MemoryKindTag::Procedural
)
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn inferential_admits_none() {
for kind in [
SourceKind::Profile,
SourceKind::Observation,
SourceKind::SelfReport,
SourceKind::ParticipantReport,
SourceKind::Document,
SourceKind::Registry,
SourceKind::Policy,
SourceKind::AgentInstruction,
SourceKind::ExternalAuthority,
SourceKind::PendingVerification,
SourceKind::LibrarianAssignment,
] {
assert!(
!kind.admits(MemoryKindTag::Inferential),
"{kind:?} must not admit Inferential"
);
}
}
#[test]
fn policy_admits_only_procedural() {
assert!(SourceKind::Policy.admits(MemoryKindTag::Procedural));
assert!(!SourceKind::Policy.admits(MemoryKindTag::Semantic));
assert!(!SourceKind::Policy.admits(MemoryKindTag::Episodic));
}
#[test]
fn pending_verification_bounded_at_point_six() {
let c = SourceKind::PendingVerification.confidence_bound();
assert!((c.as_f32() - 0.6).abs() < 1e-3);
}
#[test]
fn observation_is_fully_confident() {
assert_eq!(SourceKind::Observation.confidence_bound(), Confidence::ONE);
}
}