behaviorsim-rs 0.7.0

Domain-agnostic specification for modeling individual psychology and social dynamics
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
//! Personality profile presets for quick entity creation.
//!
//! These profiles provide archetypical personality configurations
//! that can be used to quickly create entities with consistent
//! behavioral patterns.

use serde::{Deserialize, Serialize};

/// Preset personality archetypes for quick entity creation.
///
/// Each profile represents a common personality pattern with
/// predefined trait values. These are primarily used for humans
/// and can be adapted for high-social-complexity animals.
///
/// Profiles set initial base values for personality dimensions.
/// These can be further customized after creation.
///
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub enum PersonalityProfile {
    /// Average on all dimensions. A neutral baseline.
    #[default]
    Balanced,

    /// High neuroticism, high attachment anxiety.
    /// Prone to worry and relationship insecurity.
    Anxious,

    /// High avoidance, low extraversion.
    /// Prefers distance in relationships, values independence.
    Avoidant,

    /// High agreeableness, high empathy.
    /// Cooperative and caring toward others.
    Agreeable,

    /// High conscientiousness, high impulse control.
    /// Organized, disciplined, and goal-oriented.
    Conscientious,

    /// High neuroticism, low emotional stability.
    /// Prone to negative emotions and stress.
    Neurotic,

    /// High extraversion, high sociability.
    /// Outgoing, energetic, seeks social interaction.
    Extraverted,

    /// Low extraversion, high avoidance.
    /// Prefers solitude, introspective.
    Introverted,

    /// High extraversion, high conscientiousness, low neuroticism.
    /// Natural leader with confidence and organization.
    Leader,

    /// Low agreeableness, high reactance, low honesty-humility.
    /// Challenges authority, independent-minded.
    Rebel,
}

impl PersonalityProfile {
    /// Returns the extraversion value for this profile (0.0-1.0).
    ///
    /// Higher values indicate more outgoing, energetic personality.
    #[must_use]
    pub const fn extraversion(&self) -> f32 {
        match self {
            PersonalityProfile::Balanced => 0.5,
            PersonalityProfile::Anxious => 0.4,
            PersonalityProfile::Avoidant => 0.3,
            PersonalityProfile::Agreeable => 0.5,
            PersonalityProfile::Conscientious => 0.5,
            PersonalityProfile::Neurotic => 0.4,
            PersonalityProfile::Extraverted => 0.8,
            PersonalityProfile::Introverted => 0.2,
            PersonalityProfile::Leader => 0.8,
            PersonalityProfile::Rebel => 0.5,
        }
    }

    /// Returns the agreeableness value for this profile (0.0-1.0).
    ///
    /// Higher values indicate more cooperative, trusting personality.
    #[must_use]
    pub const fn agreeableness(&self) -> f32 {
        match self {
            PersonalityProfile::Balanced => 0.5,
            PersonalityProfile::Anxious => 0.6,
            PersonalityProfile::Avoidant => 0.4,
            PersonalityProfile::Agreeable => 0.8,
            PersonalityProfile::Conscientious => 0.5,
            PersonalityProfile::Neurotic => 0.4,
            PersonalityProfile::Extraverted => 0.6,
            PersonalityProfile::Introverted => 0.5,
            PersonalityProfile::Leader => 0.5,
            PersonalityProfile::Rebel => 0.2,
        }
    }

    /// Returns the conscientiousness value for this profile (0.0-1.0).
    ///
    /// Higher values indicate more organized, disciplined personality.
    #[must_use]
    pub const fn conscientiousness(&self) -> f32 {
        match self {
            PersonalityProfile::Balanced => 0.5,
            PersonalityProfile::Anxious => 0.5,
            PersonalityProfile::Avoidant => 0.5,
            PersonalityProfile::Agreeable => 0.5,
            PersonalityProfile::Conscientious => 0.8,
            PersonalityProfile::Neurotic => 0.4,
            PersonalityProfile::Extraverted => 0.5,
            PersonalityProfile::Introverted => 0.6,
            PersonalityProfile::Leader => 0.8,
            PersonalityProfile::Rebel => 0.3,
        }
    }

    /// Returns the neuroticism value for this profile (0.0-1.0).
    ///
    /// Higher values indicate more prone to negative emotions and stress.
    #[must_use]
    pub const fn neuroticism(&self) -> f32 {
        match self {
            PersonalityProfile::Balanced => 0.5,
            PersonalityProfile::Anxious => 0.8,
            PersonalityProfile::Avoidant => 0.4,
            PersonalityProfile::Agreeable => 0.4,
            PersonalityProfile::Conscientious => 0.4,
            PersonalityProfile::Neurotic => 0.8,
            PersonalityProfile::Extraverted => 0.3,
            PersonalityProfile::Introverted => 0.5,
            PersonalityProfile::Leader => 0.2,
            PersonalityProfile::Rebel => 0.5,
        }
    }

