Re: [racket-users] Question on test failures sorting a BTS

2020-04-27 Thread Jon Zeppieri
In addition to what Jens said, you should probably give a definition
of a BST at the top, and give some thought to the question of why a
BST is not simply the same thing as a node.

- Jon

On Sun, Apr 26, 2020 at 10:36 PM Kristina Marie  wrote:
>
> Hello,
> I am trying to use HtDF to create a function to sort a Binary Search Tree. I 
> am in an intro class so this may be a simple question. I did the following:
>
> ;define-struct a node
> (define-struct node (left value right))
> ;BTS leafs
> (define a-node(make-node null "A" null))
> (define b-node (make-node null "B" null))
> (define e-node (make-node null "E" null))
> (define h-node (make-node null "H" null))
> (define i-node (make-node null "I" null))
>
> ;BTS internal
> (define c-node (make-node a-node "C" b-node))
> (define j-node (make-node h-node "J" i-node))
> (define k-node (make-node j-node "K" null))
> (define f-node (make-node e-node "F" null))
> (define g-node (make-node f-node "G" k-node))
>
> ;Root
> (define root (make-node c-node "D" g-node))
>
> ; Purpose: sort a binary tree
> ; Signature: node -> list
> ; Examples:
> (check-expect (bst-sort null)(list))
> (check-expect (bst-sort a-node)(list "A"))
> (check-expect (bst-sort j-node)(list "H" "I" "J"))
> (check-expect (bst-sort root)(list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" 
> "K"))
>
> ;Code
> (define (bst-sort nod)
>   (cond
> [(null? nod)(list)]
> [(and (null? (node-left nod)) (null?(node-right nod))) (list(node-value 
> nod))]
>[else
>(string-append (bst-sort (node-left nod) (list (node-value nod)) 
> (bst-sort (node-right nod
>]
>)
>  )
>
> I keep getting this test failure:
> bst-sort: expects only 1 argument, but found 3
>
> It has to due with the two last check-expects failing because of the 
> highlighted line.
>
> I ran this same code with integers and removed the string from append and it 
> passed. Any advice?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAKfDxxwOOMxMcmTZm7bYJm6D7vM4w1VjORBxcjypWdUCr%3DRduA%40mail.gmail.com.


Re: [racket-users] Question on test failures sorting a BTS

2020-04-27 Thread Jens Axel Søgaard
Den man. 27. apr. 2020 kl. 04.36 skrev Kristina Marie :

> Hello,
> I am trying to use HtDF to create a function to sort a Binary Search Tree.
> I am in an intro class so this may be a simple question. I did the
> following:
>
> ;define-struct a node
> (define-struct node (left value right))
>
...

> ; Purpose: sort a binary tree
> ; Signature: node -> list
> ; Examples:
> (check-expect (bst-sort null)(list))
> (check-expect (bst-sort a-node)(list "A"))
> (check-expect (bst-sort j-node)(list "H" "I" "J"))
> (check-expect (bst-sort root)(list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
> "K"))
>
> ;Code
> (define (bst-sort nod)
>   (cond
> [(null? nod)(list)]
> [(and (null? (node-left nod)) (null?(node-right nod)))
> (list(node-value nod))]
>[else
>(string-append (bst-sort (node-left nod) (list (node-value
> nod)) (bst-sort (node-right nod
>]
>)
>  )
>
>
This expression
 (bst-sort (node-left nod) (list (node-value nod)) (bst-sort
(node-right nod
is the problem. It can be reformatted to make it clearer:

 (bst-sort (node-left nod)
   (list (node-value nod))
(bst-sort (node-right nod

You are providing 3 arguments to bst-sort, but according to your signature:
; Signature: node -> list
it only takes one input.

Furthermore the `string-append` needs to be removed, since bst-sort returns
a list, not a string.

/Jens Axel



> I keep getting this test failure:
> bst-sort: expects only 1 argument, but found 3
>
> It has to due with the two last check-expects failing because of the
> highlighted line.
>
> I ran this same code with integers and removed the string from append and
> it passed. Any advice?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com
> 
> .
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgyyOCTLVomOhEWtOT%3DOOOdyNM%2BxcSEee4kdDctbspBDOg%40mail.gmail.com.


[racket-users] Question on test failures sorting a BTS

2020-04-26 Thread Kristina Marie
Hello,
I am trying to use HtDF to create a function to sort a Binary Search Tree. 
I am in an intro class so this may be a simple question. I did the 
following:

;define-struct a node
(define-struct node (left value right))
;BTS leafs
(define a-node(make-node null "A" null))
(define b-node (make-node null "B" null))
(define e-node (make-node null "E" null))
(define h-node (make-node null "H" null))
(define i-node (make-node null "I" null))

;BTS internal
(define c-node (make-node a-node "C" b-node))
(define j-node (make-node h-node "J" i-node))
(define k-node (make-node j-node "K" null))
(define f-node (make-node e-node "F" null))
(define g-node (make-node f-node "G" k-node))

;Root
(define root (make-node c-node "D" g-node))

; Purpose: sort a binary tree
; Signature: node -> list
; Examples:
(check-expect (bst-sort null)(list))
(check-expect (bst-sort a-node)(list "A"))
(check-expect (bst-sort j-node)(list "H" "I" "J"))
(check-expect (bst-sort root)(list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" 
"K"))

;Code
(define (bst-sort nod)
  (cond
[(null? nod)(list)]
[(and (null? (node-left nod)) (null?(node-right nod))) (list(node-value 
nod))]
   [else
   (string-append (bst-sort (node-left nod) (list (node-value nod)) 
(bst-sort (node-right nod
   ]
   )
 )

I keep getting this test failure:
bst-sort: expects only 1 argument, but found 3

It has to due with the two last check-expects failing because of the 
highlighted line. 

I ran this same code with integers and removed the string from append and 
it passed. Any advice?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com.