raads-r 0.1.1

raads-r library for testing and scoring
Documentation
use std::collections::VecDeque;

pub trait Scoring {
    fn score(&self, normative: bool) -> u8;
}

pub enum Answer {
    TrueOnlyWhenIWasYounger,
    TrueNowAndWhenIWasYoung,
    TrueOnlyNow,
    NeverTrue,
}

pub enum Subscale {
    CircumscribedInterests,
    SocialRelatedness,
    SensoryMotor,
    Language,
}

impl Scoring for Answer {
    fn score(&self, normative: bool) -> u8 {
        if normative {
            match self {
                Answer::TrueOnlyWhenIWasYounger => 1,
                Answer::TrueNowAndWhenIWasYoung => 0,
                Answer::TrueOnlyNow => 2,
                Answer::NeverTrue => 3,
            } 
        } else {
            match self {
                Answer::TrueOnlyWhenIWasYounger => 2,
                Answer::TrueNowAndWhenIWasYoung => 3,
                Answer::TrueOnlyNow => 1,
                Answer::NeverTrue => 0,
            }
        }
    }
}

#[derive(Debug)]
pub struct FinalScore {
    pub circumscribed_interests_subtotal: u8,
    pub social_relatedness_subtotal: u8,
    pub sensory_motor_subtotal: u8,
    pub language_subtotal: u8,
    pub total: u8,
}

pub struct Question {
    score: Option<Answer>,
    pub content: String,
    subscale: Subscale,
    normative: bool,
}

impl Question {
    fn new(content: impl Into<String>, normative: bool, subscale: Subscale) -> Self {
        Self {
            content: content.into(),
            score: None,
            normative,
            subscale,
        }
    }

    pub fn answer(&mut self, answer: Answer) {
        self.score = Some(answer);
    }
}

pub struct RaadsR {
    questions: VecDeque<Question>,
}