    /// Returns the openness value for this profile (0.0-1.0).
    ///
    /// Higher values indicate more open to new experiences and ideas.
    #[must_use]
    pub const fn openness(&self) -> f32 {
        match self {
            PersonalityProfile::Balanced => 0.5,
            PersonalityProfile::Anxious => 0.4,
            PersonalityProfile::Avoidant => 0.5,
            PersonalityProfile::Agreeable => 0.5,
            PersonalityProfile::Conscientious => 0.4,
            PersonalityProfile::Neurotic => 0.5,
            PersonalityProfile::Extraverted => 0.6,
            PersonalityProfile::Introverted => 0.6,
            PersonalityProfile::Leader => 0.6,
            PersonalityProfile::Rebel => 0.7,
        }
    }

    /// Returns the honesty-humility value for this profile (0.0-1.0).
    ///
    /// Higher values indicate more sincere, fair, modest personality.
    /// This is the sixth factor in the HEXACO model.
    #[must_use]
    pub const fn honesty_humility(&self) -> f32 {
        match self {
            PersonalityProfile::Balanced => 0.5,
            PersonalityProfile::Anxious => 0.5,
            PersonalityProfile::Avoidant => 0.5,
            PersonalityProfile::Agreeable => 0.6,
            PersonalityProfile::Conscientious => 0.6,
            PersonalityProfile::Neurotic => 0.5,
            PersonalityProfile::Extraverted => 0.5,
            PersonalityProfile::Introverted => 0.6,
            PersonalityProfile::Leader => 0.5,
            PersonalityProfile::Rebel => 0.3,
        }
    }

    /// Returns a human-readable name for this profile.
    #[must_use]
    pub const fn name(&self) -> &'static str {
        match self {
            PersonalityProfile::Balanced => "Balanced",
            PersonalityProfile::Anxious => "Anxious",
            PersonalityProfile::Avoidant => "Avoidant",
            PersonalityProfile::Agreeable => "Agreeable",
            PersonalityProfile::Conscientious => "Conscientious",
            PersonalityProfile::Neurotic => "Neurotic",
            PersonalityProfile::Extraverted => "Extraverted",
            PersonalityProfile::Introverted => "Introverted",
            PersonalityProfile::Leader => "Leader",
            PersonalityProfile::Rebel => "Rebel",
        }
    }

    /// Returns a brief description of this profile.
    #[must_use]
    pub const fn description(&self) -> &'static str {
        match self {
            PersonalityProfile::Balanced => "Average on all dimensions",
            PersonalityProfile::Anxious => "High worry and relationship insecurity",
            PersonalityProfile::Avoidant => "Prefers distance in relationships",
            PersonalityProfile::Agreeable => "Cooperative and caring toward others",
            PersonalityProfile::Conscientious => "Organized, disciplined, goal-oriented",
            PersonalityProfile::Neurotic => "Prone to negative emotions and stress",
            PersonalityProfile::Extraverted => "Outgoing, energetic, social",
            PersonalityProfile::Introverted => "Prefers solitude, introspective",
            PersonalityProfile::Leader => "Confident, organized, low anxiety",
            PersonalityProfile::Rebel => "Challenges authority, independent-minded",
        }
    }

    /// Returns all personality profiles.
    #[must_use]
    pub const fn all() -> [PersonalityProfile; 10] {
        [
            PersonalityProfile::Balanced,
            PersonalityProfile::Anxious,
            PersonalityProfile::Avoidant,
            PersonalityProfile::Agreeable,
            PersonalityProfile::Conscientious,
            PersonalityProfile::Neurotic,
            PersonalityProfile::Extraverted,
            PersonalityProfile::Introverted,
            PersonalityProfile::Leader,
            PersonalityProfile::Rebel,
        ]
    }
}

