Skip to content

Commit

Permalink
unit testing adds/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdsandifer committed Aug 30, 2016
1 parent c8e6062 commit a1e9b31
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 33 deletions.
20 changes: 8 additions & 12 deletions COUNT_RAIL.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
infillList
stockLength))))
(princ))

( (= infillType "Picket")
(setq picketList
(MeasureLineSegments
Expand All @@ -176,33 +177,28 @@
(68 . 14)
(73 . 15)
(77 . 16)
(1000 . 200) )) ;last one is just a buffer
(1000 . 200) )) ;last one is just a buffer item
(setq totalPicketLength 0
totalPickets 0)
(foreach picketPair picketList
(setq index 0)
(while (< (car (nth index picketChart)) (car picketPair))
(setq index (1+ index)))
(setq totalPicketLength
(+
(* (cdr picketPair) (car (nth index picketChart)))
totalPicketLength))
(setq totalPickets
(+
(*
(cdr picketPair)
(car (nth index picketChart)))
totalPicketLength))
(setq totalPickets (+ (* (cdr picketPair) (cdr (nth index picketChart)))totalPickets)))
(cdr (nth index picketChart)))totalPickets)))
(princ
(strcat
"\nTotal pickets: "
(itoa totalPickets)
"\nTotal picket length: "
(rtos
(RoundUpByDbl
0.5
(/
totalPicketLength
12.0))
2
2)))))
(rtos (RoundUpByDbl 0.5 (/ totalPicketLength 12.0)) 2 2)))))

(princ))

Expand Down
49 changes: 42 additions & 7 deletions FUNCTIONS.LSP
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 08/29/2016 ;;
;; - Added SortAssocListKeysBy. ;;
;; - Added SortAssocListKeysBy and ;;
;; SortAssocListValuesBy. ;;
;; - Added unit tests for above. ;;
;; ;;
;; 08/24/2016 ;;
;; - Added DisplayAssocList. ;;
Expand Down Expand Up @@ -56,19 +58,16 @@
; Runs all unit tests for this file
; Output: T if all unit tests passed, else nil