impl RaadsR {
    pub fn new() -> Self {
        let questions = vec![
            Question::new("I keep my thoughts stacked in my memory like they are on filing cards, and I pick out the ones I need by looking through the stack and finding the right one (or another unique way).", false, Subscale::CircumscribedInterests),
            Question::new("I keep lists of things that interest me, even when they have no practical use (for example sports statistics, train schedules, calendar dates, historical facts and dates).", false, Subscale::CircumscribedInterests),
            Question::new("When I am talking to someone, it is hard to change the subject. If the other person does so, I can get very upset and confused.", false, Subscale::CircumscribedInterests),
            Question::new("Sometimes I have to cover my ears to block out painful noises (like vacuum cleaners or people talking too much or too loudly).", false, Subscale::SensoryMotor),
            Question::new("I do certain things with my hands over and over again (like flapping, twirling sticks or strings, waving things by my eyes).", false, Subscale::SensoryMotor),
            Question::new("I am very sensitive to the way my clothes feel when I touch them. How they feel is more important to me than how they look.", false, Subscale::SensoryMotor),
            Question::new("Sometimes a thought or a subject gets stuck in my mind and I have to talk about it even if no one is interested.", false, Subscale::CircumscribedInterests),
            Question::new("If I am in a place where there are many smells, textures to feel, noises or bright lights, I feel anxious or frightened.", false, Subscale::SensoryMotor),
            Question::new("I get highly confused when someone interrupts me when I am talking about something I am very interested in.", false, Subscale::CircumscribedInterests),
            Question::new("Sometimes things that should feel painful are not (for instance when I hurt myself or burn my hand on the stove).", false, Subscale::SensoryMotor),
            Question::new("I like having conversation with serveral people, for instance around a dunner table, at school, or at work", true, Subscale::SocialRelatedness),
            Question::new("It is difficult for me to start and stop a conversation. I need to keep going until I am finished.", false, Subscale::CircumscribedInterests),
            Question::new("I like things to be exactly the same day after day and even small changes in my routines upset me.", false, Subscale::CircumscribedInterests),
            Question::new("I have been told that I have an unusual voice (for example flat, monotone, childish, or high-pitched).", false, Subscale::SensoryMotor),
            Question::new("When I go somewhere, I have to follow a familiar route or I can get very confused and upset.", false, Subscale::CircumscribedInterests),
            Question::new("When talking to someone, I have a hard time telling when it is my turn to talk or to listen.", false, Subscale::SocialRelatedness),
            Question::new("I get along with other people by following a set of specific rules that help me look normal.", false, Subscale::SocialRelatedness),
            Question::new("It can be very hard to read someone's face, hand and body movements when they are talking.", false, Subscale::SocialRelatedness),
            Question::new("The same thing (like clothes or temperatures) can feel very different to me at different times.", false, Subscale::SensoryMotor),
            Question::new("I have never been interested in what most of the people I know consider interesting.", false, Subscale::CircumscribedInterests),
            Question::new("I have never wanted or needed to have what other people call an 'intimate relationship.'", false, Subscale::SocialRelatedness),
            Question::new("Some ordinary textures that do not bother others feel very offensive when they touch my skin.", false, Subscale::SensoryMotor),
            Question::new("The same sound sometimes seems very loud or very soft, even though I know it has not changed.", false, Subscale::SensoryMotor),
            Question::new("I always notice how food feels in my mouth. This is more important to me than how it tastes.", false, Subscale::SensoryMotor),
            Question::new("It is difficult for me to understand how other people are feeling when we are talking.", false, Subscale::SocialRelatedness),
            Question::new("It can be very intimidating for me to talk to more than one person at the same time.", false, Subscale::SocialRelatedness),
            Question::new("I like to copy the way certain people speak and act. It helps me appear more normal.", false, Subscale::SocialRelatedness),
            Question::new("I have a hard time figuring out what some phrases mean, like 'you are the apple of my eye.'", false, Subscale::Language),
            Question::new("The same sound, color or texture can suddenly change from very sensitive to very dull.", false, Subscale::SensoryMotor),
            Question::new("It is very difficult for me to understand when someone is embarrassed or jealous.", false, Subscale::SocialRelatedness),
            Question::new("Sometimes I offend others by saying what I am thinking, even if I don't mean to.", false, Subscale::SocialRelatedness),
            Question::new("I try to be as helpful as I can when other people tell me their personal problems", true, Subscale::SocialRelatedness),
            Question::new("I get extremely upset when the way I like to do things is suddenly changed.", false, Subscale::CircumscribedInterests),
            Question::new("When I feel overwhelmed by my senses, I have to isolate myself to shut them down.", false, Subscale::SensoryMotor),
            Question::new("I'd rather go out to eat in a restaurant by myself than with someone I know.", false, Subscale::SocialRelatedness),
            Question::new("Sometimes the sound of a word or a high-pitched noise can be painful to my ears.", false, Subscale::SensoryMotor),
            Question::new("I do not connect with characters in movies and cannot feel what they feel.", false, Subscale::SocialRelatedness),
            Question::new("I can see in my mind in exact detail things that I am interested in.", false, Subscale::CircumscribedInterests),
            Question::new("I feel very comfortable dating or being in social situations with others", true, Subscale::SocialRelatedness),
            Question::new("I only like to think and talk about a few things that interest me.", false, Subscale::CircumscribedInterests),
            Question::new("I can't tolerate things I dislike (like smells, textures, sounds or colors).", false, Subscale::SensoryMotor),
            Question::new("I cannot tell if someone is interested or bored with what I am saying.", false, Subscale::SocialRelatedness),
            Question::new("It calms me to spin around or to rock in a chair when I'm feeling stressed.", false, Subscale::SensoryMotor),
            Question::new("I have to 'act normal' to please other people and make them like me.", false, Subscale::SocialRelatedness),
            Question::new("I enjoy spending time eating and talking with my family and friends", true, Subscale::SocialRelatedness),
            Question::new("I take things too literally, so I often miss what people are trying to say.", false, Subscale::Language),
            Question::new("I miss my best friends or family when we are apart for a long time", true, Subscale::SocialRelatedness),
            Question::new("I often use words and phrases from movies and television in conversations.", false, Subscale::Language),
            Question::new("The phrase, 'He wears his heart on his sleeve,' does not make sense to me.", false, Subscale::Language),
            Question::new("Sometimes I talk too loudly or too softly, and I am not aware of it.", false, Subscale::SensoryMotor),
            Question::new("I can tell when someone says one thing but means something else", true, Subscale::SocialRelatedness),
            Question::new("I only like to talk to people who share my special interests.", false, Subscale::SocialRelatedness),
            Question::new("It is difficult to figure out what other people expect of me.", false, Subscale::SocialRelatedness),
            Question::new("It is very difficult for me to work and function in groups.", false, Subscale::SocialRelatedness),
            Question::new("I am often surprised when others tell me I have been rude.", false, Subscale::SocialRelatedness),
            Question::new("The phrase 'I've got you under my skin' makes me uncomfortable.", false, Subscale::Language),
            Question::new("I focus on details rather than the overall idea.", false, Subscale::CircumscribedInterests),
            Question::new("How to make friends and socialize is a mystery to me.", false, Subscale::SocialRelatedness),
            Question::new("I often don't know how to act in social situations.", false, Subscale::SocialRelatedness),
            Question::new("I am often told that I ask embarrassing questions.", false, Subscale::SocialRelatedness),
            Question::new("I am considered a loner by those who know me best.", false, Subscale::SocialRelatedness),
            Question::new("I cannot imagine what it would be like to be someone else.", false, Subscale::Language),
            Question::new("People tell me that I give too much detail.", false, Subscale::CircumscribedInterests),
            Question::new("I cannot tell when someone is flirting with me.", false, Subscale::SocialRelatedness),
            Question::new("I have been told that I am clumsy or uncoordinated.", false, Subscale::SensoryMotor),
            Question::new("I am considered a compassionate type of person", true, Subscale::SocialRelatedness),
            Question::new("I understand when friends need to be comforted", true, Subscale::SocialRelatedness),
            Question::new("I tend to point out other people's mistakes.", false, Subscale::SocialRelatedness),
            Question::new("I can 'put myself in other people's shoes'", true, Subscale::SocialRelatedness),
            Question::new("I like to talk things over with my friends", true, Subscale::SocialRelatedness),
            Question::new("Meeting new people is usually easy for me", true, Subscale::SocialRelatedness),
            Question::new("I like to be by myself as much as I can.", false, Subscale::SocialRelatedness),
            Question::new("Others consider me odd or different.", false, Subscale::SocialRelatedness),
            Question::new("I am an understanding type of person", true, Subscale::SocialRelatedness),
            Question::new("I can chat and make small talk with people", true, Subscale::Language),
            Question::new("I don't like to be hugged or held.", false, Subscale::SensoryMotor),
            Question::new("I like to have close friends", true, Subscale::SocialRelatedness),
            Question::new("I usually speak in a normal tone", true, Subscale::SensoryMotor),
            Question::new("I am a sympathetic person", true, Subscale::SocialRelatedness), 
            Question::new("I speak with a normal rythm", true, Subscale::SensoryMotor),
        ];

        assert_eq!(questions.len(), 80);

        let dec = VecDeque::from(questions);

        Self {
            questions: dec,
        }
    }

