PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/storm-core/test/clj/backtype/storm/tuple_test.clj

http://github.com/nathanmarz/storm
Clojure | 51 lines | 27 code | 9 blank | 15 comment | 13 complexity | 2169f6e9d202097c029021ce40d895e6 MD5 | raw file
Possible License(s): Apache-2.0
  1. ;; Licensed to the Apache Software Foundation (ASF) under one
  2. ;; or more contributor license agreements. See the NOTICE file
  3. ;; distributed with this work for additional information
  4. ;; regarding copyright ownership. The ASF licenses this file
  5. ;; to you under the Apache License, Version 2.0 (the
  6. ;; "License"); you may not use this file except in compliance
  7. ;; with the License. You may obtain a copy of the License at
  8. ;;
  9. ;; http:;; www.apache.org/licenses/LICENSE-2.0
  10. ;;
  11. ;; Unless required by applicable law or agreed to in writing, software
  12. ;; distributed under the License is distributed on an "AS IS" BASIS,
  13. ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ;; See the License for the specific language governing permissions and
  15. ;; limitations under the License.
  16. (ns backtype.storm.tuple-test
  17. (:use [clojure test])
  18. (:import [backtype.storm.tuple Tuple])
  19. (:use [backtype.storm testing]))
  20. (deftest test-lookup
  21. (let [ tuple (test-tuple [12 "hello"] :fields ["foo" "bar"]) ]
  22. (is (= 12 (tuple "foo")))
  23. (is (= 12 (tuple :foo)))
  24. (is (= 12 (:foo tuple)))
  25. (is (= "hello" (:bar tuple)))
  26. (is (= :notfound (tuple "404" :notfound)))))
  27. (deftest test-indexed
  28. (let [ tuple (test-tuple [12 "hello"] :fields ["foo" "bar"]) ]
  29. (is (= 12 (nth tuple 0)))
  30. (is (= "hello" (nth tuple 1)))))
  31. (deftest test-seq
  32. (let [ tuple (test-tuple [12 "hello"] :fields ["foo" "bar"]) ]
  33. (is (= [["foo" 12] ["bar" "hello"]] (seq tuple)))))
  34. (deftest test-map
  35. (let [tuple (test-tuple [12 "hello"] :fields ["foo" "bar"]) ]
  36. (is (= {"foo" 42 "bar" "hello"} (.getMap (assoc tuple "foo" 42))))
  37. (is (= {"foo" 42 "bar" "hello"} (.getMap (assoc tuple :foo 42))))
  38. (is (= {"bar" "hello"} (.getMap (dissoc tuple "foo"))))
  39. (is (= {"bar" "hello"} (.getMap (dissoc tuple :foo))))
  40. (is (= {"foo" 42 "bar" "world"} (.getMap (assoc
  41. (assoc tuple "foo" 42)
  42. :bar "world"))))))