(defun C:TestFunctions ( / testList testResults varList)

(defun C:TestFunctions ( / testList)
;; Setup for tests
(princ "\n")
(princ "Testing FUNCTIONS\n")
(princ "--------------------\n")

;; Actual tests
(princ "SortAssocListKeysBy\n")
(Assert
'SortAssocListKeysBy
'('(("a" . 1)) '<)
'(("a" . 1)))
(Assert 'SortAssocListKeysBy '('() '<) '())
(Assert 'SortAssocListKeysBy '('(("a" . 1)) '<) '(("a" . 1)))
(Assert
'SortAssocListKeysBy
'('(("a" . 1)("b" . 0)) '<)
Expand All @@ -82,6 +81,23 @@
'('(("a" . 1)("c" . 3)("b" . 0)) '>)
'(("c" . 3)("b" . 0)("a" . 1)))

(princ "\n")
(princ "SortAssocListValuesBy\n")
(Assert 'SortAssocListValuesBy '('() '<) '())
(Assert 'SortAssocListValuesBy '('(("a" . 1)) '<) '(("a" . 1)))
(Assert
'SortAssocListValuesBy
'('(("a" . 1)("b" . 0)) '<)
'(("b" . 0)("a" . 1)))
(Assert
'SortAssocListValuesBy
'('(("a" . 1)("c" . 3)("b" . 0)) '<)
'(("b" . 0)("a" . 1)("c" . 3)))
(Assert
'SortAssocListValuesBy
'('(("a" . 1)("c" . 3)("b" . 0)) '>)
'(("c" . 3)("a" . 1)("b" . 0)))

;; Displaying the results of the tests
(JD:PrintTestResults (JD:CountBooleans testList)))

Expand Down Expand Up @@ -263,6 +279,25 @@



;;; SortAssocListValuesBy - Sorts the list by the provided comparison function
;;; using vl-sort-i to get sorted indexes and assembling a
;;; sorted list with those indexes.
;;; thelist - [list] name of the list to sort
;;; functionName - [symbol] the function to use
;;; Based on (mapcar '(lambda (x) (nth x a)) (vl-sort-i a '<))
;;; provided by *Kim, HeeTea on forums.autodesk.com, 1/23/2002 (02/06/16)



(defun SortAssocListValuesBy (theAssoclist functionName)
(mapcar '(lambda (index) (nth index theAssoclist))
(vl-sort-i
(mapcar
'cdr theAssoclist)
functionName)))



;; DisplayAssocList - Displays the association list as a table: label then quantity
;; result - [association list] Labels paired with quantities.

Expand Down
71 changes: 57 additions & 14 deletions TEST.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
;; - Added Verify for functions that don't ;;
;; return a value. ;;
;; ;;
;; 08/29/2016 ;;
;; - Added JD:ReplaceAllSubst to clean up ;;
;; display of argument lists. ;;
;; - Tweaked Assert and Verify to use it. ;;
;; - Added tests of the tests...still need ;;
;; real tests of Assert & Verify. Maybe not ;;
;; immediately print results? Separate ;;
;; function? ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; Tests the testing functions.
; Output: T if all unit tests passed, else nil

(defun C:Test ( / testList testResults varList)

(defun C:Test ( / testList)
;; Setup for tests
(princ "\n")
(princ "Testing TEST\n")
Expand All @@ -33,9 +41,26 @@
;; Actual tests
(princ "Assert\n")
(Assert '+ '(1 2 3) 6)
;(princ "Verify\n")
;(Verify 'JD:ResetVar '("osmode" 'varList) '(= (getvar "osmode") 180))

(princ "\nVerify\n")

(setq varToTest nil)
(Verify 'set '('varToTest 6) '(= varToTest 6))
(setq varToTest nil)

(princ "\nJD:ReplaceAllSubst\n")
(Assert 'JD:ReplaceAllSubst '("y" "a" "Hello") "Hello")
(Assert 'JD:ReplaceAllSubst '("o" "a" "Hella") "Hello")
(Assert 'JD:ReplaceAllSubst '("o" "a" "Hella hella hella") "Hello hello hello")
(Assert 'JD:ReplaceAllSubst '("o" "a" "a hella") "o hello")
(Assert 'JD:ReplaceAllSubst '("o" "a" "A hella") "A hello")
(Assert 'JD:ReplaceAllSubst '("o" "a" "hallaw") "hollow")

(princ "\nJD:CountBooleans\n")
(Assert 'JD:CountBooleans '('()) '(("T" . 0)("F" . 0)))
(Assert 'JD:CountBooleans '('(T T T)) '(("T" . 3)("F" . 0)))
(Assert 'JD:CountBooleans '('(F F F)) '(("T" . 0)("F" . 3)))
(Assert 'JD:CountBooleans '('(F T F)) '(("T" . 1)("F" . 2)))

;; Displaying the results of the tests
(JD:PrintTestResults (JD:CountBooleans testList)))

Expand Down Expand Up @@ -67,13 +92,10 @@
(princ (strcase (vl-symbol-name functionName) T))
(princ " ")
(princ
(vl-string-subst
(JD:ReplaceAllSubst
"'"
"(QUOTE "
(vl-string-subst
"'"
"(QUOTE "
(vl-prin1-to-string argumentList))))
(vl-prin1-to-string argumentList)))
(princ ") returned ")
(if actualReturn (princ actualReturn))
(princ expectedReturn)
Expand Down Expand Up @@ -107,7 +129,11 @@
;; continue printing result...
(princ (strcase (vl-symbol-name functionName) T))
(princ " ")
(prin1 argumentList)
(princ
(JD:ReplaceAllSubst
"'"
"(QUOTE "
(vl-prin1-to-string argumentList)))
(princ ") functioned ")
(if passed
(princ "as expected")
Expand All @@ -119,13 +145,28 @@



; Changes all "pattern"s to "newSubst". Like vl-string-subst, but replaces
; ALL instances of pattern instead of just the first one.
; Argument: String to alter.
; Return: Altered string.

(defun JD:ReplaceAllSubst (newSubst pattern string / pattern)
(while (vl-string-search pattern string)
(setq
string
(vl-string-subst newSubst pattern string)))
string)



; Counts boolean values
; Input: simple list of boolean values - (T T T T T T T T T T)
; Output: none
; Return: assoc. list of the qty of T's and F's - (("T" . 10) ("F" . 0))


(defun JD:CountBooleans ( booleanList / countList)
(setq countList '(("T" . 0)("F" . 0)))
(foreach listItem booleanList
(if (= listItem T)
(setq countList (Assoc++ "T" countList))
Expand All @@ -144,9 +185,6 @@
; Note: there are always four characters before each "tests"

(defun JD:PrintTestResults ( testResults / trues falses)
(princ "\nResults:")
(princ "\n----------------")

(setq trues (cdr (Assoc "T" testResults)))
(setq falses (cdr (Assoc "F" testResults)))

Expand All @@ -155,6 +193,11 @@
(if (= falses nil)
(setq falses 0))

(princ "\nResults:")
(if (= falses 0)
(princ " ALL PASS"))
(princ "\n-----------------")


; add code to count digits in numbers and add correct space before.
; also, choose between "test" and "tests" correctly?
Expand Down

0 comments on commit a1e9b31

Please sign in to comment.