|
| 1 | +; MIT License |
| 2 | +; |
| 3 | +; Copyright (c) 2016 Andy Best |
| 4 | +; |
| 5 | +; Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +; of this software and associated documentation files (the "Software"), to deal |
| 7 | +; in the Software without restriction, including without limitation the rights |
| 8 | +; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +; copies of the Software, and to permit persons to whom the Software is |
| 10 | +; furnished to do so, subject to the following conditions: |
| 11 | +; |
| 12 | +; The above copyright notice and this permission notice shall be included in all |
| 13 | +; copies or substantial portions of the Software. |
| 14 | +; |
| 15 | +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +; SOFTWARE. |
| 22 | + |
| 23 | +(ns core-tests |
| 24 | + (:refer core.test)) |
| 25 | + |
| 26 | +(deftest map-applies-function-to-items () |
| 27 | + (let (test-input '(1 2 3 4 5 6) |
| 28 | + add-fn #((x) (+ x 1))) |
| 29 | + |
| 30 | + (assertEqual |
| 31 | + (map add-fn test-input) |
| 32 | + '(2 3 4 5 6 7)))) |
| 33 | + |
| 34 | +(deftest reduce-reduces-values () |
| 35 | + (let (test-input '(1 2 3 4 5) |
| 36 | + add-fn #((x y) (+ x y))) |
| 37 | + |
| 38 | + (assertEqual |
| 39 | + (reduce add-fn 0 test-input) |
| 40 | + 15))) |
| 41 | + |
| 42 | +(deftest filter-filters-values () |
| 43 | + (let (test-input '(1 2 3 4 5 6 7 8 9 10) |
| 44 | + test-fn #((x) (== (mod x 2) 0))) |
| 45 | + |
| 46 | + (assertEqual |
| 47 | + (filter test-fn test-input) |
| 48 | + '(2 4 6 8 10)))) |
| 49 | + |
| 50 | +(deftest second-returns-second-item () |
| 51 | + (assertEqual |
| 52 | + (second '(1 2 3 4)) |
| 53 | + 2)) |
| 54 | + |
| 55 | +(deftest reverse-reverses-list () |
| 56 | + (assertEqual |
| 57 | + (reverse '(1 2 3 4)) |
| 58 | + '(4 3 2 1))) |
| 59 | + |
| 60 | +(deftest reverse-reverses-string () |
| 61 | + (assertEqual |
| 62 | + (reverse "Hello") |
| 63 | + "olleH")) |
| 64 | + |
| 65 | + |
| 66 | +(deftest less-than-or-equal () |
| 67 | + (assert (<= 2 10)) |
| 68 | + (assert (<= 2 2)) |
| 69 | + (assert (! (<= 10 2)))) |
| 70 | + |
| 71 | +(deftest greater-than-or-equal () |
| 72 | + (assert (>= 10 2)) |
| 73 | + (assert (>= 10 10)) |
| 74 | + (assert (! (>= 10 20)))) |
0 commit comments