impl std::fmt::Display for PersonalityProfile {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.name())
    }
}

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

    #[test]
    fn balanced_is_neutral() {
        let profile = PersonalityProfile::Balanced;
        assert!((profile.extraversion() - 0.5).abs() < f32::EPSILON);
        assert!((profile.agreeableness() - 0.5).abs() < f32::EPSILON);
        assert!((profile.conscientiousness() - 0.5).abs() < f32::EPSILON);
        assert!((profile.neuroticism() - 0.5).abs() < f32::EPSILON);
        assert!((profile.openness() - 0.5).abs() < f32::EPSILON);
        assert!((profile.honesty_humility() - 0.5).abs() < f32::EPSILON);
    }

    #[test]
    fn anxious_has_high_neuroticism() {
        let profile = PersonalityProfile::Anxious;
        assert!(profile.neuroticism() > 0.7);
    }

    #[test]
    fn leader_has_low_neuroticism_high_extraversion() {
        let profile = PersonalityProfile::Leader;
        assert!(profile.neuroticism() < 0.3);
        assert!(profile.extraversion() > 0.7);
        assert!(profile.conscientiousness() > 0.7);
    }

    #[test]
    fn rebel_has_low_agreeableness_and_honesty() {
        let profile = PersonalityProfile::Rebel;
        assert!(profile.agreeableness() < 0.3);
        assert!(profile.honesty_humility() < 0.4);
    }

    #[test]
    fn introverted_has_low_extraversion() {
        let profile = PersonalityProfile::Introverted;
        assert!(profile.extraversion() < 0.3);
    }

    #[test]
    fn all_values_in_valid_range() {
        for profile in PersonalityProfile::all() {
            assert!(profile.extraversion() >= 0.0 && profile.extraversion() <= 1.0);
            assert!(profile.agreeableness() >= 0.0 && profile.agreeableness() <= 1.0);
            assert!(profile.conscientiousness() >= 0.0 && profile.conscientiousness() <= 1.0);
            assert!(profile.neuroticism() >= 0.0 && profile.neuroticism() <= 1.0);
            assert!(profile.openness() >= 0.0 && profile.openness() <= 1.0);
            assert!(profile.honesty_humility() >= 0.0 && profile.honesty_humility() <= 1.0);
        }
    }

    #[test]
    fn all_profiles() {
        let profiles = PersonalityProfile::all();
        assert_eq!(profiles.len(), 10);
    }

    #[test]
    fn display_format() {
        assert_eq!(format!("{}", PersonalityProfile::Balanced), "Balanced");
        assert_eq!(format!("{}", PersonalityProfile::Leader), "Leader");
    }

    #[test]
    fn default_is_balanced() {
        assert_eq!(PersonalityProfile::default(), PersonalityProfile::Balanced);
    }

    #[test]
    fn name_and_description() {
        let profile = PersonalityProfile::Anxious;
        assert_eq!(profile.name(), "Anxious");
        assert!(!profile.description().is_empty());
    }

    #[test]
    fn equality_and_hash() {
        use std::collections::HashSet;

        assert_eq!(PersonalityProfile::Leader, PersonalityProfile::Leader);
        assert_ne!(PersonalityProfile::Leader, PersonalityProfile::Rebel);

        let mut set = HashSet::new();
        set.insert(PersonalityProfile::Leader);
        set.insert(PersonalityProfile::Leader);
        assert_eq!(set.len(), 1);
    }

    #[test]
    fn copy_and_clone() {
        let original = PersonalityProfile::Anxious;
        let copied = original;
        let cloned = original.clone();

        assert_eq!(original, copied);
        assert_eq!(original, cloned);
    }

    #[test]
    fn all_profiles_have_names() {
        for profile in PersonalityProfile::all() {
            assert!(!profile.name().is_empty());
        }
    }

    #[test]
    fn all_profiles_have_descriptions() {
        for profile in PersonalityProfile::all() {
            assert!(!profile.description().is_empty());
        }
    }

    #[test]
    fn avoidant_profile() {
        let profile = PersonalityProfile::Avoidant;
        assert!(profile.extraversion() < 0.4);
        assert_eq!(profile.name(), "Avoidant");
    }

    #[test]
    fn agreeable_profile() {
        let profile = PersonalityProfile::Agreeable;
        assert!(profile.agreeableness() > 0.7);
        assert_eq!(profile.name(), "Agreeable");
    }

    #[test]
    fn conscientious_profile() {
        let profile = PersonalityProfile::Conscientious;
        assert!(profile.conscientiousness() > 0.7);
        assert_eq!(profile.name(), "Conscientious");
    }

    #[test]
    fn neurotic_profile() {
        let profile = PersonalityProfile::Neurotic;
        assert!(profile.neuroticism() > 0.7);
        assert_eq!(profile.name(), "Neurotic");
    }

    #[test]
    fn extraverted_profile() {
        let profile = PersonalityProfile::Extraverted;
        assert!(profile.extraversion() > 0.7);
        assert_eq!(profile.name(), "Extraverted");
    }

    #[test]
    fn all_profiles_trait_values() {
        // Exercise all trait methods for all profiles
        for profile in PersonalityProfile::all() {
            let _ = profile.extraversion();
            let _ = profile.agreeableness();
            let _ = profile.conscientiousness();
            let _ = profile.neuroticism();
            let _ = profile.openness();
            let _ = profile.honesty_humility();
        }
    }

    #[test]
    fn debug_format() {
        let profile = PersonalityProfile::Leader;
        let debug = format!("{:?}", profile);
        assert!(debug.contains("Leader"));
    }
}