    pub fn score(questions: Vec<Question>) -> FinalScore {
        let mut final_score = FinalScore {
            circumscribed_interests_subtotal: 0,
            social_relatedness_subtotal: 0,
            sensory_motor_subtotal: 0,
            language_subtotal: 0,
            total: 0,
        };

        final_score.total = questions.iter().fold(0 as u8, |attr, a| {
            attr + match &a.score {
                Some(x) => {
                    let score = x.score(a.normative);

                    match a.subscale {
                        Subscale::CircumscribedInterests => final_score.circumscribed_interests_subtotal += score,
                        Subscale::SocialRelatedness => final_score.social_relatedness_subtotal += score,
                        Subscale::SensoryMotor => final_score.sensory_motor_subtotal += score,
                        Subscale::Language => final_score.language_subtotal += score,
                    }

                    score
                },
                None => 0,
            }
        });

        final_score
    }

    pub fn reádd_front(&mut self, question: Question) {
        self.questions.push_front(question)
    }

    pub fn reádd_back(&mut self, question: Question) {
        self.questions.push_back(question)
    }
}

impl Iterator for RaadsR {
    type Item = Question;

    fn next(&mut self) -> Option<Self::Item> {
        self.questions.pop_front()
    }
}

#[cfg(test)]
mod tests {
    use crate::RaadsR;

    #[test]
    fn raads_r_eighty() {
        RaadsR::new();
    }
}