@@ -202,7 +202,7 @@ pub fn generate_hint<'a>(input: &str) -> &'a Hint<'a> {
202
202
}
203
203
}
204
204
205
- fn get_last_term ( chars : & [ char ] ) -> String {
205
+ pub fn get_last_term ( chars : & [ char ] ) -> String {
206
206
assert ! ( !chars. is_empty( ) ) ;
207
207
208
208
unsafe {
@@ -253,143 +253,3 @@ impl<'a> Hint<'a> {
253
253
}
254
254
255
255
include ! ( concat!( env!( "OUT_DIR" ) , "/codegen.rs" ) ) ;
256
-
257
- #[ cfg( test) ]
258
- mod tests {
259
- use std:: collections:: HashMap ;
260
-
261
- use super :: * ;
262
-
263
- /// Tests to make sure hints are properly outputed based on input
264
- #[ test]
265
- fn hints ( ) {
266
- let values = HashMap :: from ( [
267
- ( "" , Hint :: Single ( "x^2" ) ) ,
268
- ( "si" , Hint :: Many ( & [ "n(" , "nh(" , "gnum(" ] ) ) ,
269
- ( "log" , Hint :: Many ( & [ "2(" , "10(" ] ) ) ,
270
- ( "cos" , Hint :: Many ( & [ "(" , "h(" ] ) ) ,
271
- ( "sin(" , Hint :: Single ( ")" ) ) ,
272
- ( "sqrt" , Hint :: Single ( "(" ) ) ,
273
- ( "ln(x)" , Hint :: None ) ,
274
- ( "ln(x)cos" , Hint :: Many ( & [ "(" , "h(" ] ) ) ,
275
- ( "ln(x)*cos" , Hint :: Many ( & [ "(" , "h(" ] ) ) ,
276
- ( "sin(cos" , Hint :: Many ( & [ "(" , "h(" ] ) ) ,
277
- ] ) ;
278
-
279
- for ( key, value) in values {
280
- println ! ( "{} + {:?}" , key, value) ;
281
- assert_eq ! ( super :: generate_hint( key) , & value) ;
282
- }
283
- }
284
-
285
- #[ test]
286
- fn hint_to_string ( ) {
287
- let values = HashMap :: from ( [
288
- ( "x^2" , Hint :: Single ( "x^2" ) ) ,
289
- (
290
- r#"["n(", "nh(", "gnum("]"# ,
291
- Hint :: Many ( & [ "n(" , "nh(" , "gnum(" ] ) ,
292
- ) ,
293
- ( r#"["n("]"# , Hint :: Many ( & [ "n(" ] ) ) ,
294
- ( "None" , Hint :: None ) ,
295
- ] ) ;
296
-
297
- for ( key, value) in values {
298
- assert_eq ! ( value. to_string( ) , key) ;
299
- }
300
- }
301
-
302
- #[ test]
303
- fn invalid_function ( ) {
304
- SUPPORTED_FUNCTIONS
305
- . iter ( )
306
- . map ( |func1| {
307
- SUPPORTED_FUNCTIONS
308
- . iter ( )
309
- . map ( |func2| func1. to_string ( ) + func2)
310
- . collect :: < Vec < String > > ( )
311
- } )
312
- . flatten ( )
313
- . filter ( |func| !SUPPORTED_FUNCTIONS . contains ( & func. as_str ( ) ) )
314
- . for_each ( |key| {
315
- let split = super :: split_function ( & key) ;
316
-
317
- if split. len ( ) != 1 {
318
- panic ! ( "failed: {} (len: {}, split: {:?})" , key, split. len( ) , split) ;
319
- }
320
-
321
- let generated_hint = super :: generate_hint ( & key) ;
322
- if generated_hint. is_none ( ) {
323
- println ! ( "success: {}" , key) ;
324
- } else {
325
- panic ! ( "failed: {} (Hint: '{}')" , key, generated_hint. to_string( ) ) ;
326
- }
327
- } ) ;
328
- }
329
-
330
- #[ test]
331
- fn split_function ( ) {
332
- let values = HashMap :: from ( [
333
- ( "cos(x)" , vec ! [ "cos(x)" ] ) ,
334
- ( "cos(" , vec ! [ "cos(" ] ) ,
335
- ( "cos(x)sin(x)" , vec ! [ "cos(x)" , "sin(x)" ] ) ,
336
- ( "aaaaaaaaaaa" , vec ! [ "aaaaaaaaaaa" ] ) ,
337
- ( "emax(x)" , vec ! [ "e" , "max(x)" ] ) ,
338
- ( "x" , vec ! [ "x" ] ) ,
339
- ( "xxx" , vec ! [ "x" , "x" , "x" ] ) ,
340
- ( "sin(cos(x)x)" , vec ! [ "sin(cos(x)" , "x)" ] ) ,
341
- ( "sin(x)*cos(x)" , vec ! [ "sin(x)" , "cos(x)" ] ) ,
342
- ( "x*x" , vec ! [ "x" , "x" ] ) ,
343
- ( "10*10" , vec ! [ "10" , "10" ] ) ,
344
- ] ) ;
345
-
346
- for ( key, value) in values {
347
- assert_eq ! ( super :: split_function( key) , value) ;
348
- }
349
- }
350
-
351
- #[ test]
352
- fn hint_tests ( ) {
353
- {
354
- let hint = Hint :: None ;
355
- assert ! ( hint. is_none( ) ) ;
356
- assert ! ( !hint. is_some( ) ) ;
357
- assert ! ( !hint. is_single( ) ) ;
358
- }
359
-
360
- {
361
- let hint = Hint :: Single ( & "" ) ;
362
- assert ! ( !hint. is_none( ) ) ;
363
- assert ! ( hint. is_some( ) ) ;
364
- assert ! ( hint. is_single( ) ) ;
365
- }
366
-
367
- {
368
- let hint = Hint :: Many ( & [ "" ] ) ;
369
- assert ! ( !hint. is_none( ) ) ;
370
- assert ! ( hint. is_some( ) ) ;
371
- assert ! ( !hint. is_single( ) ) ;
372
- }
373
- }
374
-
375
- #[ test]
376
- fn get_last_term ( ) {
377
- let values = HashMap :: from ( [
378
- ( "cos(x)" , "x)" ) ,
379
- ( "cos(" , "cos(" ) ,
380
- ( "aaaaaaaaaaa" , "aaaaaaaaaaa" ) ,
381
- ( "x" , "x" ) ,
382
- ( "xxx" , "x" ) ,
383
- ( "x*x" , "x" ) ,
384
- ( "10*10" , "10" ) ,
385
- ( "sin(cos" , "cos" ) ,
386
- ] ) ;
387
-
388
- for ( key, value) in values {
389
- assert_eq ! (
390
- super :: get_last_term( key. chars( ) . collect:: <Vec <char >>( ) . as_slice( ) ) ,
391
- value
392
- ) ;
393
- }
394
- }
395
- }
0 commit comments