'Boolean in Racket

I run the test and there is always one test cannot pass. I tried every permutation. Is there an easier way like maybe try not returning a simple boolean, maybe the return depends on the input(s)?

Here are my codes:

(check-expect (same? #true #true) #true)
(check-expect (same? #false #false) #true)
(check-expect (same? #true #false) #false)

(define (same? b1 b2)
 (cond
    [ b1 #t ]
    [ b2 #f ]
    [else #t]))


Solution 1:[1]

That same? definition is wrong. To pass all test cases, you can use equal?:

(define same? equal?) ; <-- some languages, e.g. BSL don't allow this way

(define (same? b1 b2)
  (equal? b1 b2))

or, if you aren't allowed to use equal?, you can write something like this:

(define (same? b1 b2)
  (if b1 (if b2 #true #false)
      (if b2 #false #true)))

(In this solution, I expect b1 and b2 to be boolean values and nothing else.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Půda