behaviorsim-rs 0.7.0

Domain-agnostic specification for modeling individual psychology and social dynamics
Documentation
//! Demand characteristics: observable traits that shape social responses.

use crate::enums::{ApparentGender, ApparentRace, VisibleTrait};
use serde::{Deserialize, Serialize};

/// Observable characteristics that influence how others respond.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DemandCharacteristics {
    age_years: u8,
    apparent_gender: ApparentGender,
    apparent_race: ApparentRace,
    visible_traits: Vec<VisibleTrait>,
}

impl DemandCharacteristics {
    /// Creates a new demand characteristics profile.
    #[must_use]
    pub fn new(
        age_years: u8,
        apparent_gender: ApparentGender,
        apparent_race: ApparentRace,
        visible_traits: Vec<VisibleTrait>,
    ) -> Self {
        DemandCharacteristics {
            age_years,
            apparent_gender,
            apparent_race,
            visible_traits,
        }
    }

    /// Returns the apparent age in years.
    #[must_use]
    pub fn age_years(&self) -> u8 {
        self.age_years
    }

    /// Returns the apparent gender presentation.
    #[must_use]
    pub fn apparent_gender(&self) -> ApparentGender {
        self.apparent_gender
    }

    /// Returns the apparent racialization.
    #[must_use]
    pub fn apparent_race(&self) -> ApparentRace {
        self.apparent_race
    }

    /// Returns visible traits.
    #[must_use]
    pub fn visible_traits(&self) -> &[VisibleTrait] {
        &self.visible_traits
    }
}

impl Default for DemandCharacteristics {
    fn default() -> Self {
        DemandCharacteristics {
            age_years: 0,
            apparent_gender: ApparentGender::Unknown,
            apparent_race: ApparentRace::Unknown,
            visible_traits: Vec::new(),
        }
    }
}

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

    #[test]
    fn demand_characteristics_accessors() {
        let demand = DemandCharacteristics::new(
            12,
            ApparentGender::Female,
            ApparentRace::Marginalized,
            vec![VisibleTrait::StigmatizedAppearance],
        );

        assert_eq!(demand.age_years(), 12);
        assert_eq!(demand.apparent_gender(), ApparentGender::Female);
        assert_eq!(demand.apparent_race(), ApparentRace::Marginalized);
        assert_eq!(demand.visible_traits(), &[VisibleTrait::StigmatizedAppearance]);
    }
}