models_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package models
  2. import (
  3. "fmt"
  4. "reflect"
  5. "testing"
  6. "github.com/remogatto/prettytest"
  7. )
  8. type testSuite struct {
  9. prettytest.Suite
  10. }
  11. func TestRunner(t *testing.T) {
  12. prettytest.Run(
  13. t,
  14. new(testSuite),
  15. new(groupTestSuite),
  16. )
  17. }
  18. func (t *testSuite) TestQuizFromMarkdown() {
  19. markdown := `Question text (1).
  20. Question text (2).
  21. Question text with #tag1 #tag2 (3).
  22. * Answer 1
  23. * Answer 2
  24. * Answer 3
  25. * Answer 4`
  26. expectedQuiz := &Quiz{
  27. Question: &Question{Text: "Question text (1).\n\nQuestion text (2).\n\nQuestion text with #tag1 #tag2 (3)."},
  28. Answers: []*Answer{
  29. {Text: "Answer 1"},
  30. {Text: "Answer 2"},
  31. {Text: "Answer 3"},
  32. {Text: "Answer 4"},
  33. },
  34. CorrectPos: 0,
  35. }
  36. q := new(Quiz)
  37. err := MarkdownToQuiz(q, markdown)
  38. t.Nil(err, fmt.Sprintf("Quiz should be parsed without errors: %v", err))
  39. if !t.Failed() {
  40. t.True(reflect.DeepEqual(q, expectedQuiz), fmt.Sprintf("Expected %+v got %+v", expectedQuiz, q))
  41. }
  42. }
  43. func (t *testSuite) TestMarkdownFromQuiz() {
  44. quiz := &Quiz{
  45. Question: &Question{Text: "Newly created question text."},
  46. Answers: []*Answer{
  47. {Text: "Answer 1"},
  48. {Text: "Answer 2"},
  49. {Text: "Answer 3"},
  50. {Text: "Answer 4"},
  51. },
  52. CorrectPos: 0,
  53. }
  54. md, err := QuizToMarkdown(quiz)
  55. t.Nil(err, fmt.Sprintf("Conversion to markdown should not raise an error: %v", err))
  56. if !t.Failed() {
  57. t.Equal(`Newly created question text.
  58. * Answer 1
  59. * Answer 2
  60. * Answer 3
  61. * Answer 4
  62. `, md)
  63. }
  64. }
  65. func (t *testSuite) TestParticipantTokenMarshalCSV() {
  66. }