@@ -5,17 +5,13 @@ use super::dto::{
5
5
execute_code_for_question:: { ExecuteCodeForQuestionOutput , TestCaseStatus } ,
6
6
} ,
7
7
queries:: {
8
- class_details:: ClassDetailsOutput ,
9
- question_details:: QuestionDetailsOutput ,
10
- test_case:: { TestCase , TestCaseUnit } ,
8
+ class_details:: ClassDetailsOutput , question_details:: QuestionDetailsOutput ,
9
+ test_case:: TestCaseInput ,
11
10
} ,
12
11
} ;
13
- use crate :: {
14
- farem:: {
15
- dto:: mutations:: execute_code:: { ExecuteCodeError , ExecuteCodeErrorStep } ,
16
- service:: { FaremService , SupportedLanguage } ,
17
- } ,
18
- utils:: case_unit_to_argument,
12
+ use crate :: farem:: {
13
+ dto:: mutations:: execute_code:: { ExecuteCodeError , ExecuteCodeErrorStep } ,
14
+ service:: { FaremService , SupportedLanguage } ,
19
15
} ;
20
16
use async_trait:: async_trait;
21
17
use auth:: validate_user_role;
@@ -24,7 +20,6 @@ use edgedb_tokio::Client as DbClient;
24
20
use rand:: { distributions:: Alphanumeric , Rng } ;
25
21
use slug:: slugify;
26
22
use std:: sync:: Arc ;
27
- use strum:: IntoEnumIterator ;
28
23
use utilities:: { graphql:: ApiError , models:: IdObject , users:: AccountType } ;
29
24
use uuid:: Uuid ;
30
25
@@ -38,29 +33,16 @@ const CREATE_CLASS: &str =
38
33
include_str ! ( "../../../../libs/main-db/edgeql/learning/create-class.edgeql" ) ;
39
34
const CREATE_QUESTION : & str =
40
35
include_str ! ( "../../../../libs/main-db/edgeql/learning/create-question.edgeql" ) ;
41
- const INSERT_NUMBER_COLLECTION_UNIT : & str = include_str ! (
42
- "../../../../libs/main-db/edgeql/learning/test-cases/number-collection-unit.edgeql"
43
- ) ;
44
- const INSERT_NUMBER_UNIT : & str =
45
- include_str ! ( "../../../../libs/main-db/edgeql/learning/test-cases/number-unit.edgeql" ) ;
46
- const INSERT_STRING_UNIT : & str =
47
- include_str ! ( "../../../../libs/main-db/edgeql/learning/test-cases/string-unit.edgeql" ) ;
48
- const INSERT_STRING_COLLECTION_UNIT : & str = include_str ! (
49
- "../../../../libs/main-db/edgeql/learning/test-cases/string-collection-unit.edgeql"
36
+ const INSERT_TEST_CASE_DATA : & str = include_str ! (
37
+ "../../../../libs/main-db/edgeql/learning/test-cases/insert-test-case-data.edgeql"
50
38
) ;
51
- const INSERT_INPUT_CASE_UNIT : & str =
52
- include_str ! ( "../../../../libs/main-db/edgeql/learning/test-cases/input-case-unit.edgeql" ) ;
53
- const INSERT_OUTPUT_CASE_UNIT : & str =
54
- include_str ! ( "../../../../libs/main-db/edgeql/learning/test-cases/output-case-unit.edgeql" ) ;
55
39
const INSERT_TEST_CASE : & str =
56
40
include_str ! ( "../../../../libs/main-db/edgeql/learning/test-cases/test-case.edgeql" ) ;
57
41
const UPDATE_QUESTION : & str =
58
42
include_str ! ( "../../../../libs/main-db/edgeql/learning/test-cases/update-question.edgeql" ) ;
59
43
60
44
#[ async_trait]
61
45
pub trait LearningServiceTrait : Sync + Send {
62
- fn test_case_units ( & self ) -> Vec < TestCaseUnit > ;
63
-
64
46
async fn class_details < ' a > ( & self , class_id : Uuid ) -> Result < ClassDetailsOutput , ApiError > ;
65
47
66
48
async fn question_details < ' a > (
@@ -82,7 +64,7 @@ pub trait LearningServiceTrait: Sync + Send {
82
64
account_type : & AccountType ,
83
65
name : & ' a str ,
84
66
problem : & ' a str ,
85
- test_cases : & [ TestCase ] ,
67
+ test_cases : & [ TestCaseInput ] ,
86
68
class_ids : & [ Uuid ] ,
87
69
) -> Result < CreateQuestionOutput , ApiError > ;
88
70
@@ -112,10 +94,6 @@ impl LearningService {}
112
94
113
95
#[ async_trait]
114
96
impl LearningServiceTrait for LearningService {
115
- fn test_case_units ( & self ) -> Vec < TestCaseUnit > {
116
- TestCaseUnit :: iter ( ) . collect ( )
117
- }
118
-
119
97
async fn class_details < ' a > ( & self , class_id : Uuid ) -> Result < ClassDetailsOutput , ApiError > {
120
98
self . db_conn
121
99
. query_required_single :: < ClassDetailsOutput , _ > ( CLASS_DETAILS , & ( class_id, ) )
@@ -169,7 +147,7 @@ impl LearningServiceTrait for LearningService {
169
147
account_type : & AccountType ,
170
148
name : & ' a str ,
171
149
problem : & ' a str ,
172
- test_cases : & [ TestCase ] ,
150
+ test_cases : & [ TestCaseInput ] ,
173
151
class_ids : & [ Uuid ] ,
174
152
) -> Result < CreateQuestionOutput , ApiError > {
175
153
validate_user_role ( & AccountType :: Teacher , account_type) ?;
@@ -216,47 +194,27 @@ impl LearningServiceTrait for LearningService {
216
194
. to_string ( ) ,
217
195
}
218
196
} ) ?;
219
- fn get_insert_ql ( test_case : & TestCaseUnit ) -> & ' static str {
220
- match test_case {
221
- TestCaseUnit :: Number => INSERT_NUMBER_UNIT ,
222
- TestCaseUnit :: NumberCollection => INSERT_NUMBER_COLLECTION_UNIT ,
223
- TestCaseUnit :: String => INSERT_STRING_UNIT ,
224
- TestCaseUnit :: StringCollection => INSERT_STRING_COLLECTION_UNIT ,
225
- }
226
- }
227
197
let mut test_cases_to_associate = vec ! [ ] ;
228
198
for test_case in test_cases. iter ( ) {
229
199
let mut input_case_units = vec ! [ ] ;
230
200
let mut output_case_units = vec ! [ ] ;
231
201
for ( idx, input) in test_case. inputs . iter ( ) . enumerate ( ) {
232
- let insert_ql = get_insert_ql ( & input. data_type ) ;
233
- let case_unit = self
234
- . db_conn
235
- . query_required_single :: < IdObject , _ > ( insert_ql, & ( & input. data , ) )
236
- . await
237
- . unwrap ( ) ;
238
202
let input_case_unit = self
239
203
. db_conn
240
204
. query_required_single :: < IdObject , _ > (
241
- INSERT_INPUT_CASE_UNIT ,
242
- & ( & input . name , idx as i32 , case_unit . id ) ,
205
+ INSERT_TEST_CASE_DATA ,
206
+ & ( idx as i32 , input . data . clone ( ) ) ,
243
207
)
244
208
. await
245
209
. unwrap ( ) ;
246
210
input_case_units. push ( input_case_unit. id ) ;
247
211
}
248
212
for ( idx, output) in test_case. outputs . iter ( ) . enumerate ( ) {
249
- let insert_ql = get_insert_ql ( & output. data_type ) ;
250
- let case_unit = self
251
- . db_conn
252
- . query_required_single :: < IdObject , _ > ( insert_ql, & ( & output. data , ) )
253
- . await
254
- . unwrap ( ) ;
255
213
let output_case_unit = self
256
214
. db_conn
257
215
. query_required_single :: < IdObject , _ > (
258
- INSERT_OUTPUT_CASE_UNIT ,
259
- & ( idx as i32 , case_unit . id ) ,
216
+ INSERT_TEST_CASE_DATA ,
217
+ & ( idx as i32 , output . data . clone ( ) ) ,
260
218
)
261
219
. await
262
220
. unwrap ( ) ;
@@ -306,7 +264,7 @@ impl LearningServiceTrait for LearningService {
306
264
let arguments = test_case
307
265
. inputs
308
266
. iter ( )
309
- . map ( case_unit_to_argument )
267
+ . map ( |f| f . data . clone ( ) )
310
268
. collect :: < Vec < _ > > ( ) ;
311
269
let user_output = self
312
270
. farem_service
@@ -316,13 +274,15 @@ impl LearningServiceTrait for LearningService {
316
274
error : f,
317
275
step : ExecuteCodeErrorStep :: WasmExecution ,
318
276
} ) ?;
319
- let expected_output = test_case
277
+ let collected_expected_output = test_case
320
278
. outputs
321
279
. iter ( )
322
- . map ( case_unit_to_argument)
323
- . collect :: < Vec < _ > > ( )
324
- . join ( "\n " )
325
- + "\n " ;
280
+ . map ( |f| f. data . clone ( ) )
281
+ . collect :: < Vec < _ > > ( ) ;
282
+ let mut expected_output = collected_expected_output. join ( "\n " ) ;
283
+ if !collected_expected_output. is_empty ( ) {
284
+ expected_output += "\n " ;
285
+ }
326
286
outputs. push ( TestCaseStatus {
327
287
passed : user_output == expected_output,
328
288
user_output,
0 commit comments