Unit Testing in Clojure and Lab 4


(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-same-from-end [vect]
  (loop [v vect]
    (cond
     (empty? v) 0
     (all-same v) (count v)
     :else (recur (rest v))
     )
   )
)

(deftest empty-vec
  (is (= (longest-same-from-end []) 0))
)

(deftest long-sequence-test 
  (is (= (longest-same-from-end [1 3 1 1 1 1 1 1]) 6)) 
)

(deftest short-sequence-test 
  (is (= (longest-same-from-end [1 3 1 1 1 1 1 3 1]) 1)) 
)

(run-tests)

;; 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

;; write a function that removes duplicates from a vector



UMM CSci 4409

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.