Permalink
Browse files

Made how-long-ms macro reusable in other projects/tests

  • Loading branch information...
reinhrst committed Mar 6, 2012
1 parent d7bc358 commit 85ef56f2a6e526cee8f3b03523b8291133e96fe9
View
@@ -28,6 +28,12 @@ Has one function: timed-sequence. This takes a sequence, and a delay. The functi
Works even with delays of less than 1/1000 second. However, because java time only has milisecond resolution, a timing of 0.0001 means that every 1ms a burst of 10 items becomes available. Probably there is something better to use than java time, but this suits my needs
+### Test tools
+Tools that can be used in tests, currently just the "how-long-ms" macro. This macro returns a vector, first element the body's return value, second element the number of ms it took.
+
+(use 'nl.claude.tools.test-tools)
+(how-long-ms (Thread/sleep 300) 42) --> should return [42 300]; the second number may be slightly higher if the rest of the body took more than one ms
+
### HVR-2200 patch
See the misc directory. Patches the Hauppauge HVR-2200 v4l2 drivers to work with the PAL analog signal. This patch is adapted from http://thread.gmane.org/gmane.linux.drivers.video-input-infrastructure/26212/focus=26524 to a newer kernel version. Also see http://www.mythtvtalk.com/you-waiting-hvr-2200-2250-linux-driver-10906-6/ and http://linuxtv.org/wiki/index.php/Hauppauge_WinTV-HVR-2200 .
View
Binary file not shown.
@@ -0,0 +1,10 @@
+(ns nl.claude.tools.test-tools
+ (:import java.util.Date))
+
+(defmacro how-long-ms [& x]
+ "Returns a veactor with first element the result of the body, and second element the number of miliseconds the body took"
+
+ `(let [~'todo #(do ~@x)
+ ~'start-time (.getTime (Date.))]
+ [(~'todo) (- (.getTime (Date.)) ~'start-time)]))
+
@@ -0,0 +1,10 @@
+(ns nl.claude.tools.test.test-tools
+ (:use nl.claude.tools.test-tools)
+ (:use clojure.test))
+
+(deftest howlong
+ (let [x (how-long-ms
+ (Thread/sleep 300)
+ 42)]
+ (is (< -1 (- (x 1) 300) 20) (str "Timing should be around 300 ms, was " (x 1)))
+ (is (= 42 (x 0)) "Answer should have been 42")))
@@ -1,14 +1,6 @@
(ns nl.claude.tools.test.timed-sequence
- (:use [nl.claude.tools.timed-sequence])
- (:use [clojure.test])
- (:import java.util.Date))
-
-(defmacro how-long-ms [& x]
- "Returns a veactor with first element the result of the body, and second element the number of miliseconds the body took"
-
- `(let [~'todo #(do ~@x)
- ~'start-time (.getTime (Date.))]
- [(~'todo) (- (.getTime (Date.)) ~'start-time)]))
+ (:use (nl.claude.tools timed-sequence test-tools))
+ (:use clojure.test))
(defmacro test-equal [sequence delay selector]
`(is (= (~selector ~sequence) (doall (~selector (timed-sequence ~sequence ~delay)))) (str "expected sequences to be equal: (" '~selector '~sequence ") with delay " ~delay)))

0 comments on commit 85ef56f

Please sign in to comment.