Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

small tool changes

  • Loading branch information...
commit 3b1da061793ef14f83d86e1a4e513b428c3a67cb 1 parent 5378653
@sroccaserra authored
Showing with 59 additions and 41 deletions.
  1. +5 −6 tools.el
  2. +54 −35 tools.elk
View
11 tools.el
@@ -40,13 +40,12 @@
;; Strings
(defun string-empty-p (str)
- (unless (stringp str)
- (error "not a string."))
- (string= "" str))
+ (if str
+ (string= "" str)
+ t))
-(defun string-not-blank-p (str)
- (when str
- (not (string-empty-p str))))
+(defun string-not-empty-p (str)
+ (not (string-empty-p str)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Undestructive alist functions
View
89 tools.elk
@@ -4,19 +4,33 @@
(require 'tools)
+;;;;;;;;;;;;
+;; Sequences
+
(deftest "seq returns the sequence itself"
(assert-equal '(1)
- (seq '(1)))
+ (sequence '(1)))
(assert-equal [1]
- (seq [1]))
+ (sequence [1]))
(assert-equal "1"
- (seq "1")))
+ (sequence "1")))
(deftest "seq turns non-sequences into a list"
(assert-equal '(1)
- (seq 1))
+ (sequence 1))
(assert-equal '(toto)
- (seq 'toto)))
+ (sequence 'toto)))
+
+(deftest "I can substract two vectors"
+ (assert-equal ["ABC"]
+ (seq-difference ["ABC" "DEF"] ["DEF"])))
+
+(deftest "retrieving a random element"
+ (assert-equal "ABC"
+ (random-elt ["ABC"])))
+
+;;;;;;;;;;;;;
+;; Functional
(deftest "currying the plus function"
(assert-equal 5
@@ -30,6 +44,24 @@
(assert-equal [2 3]
(remove-if-not (partial < 1) [1 2 3])))
+(lexdef lexdef-test (x)
+ (lambda () x))
+
+(defun defun-test (x)
+ (lambda () x))
+
+(deftest "lexdef has lexical scoping"
+ (let ((lexical (lexdef-test 1))
+ (dynamic (defun-test 1))
+ (x 2))
+ (assert-equal 1
+ (funcall lexical))
+ (assert-equal 2
+ (funcall dynamic))))
+
+;;;;;;;;;;;;;;
+;; Trush tests
+
(deftest "applying trush to one form"
(assert-equal 5.0
(-> 25 sqrt)))
@@ -46,21 +78,6 @@
(assert-equal '(* 6 (+ 4 5 (- 2 3 x)))
(macroexpand '(->> x (- 2 3) (+ 4 5) (* 6)))))
-(lexdef lexdef-test (x)
- (lambda () x))
-
-(defun defun-test (x)
- (lambda () x))
-
-(deftest "lexdef has lexical scoping"
- (let ((lexical (lexdef-test 1))
- (dynamic (defun-test 1))
- (x 2))
- (assert-equal 1
- (funcall lexical))
- (assert-equal 2
- (funcall dynamic))))
-
(deftest "comment returns nil"
(assert-equal nil
(comment 3)))
@@ -72,6 +89,9 @@
(setq x 3))
(assert-equal 2 x)))
+;;;;;;;;
+;; Maths
+
(deftest "variance of a const list returns 0"
(->> [[1 1 1]
[2 2 2 2 2]
@@ -84,14 +104,6 @@
(- (/ 2 3.0)
(variance [1 2 3]))))
-(deftest "retrieving a random element"
- (assert-equal "ABC"
- (random-elt ["ABC"])))
-
-(deftest "I can substract two vectors"
- (assert-equal ["ABC"]
- (seq-difference ["ABC" "DEF"] ["DEF"])))
-
;;;
;; Alist functions
@@ -117,14 +129,21 @@
;;;;;;;;;;
;; Strings
+(deftest "string-equal can compare strings to symbols"
+ (assert-t (string= 'hello "hello"))
+ (assert-error "string" (string= 1 "1")))
+
(deftest "an empty string is empty, a non empty string is not empty"
(assert-nil (string-empty-p "hello"))
- (assert-nonnil (string-empty-p (copy-seq "")))
- (assert-error "string" (string-empty-p 1))
- (assert-error "string" (string-empty-p nil)))
+ (assert-t (string-empty-p (copy-seq "")))
+ (assert-t (string-empty-p nil))
+ (assert-error "string" (string-empty-p 1)))
(deftest "I can tell if a sring is blank"
- (assert-t (string-not-blank-p "hello"))
- (assert-nil (string-not-blank-p nil))
- (assert-nil (string-not-blank-p ""))
- (assert-error "string" (string-not-blank-p 1)))
+ (assert-t (string-not-empty-p "hello"))
+ (assert-nil (string-not-empty-p nil))
+ (assert-nil (string-not-empty-p ""))
+ (assert-error "string" (string-not-empty-p 1)))
+
+(deftest "symbols are non empty"
+ (assert-nil (string-empty-p 'hello)))
Please sign in to comment.
Something went wrong with that request. Please try again.