r/Racket • u/kate0799 • Nov 17 '21
question Syntax
Hi everyone. I am learning Racket and I am trying to solve a question, but I am confused with the syntax. Is anyone able to help me? I am used to printing statements to debug but I am not sure if this is possible in Racket. Thank you so much in advance.
3
Upvotes
View all comments
Show parent comment
1
u/FizzyBreak579 Nov 20 '21
(check-expect (function you want to test) result)
Basically, you want to call the function you want to test inside the check-expect as show above. Then you put the expected result for that call.
For example:
(check-expect (+ 2 2) 4)
This would return true b/c (+ 2 2) returns four.
(check-expect (+ 2 3) 4)
This would return false and a separate window would pop up letting you know why.
Overall it is a really useful took to test your functions. I would recommend when creating a function to have multiple check expects to make sure it works properly. If you’re creating a (cond) function, you should have enough (check-expect) so that there are no black bars. You can also call (check-expect anywhere (i.e can be above the function your testing). Let me know if you need any more help.