Clojure testing and lab 2 (part 2)



(ns testing
  (:require clojure.test))

(use 'clojure.repl)
(use 'clojure.test)

(with-test
(defn all-same [vect]
  (cond 
    (empty? vect) true
    :else (every? #(= (first vect) %1) (rest vect)) 
  )
)
(is (= (all-same []) true))
(is (= (all-same [1 2 1 3]) false))
(is (= (all-same [1 2 2 2]) false))
(is (= (all-same [2 2 2 2]) true)))


(defn longest-ending-seq [vect]
  (loop [v vect]
    (cond
     (empty? v) 0
     (all-same v) (count v)
     :else (recur (rest v))
     )
   )
)

(deftest empty-vec
  (is (= (longest-ending-seq []) 0))
)

(deftest long-sequence-test 
  (is (= (longest-ending-seq [1 3 1 1 1 1 1 1]) 6)) 
)

(deftest short-sequence-test 
  (is (= (longest-ending-seq [1 3 1 1 1 1 1 3 1]) 1)) 
)

(run-tests)

;; Lab 2, problem 4
;; write a function that takes a vector and returns true 
;; if it has no duplicated elements
;; and false otherwise
;; Provide testing for all intermediate fucntions 
;; and the final function

;; Lab 2, problem 5
;; write a function that removes duplicates from a vector
;; also provide tests

UMM CSci 4651