Skip to content

Latest commit

 

History

History
82 lines (55 loc) · 3.31 KB

questionarie.md

File metadata and controls

82 lines (55 loc) · 3.31 KB

This Go package creates, collects, and validates a questionnaire. It defined some interfaces and structures to manage the questionnaire and answers.

Interfaces

  • 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).

Structures

  • 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 method Create.
  • 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 and ValidateAnswers through the methods Collect and Validate.
  • 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.

Auxiliary Functions

  • 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 returns false.

How it works

1. Creates Questionnaire

  • The questionnaire is created when using the method Create from QuestionnaireService

2. Collect the Answers

  • The answers are collected when using the method Collect from AnswerService
  • The answers are validated using the function validateOption

3. Validate the Answers

  • The answers are validated when using the method Validate from AnswerService
  • The results show up including the score count of answers and correct percentage.