Skip to content

Mapping

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(mapping-empty <)

When I successfully run stak main.scm

Then the exit status should be 0.

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(write-u8 (if (mapping? (mapping-empty <)) 65 66))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(define tree (mapping-empty <))
(write-u8 (if (mapping-find tree 1) 65 66))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “B”.

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(define tree (mapping-empty <))
(mapping-insert! tree 1)
(write-u8 (if (= (mapping-find tree 1) 1) 65 66))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(define tree (mapping-empty <))
(mapping-insert! tree 2)
(mapping-insert! tree 1)
(for-each
(lambda (x)
(write-u8 (if (eq? (mapping-find tree x) x) 65 66)))
'(1 2 3))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “AAB”.

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(define tree (mapping-empty <))
(mapping-insert! tree 1)
(mapping-insert! tree 2)
(for-each
(lambda (x)
(write-u8 (if (eq? (mapping-find tree x) x) 65 66)))
'(1 2 3))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “AAB”.

Insert a value into the same node of a tree

Section titled “Insert a value into the same node of a tree”

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(define tree (mapping-empty <))
(mapping-insert! tree 1)
(mapping-insert! tree 1)
(write-u8 (if (eq? (mapping-find tree 1) 1) 65 66))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(define tree (mapping-empty <))
(define (check x)
(write-u8 (if (eq? (mapping-find tree x) x) 65 66)))
(for-each
(lambda (x)
(check x)
(mapping-insert! tree x)
(check x))
'(<values>))
(for-each check '(<values>))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “<output>”.

values output
1 2 3 BABABAAAA
1 3 2 BABABAAAA
2 1 3 BABABAAAA
2 3 1 BABABAAAA
3 1 2 BABABAAAA
3 2 1 BABABAAAA
1 2 3 4 BABABABAAAAA
1 2 4 3 BABABABAAAAA
1 3 2 4 BABABABAAAAA
1 3 4 2 BABABABAAAAA
1 4 2 3 BABABABAAAAA
1 4 3 2 BABABABAAAAA
2 1 3 4 BABABABAAAAA
2 1 4 3 BABABABAAAAA
2 3 1 4 BABABABAAAAA
2 3 4 1 BABABABAAAAA
2 4 1 3 BABABABAAAAA
2 4 3 1 BABABABAAAAA

Given a file named “main.scm” with:

(import (scheme base) (stak mapping))
(write-u8 (if (equal? (mapping->list (list->mapping '(<values>) <)) '(<output>)) 65 66))

When I successfully run stak main.scm

Then the exit status should be 0

And the stdout should contain exactly “A”.

values output
1 1
1 2 1 2
2 1 1 2
1 2 3 1 2 3
1 3 2 1 2 3
2 1 3 1 2 3
2 3 1 1 2 3
3 1 2 1 2 3
3 2 1 1 2 3
1 2 3 4 1 2 3 4
1 2 4 3 1 2 3 4
1 3 2 4 1 2 3 4
1 3 4 2 1 2 3 4
1 4 2 3 1 2 3 4
1 4 3 2 1 2 3 4
2 1 3 4 1 2 3 4
2 1 4 3 1 2 3 4
2 3 1 4 1 2 3 4
2 3 4 1 1 2 3 4
2 4 1 3 1 2 3 4
2 4 3 1 1 2 3 4