-
Notifications
You must be signed in to change notification settings - Fork 0
/
rope-test.rkt
46 lines (38 loc) · 1.59 KB
/
rope-test.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#lang racket
(require rackunit
"rope.rkt")
(define test-str "hello I am a small rope test")
; Basic Conversion Test
(check-equal? (rope->str (str->rope test-str)) test-str)
; Insertion Tests
; these make sense when we're breaking strings into chunks of max length 10
; but will need to be replaced with longer ones probably
(for ([r (+ 1 (string-length test-str))])
(check-equal?
(rope->str (insert-str-into-rope (str->rope test-str) "¯\\_(ツ)_/¯" r))
(string-append-immutable (substring test-str 0 r)
"¯\\_(ツ)_/¯"
(substring test-str r))))
; Deletion Tests
; Again, need long tests for bigger chunks
(for ([r `((4 8) (4 12) (4 21) (12 24) (24 25) (0 27))])
(check-equal?
(rope->str (delete-from-rope (str->rope test-str) (first r) (second r)))
(string-append-immutable (substring test-str 0 (first r))
(substring test-str (second r)))))
; get-substring-from-rope
(for ([r `((4 8) (4 12) (4 21) (12 24) (24 25) (0 27))])
(check-equal?
(get-substring-from-rope (str->rope test-str) (first r) (second r))
(substring test-str (first r) (second r))))
; rebalance
(check-equal?
(rope->str (rebalance-rope
(insert-str-into-rope
(str->rope "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16")
"asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadfasdfasdf"
10)))
(rope->str (insert-str-into-rope
(str->rope "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16")
"asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadfasdfasdf"
10)))