This Go package creates, collects, and validates a questionnaire. It defined some interfaces and structures to manage the questionnaire and answers.
- Is defined as the method
Create
that will create a questionnaire from a slice of the questionnaire. - Returns a Slice of the Questionnaire.
- Is defined as the method
Collect
that will collect the answers from a questionnaire. - Receive a slice of a questionnaire and return a slice of Answers and an error.
- Is defined as the method
Validate
that will validate the answers from a questionnaire. - Receive two slices of Answers (user answers and correct answers).
- Represents a question in a test with options for answers
- Fields:
Number
: The number of the question.Question
: The question.Options
: The options of the question.
- Represents an answer to a question, storing the answer of the user and status.
- Fields:
Number
: The number of the question.Answer
: The answer of the user.Status
: The status of the answer (correct or incorrect).
- Implements the interface
CreateQuestionnaire
through the methodCreate
. - Method
Create
:- Receives a slice of questions and returns a slice of the questionnaire.
- Iterated over the slice of the questionnaire and added a question and options to the slice test.
- Implements the interface
CollectAnswers
andValidateAnswers
through the methodsCollect
andValidate
. - Method
Collect
:- Receives a slice of the questionnaire and returns a slice of answers and an error.
- Create a questionnaire using
QuestionnaireService
. - Iterated the questionnaire and collected the answers from the user.
- Validate the answers using the function
validateOption
.
- Method
Validate
:- Receives two slices of answers (user answers and correct answers).
- Iterated the answers and validated the answers checking if the answer was correct or incorrect.
- Calculate the score of the user and return the score.
- Checking if the user's answer is valid to answer the question.
- Receives an answer from the user and validates if the answer is a string
- Returns
true
if the answer is between the valid options otherwise returnsfalse
.
- The questionnaire is created when using the method
Create
fromQuestionnaireService
- The answers are collected when using the method
Collect
fromAnswerService
- The answers are validated using the function
validateOption
- The answers are validated when using the method
Validate
fromAnswerService
- The results show up including the score count of answers and correct percentage.