Skip to content

Commit

Permalink
countrailparts consumes list in order, math tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdsandifer committed Aug 30, 2016
1 parent b24ea9b commit 0d0370b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 1 addition & 1 deletion COUNT_RAIL.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
;; 08/30/2016 ;;
;; - Finished CountRailParts. And 2nd version. ;;
;; - Added ListRemove & ListSearch (temp.). ;;
;; - Moved them to functions. ;;
;; - Then moved them to FUNCTIONS. ;;
;; - Added unit tests. ;;
;; ;;
;; 08/29/2016 ;;
Expand Down
23 changes: 17 additions & 6 deletions FUNCTIONS.LSP
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
(Assert 'ListSearch '('(= "a" (nth i theList)) aList) 0)
(Assert 'ListSearch '('(= "b" (nth i theList)) aList) 1)
(Assert 'ListSearch '('(= "c" (nth i theList)) aList) 2)
(setq aList '(1 2 3))
(princ aList)(princ "\n")
(Assert 'ListSearch '('(<= 1 (nth i theList)) aList) 0)
(Assert 'ListSearch '('(<= 2 (nth i theList)) aList) 1)
(Assert 'ListSearch '('(<= 3 (nth i theList)) aList) 2)

;; Displaying the results of the tests
(JD:PrintTestResults (JD:CountBooleans testList)))
Expand Down Expand Up @@ -228,12 +233,18 @@
; Ret: index of item if found, nil if not

(defun ListSearch (criteria theList / n)
(if (/= nil theList)
(foreach i (Range 0 (1- (length theList)) 1)
(if (eval criteria)
(setq n i)))
(setq n nil))
n)
(cond
( (/= nil theList)
(setq i 0)
(while (< i (length theList))
(cond
( (eval criteria)
(setq n i)
(setq i (length theList))))
(setq i (1+ i))))
( T
(setq n nil)))
n)



Expand Down
21 changes: 21 additions & 0 deletions MATH.LSP
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 08/30/2016 ;;
;; - Added unit tests for RoundUpBy. ;;
;; ;;
;; 03/16/2016 ;;
;; - Moved math functions to this file. ;;
;; No more list and general functions... ;;
Expand Down Expand Up @@ -39,6 +42,24 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; Runs all unit tests for this file
; Output: T if all unit tests passed, else nil

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

;; Actual tests
(princ "RoundUpBy\n")
(Assert 'RoundUpBy '(12 12) 12)
(Assert 'RoundUpBy '(12 12.0) 12)

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



;; DTR - (Converts) Degrees To Radians - useful for polar command
;; angleInDegrees [ integer ]
Expand Down

0 comments on commit 0d0370b

Please sign in to comment.