-
Notifications
You must be signed in to change notification settings - Fork 82
/
exercises.rb
124 lines (116 loc) · 3.86 KB
/
exercises.rb
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
# == Schema Information
#
# Table name: exercises
#
# id :integer not null, primary key
# experience :integer not null
# is_public :boolean default(FALSE), not null
# name :string(255)
# question_type :integer not null
# versions :integer
# created_at :datetime
# updated_at :datetime
# current_version_id :integer
# exercise_collection_id :integer
# exercise_family_id :integer
# external_id :string(255)
# irt_data_id :integer
#
# Indexes
#
# exercises_irt_data_id_fk (irt_data_id)
# index_exercises_on_exercise_collection_id (exercise_collection_id)
# index_exercises_on_exercise_family_id (exercise_family_id)
# index_exercises_on_external_id (external_id) UNIQUE
# index_exercises_on_is_public (is_public)
#
# Foreign Keys
#
# exercises_exercise_family_id_fk (exercise_family_id => exercise_families.id)
# exercises_irt_data_id_fk (irt_data_id => irt_data.id)
#
FactoryBot.define do
sequence :exercise_no, 1
factory :exercise do
transient do
num { generate :exercise_no }
end
external_id { 'E' + ('a'..'z').to_a.shuffle[0,8].join } # use a random string
name { 'Factorial ' + num.to_s }
question_type { Exercise::Q_CODING }
is_public { true }
experience { 50 }
# tags: Java, factorial, multiplication, function
factory :coding_exercise do
transient do
creator_id { 1 }
question { "Write a function in Java called `factorial()` that will "\
"take a\npositive integer as input and returns its factorial as "\
"output.\n" }
feedback { "Explanation for the correct answer goes here. This is "\
"just\nan example.\n" }
class_name { 'Factorial' }
method_name { 'factorial' }
starter_code { "public int factorial(int n)\n"\
"{\n"\
" ___\n"\
"}\n" }
wrapper_code { "public class Factorial\n"\
"{\n"\
" ___\n"\
"}\n" }
test_script { ""\
"0,1\n"\
"1,1\n"\
"2,2\n"\
"3,6\n"\
"4,24,hidden\n"\
"5,120,hidden\n" }
end
question_type { Exercise::Q_CODING }
language_list { 'Java' }
tag_list { 'factorial, function, multiplication' }
style_list { 'code writing' }
after :create do |e, v|
e.current_version = FactoryBot.create :exercise_version,
exercise: e,
creator_id: v.creator_id
e.exercise_versions << e.current_version
FactoryBot.create :coding_prompt,
exercise_version: e.current_version,
question: v.question,
feedback: v.feedback,
class_name: v.class_name,
method_name: v.method_name,
starter_code: v.starter_code,
wrapper_code: v.wrapper_code,
test_script: v.test_script
e.save!
end
end
factory :mc_exercise do
transient do
creator_id { 2 }
question { "This is a sample multiple choice question. It has only "\
"one correct answer.\n" }
feedback { "Explanation for the correct answer goes here. This is "\
"just\nan example.\n" }
end
name { 'Pick One ' + num.to_s }
question_type { Exercise::Q_MC }
tag_list { 'random' }
style_list { 'forced choice' }
after :create do |e, v|
e.current_version = FactoryBot.create :exercise_version,
exercise: e,
creator_id: v.creator_id
e.exercise_versions << e.current_version
FactoryBot.create :mc_with_choices,
exercise_version: e.current_version,
question: v.question,
feedback: v.feedback
e.save!
end
end
end
end