work in progress on unit testing functions
This commit is contained in:
parent
7cc938fc7c
commit
02c3a20936
|
|
@ -36,7 +36,7 @@
|
||||||
- env functions
|
- env functions
|
||||||
- get-env, set-env; set-env cannot be implemented in stdlib.lsp, because popen is in fact subshell
|
- get-env, set-env; set-env cannot be implemented in stdlib.lsp, because popen is in fact subshell
|
||||||
- format (sprintf)
|
- format (sprintf)
|
||||||
- setq
|
- add include-stdlib function for other libs in stdlib dir (during startup stdlib.lsp is loaded only)
|
||||||
- syntax highlighting do VS Code
|
- syntax highlighting do VS Code
|
||||||
- add hash datatype
|
- add hash datatype
|
||||||
|
|
||||||
|
|
|
||||||
102
debug.lsp
102
debug.lsp
|
|
@ -1,18 +1,18 @@
|
||||||
(print (string-split "split me by space" "\\s+"))
|
;; (print (string-split "split me by space" "\\s+"))
|
||||||
|
|
||||||
|
|
||||||
(print (string-rtrim "abc "))
|
;; (print (string-rtrim "abc "))
|
||||||
(print (string-ltrim " abc"))
|
;; (print (string-ltrim " abc"))
|
||||||
(print (string-trim " abc "))
|
;; (print (string-trim " abc "))
|
||||||
|
|
||||||
(defun string-upcase (str)
|
;; (defun string-upcase (str)
|
||||||
(string-case str "upper"))
|
;; (string-case str "upper"))
|
||||||
|
|
||||||
(defun string-downcase (str)
|
;; (defun string-downcase (str)
|
||||||
(string-case str "lower"))
|
;; (string-case str "lower"))
|
||||||
|
|
||||||
(print (string-upcase "abcABCD"))
|
;; (print (string-upcase "abcABCD"))
|
||||||
(print (string-downcase "abcABCD"))
|
;; (print (string-downcase "abcABCD"))
|
||||||
|
|
||||||
;; (print (sprintf "%.2f" (list 1.25)))
|
;; (print (sprintf "%.2f" (list 1.25)))
|
||||||
|
|
||||||
|
|
@ -44,14 +44,82 @@
|
||||||
;; (define fdx_list (parse-csv (read-file "tests/csv_data.csv")))
|
;; (define fdx_list (parse-csv (read-file "tests/csv_data.csv")))
|
||||||
;; (print fdx_list)
|
;; (print fdx_list)
|
||||||
|
|
||||||
(print (and (print "xx") (= 1 0) (print "yy")))
|
;; (print (and (print "xx") (= 1 0) (print "yy")))
|
||||||
|
|
||||||
(defun aa () (do
|
;; (defun aa () (do
|
||||||
(print "prvni")
|
;; (print "prvni")
|
||||||
(+ 1 xx)
|
;; (+ 1 xx)
|
||||||
(print "druhy")
|
;; (print "druhy")
|
||||||
|
;; ))
|
||||||
|
|
||||||
|
;; (aa)
|
||||||
|
|
||||||
|
; (sleep 1.5)
|
||||||
|
|
||||||
|
(define multiply-by (lambda (n) (lambda (y) (* y n))))
|
||||||
|
(define doubler (multiply-by 2))
|
||||||
|
(define tripler (multiply-by 3))
|
||||||
|
(doubler 4)
|
||||||
|
(tripler 4)
|
||||||
|
|
||||||
|
|
||||||
|
;https://github.com/anthay/Lisp90/blob/master/lisp90.cpp
|
||||||
|
;http://howtowriteaprogram.blogspot.com/2010/11/lisp-interpreter-in-90-lines-of-c.html
|
||||||
|
|
||||||
|
; https://stackoverflow.com/questions/526082/in-scheme-whats-the-point-of-set
|
||||||
|
(define x 3)
|
||||||
|
(defun foo() (do (define x 4) x))
|
||||||
|
(defun bar() (do (set! x 4) x))
|
||||||
|
|
||||||
|
(foo) ; returns 4
|
||||||
|
x ; still 3
|
||||||
|
(bar) ; returns 4
|
||||||
|
x ; is now 4
|
||||||
|
|
||||||
|
|
||||||
|
(defun mini-uuid (uuid_len)
|
||||||
|
(do
|
||||||
|
(define a_list '("_" "-" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
|
||||||
|
(reduce (lambda (acc y) (+ acc y)) "" (map (lambda (e) (index a_list (random 0 (- (len a_list) 1)))) (range 0 uuid_len)))
|
||||||
))
|
))
|
||||||
|
|
||||||
(aa)
|
(benchmark "uuid 1000x :" (define i 0) (while (< i 1000) (do (mini-uuid 5) (define i (+ i 1)))))
|
||||||
|
|
||||||
; (sleep 1.5)
|
|
||||||
|
(defun ut::assert-equal (value form) (do
|
||||||
|
(define fvalue (eval form))
|
||||||
|
(if (= value fvalue)
|
||||||
|
1
|
||||||
|
nil
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
|
(define ut::assert-true (test) (ut::assert-equal 1 test))
|
||||||
|
(assert-false (test)() (asertt-equal nil test)
|
||||||
|
(defun ut::assert-true test) ()
|
||||||
|
|
||||||
|
|
||||||
|
(defun ut::assert-false test)
|
||||||
|
(define ut::tests_list '())
|
||||||
|
(defun ut::define-test (name exp_list) (
|
||||||
|
define test_list (push ut::tests_list (list name exp_list))))
|
||||||
|
|
||||||
|
(run-tests name1 name2 ...)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(defun define-test (name exp_list) (set! test_list (push test_list (list name exp_list))))
|
||||||
|
(defun run-tests () (do (for t test_list (if (eval (index t 1)) (print (+ "OK -> " (index t 0))) (print (+ "ERR -> " (index t 0)))))))
|
||||||
|
;(run-test name)
|
||||||
|
|
||||||
|
(define test_list '())
|
||||||
|
|
||||||
|
(define-test "je to dvojka" '(assert-equal 2 (+ 1 1)))
|
||||||
|
(define-test "je to trojka" '(assert-equal 3 (+ 1 1)))
|
||||||
|
|
||||||
|
(run-tests)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(define-test "je to dvojka" '(assert-equal 2 (+ 1 1)))
|
||||||
Loading…
Reference in New Issue