Repository: exercism/clojure
Pull request #284 (2019-11-25 15:01:39)

Update tests for 'Triangle' exercise
Updated tests based on the problem specifications. Also updated the example.


Patch:
diff --git a/config.json b/config.json
index 5f7bc86..0eb5a4a 100644
--- a/config.json
+++ b/config.json
@@ -12,16 +12,6 @@
       "difficulty": 1,
       "topics": null
     },
-    {
-      "slug": "armstrong-numbers",
-      "uuid": "a4bdbdfd-1db1-425c-a243-dd032dc7b93a",
-      "core": false,
-      "unlocked_by": null,
-      "difficulty": 1,
-      "topics": [
-        "math"
-      ]
-    },
     {
       "slug": "two-fer",
       "uuid": "91a1f32c-0dac-4c65-8a13-49da90d21520",
@@ -46,6 +36,16 @@
       "difficulty": 2,
       "topics": null
     },
+    {
+      "slug": "armstrong-numbers",
+      "uuid": "a4bdbdfd-1db1-425c-a243-dd032dc7b93a",
+      "core": false,
+      "unlocked_by": null,
+      "difficulty": 1,
+      "topics": [
+        "math"
+      ]
+    },
     {
       "slug": "rna-transcription",
       "uuid": "c2100dff-4d18-4fcb-9035-6c57eddd6d37",
diff --git a/config/maintainers.json b/config/maintainers.json
index 72311f2..5bd6fbb 100644
--- a/config/maintainers.json
+++ b/config/maintainers.json
@@ -40,6 +40,26 @@
       "link_url": null,
       "avatar_url": null,
       "bio": null
+    },
+    {
+      "github_username": "porkostomus",
+      "alumnus": false,
+      "show_on_website": false,
+      "name": "Bobby Towers",
+      "link_text": null,
+      "link_url": null,
+      "avatar_url": null,
+      "bio": null
+    },
+    {
+      "github_username": "bemself",
+      "alumnus": false,
+      "show_on_website": false,
+      "name": null,
+      "link_text": null,
+      "link_url": null,
+      "avatar_url": null,
+      "bio": null
     }
   ]
 }
diff --git a/exercises/bob/src/example.clj b/exercises/bob/src/example.clj
index fd4d2d4..484c693 100644
--- a/exercises/bob/src/example.clj
+++ b/exercises/bob/src/example.clj
@@ -14,9 +14,11 @@
   (and (shouting? msg) (question? msg)))
 
 (defn response-for [input]
-  (cond
-    (forceful-question? input) "Calm down, I know what I'm doing!"
-    (silence?  input) "Fine. Be that way!"
-    (shouting? input) "Whoa, chill out!"
-    (question? input) "Sure."
-    :else             "Whatever."))
+  (let [clean (str/trim input)]
+    (cond
+      (forceful-question? clean) "Calm down, I know what I'm doing!"
+      (silence?  clean) "Fine. Be that way!"
+      (shouting? clean) "Whoa, chill out!"
+      (question? clean) "Sure."
+      :else             "Whatever.")))
+
diff --git a/exercises/triangle/src/example.clj b/exercises/triangle/src/example.clj
index 25321b4..8bc770d 100644
--- a/exercises/triangle/src/example.clj
+++ b/exercises/triangle/src/example.clj
@@ -1,10 +1,17 @@
-(ns triangle
-  (:refer-clojure :exclude [type]))
-
-(defn type [a b c]
-  (let [sorted (sort > [a b c])]
-    (if (>= (first sorted) (apply + (rest sorted))) :illogical
-        (case (count (set sorted))
-          1 :equilateral
-          2 :isosceles
-          3 :scalene))))
+(ns triangle)
+
+(defn is-valid? [s1 s2 s3]
+  (and
+   (> s1 0) (> s2 0) (> s3 0)
+   (>= (+ s1 s2) s3)
+   (>= (+ s1 s3) s2)
+   (>= (+ s2 s3) s1)))
+
+(defn equilateral? [s1 s2 s3]
+  (and (is-valid? s1 s2 s3) (= s1 s2 s3)))
+
+(defn isosceles? [s1 s2 s3]
+  (and (is-valid? s1 s2 s3) (or (= s1 s2) (= s1 s3) (= s2 s3))))
+
+(defn scalene? [s1 s2 s3]
+  (and (not (isosceles? s1 s2 s3)) (is-valid? s1 s2 s3)))
\ No newline at end of file
diff --git a/exercises/triangle/src/triangle.clj b/exercises/triangle/src/triangle.clj
index 513a648..212b3a2 100644
--- a/exercises/triangle/src/triangle.clj
+++ b/exercises/triangle/src/triangle.clj
@@ -1,5 +1,17 @@
 (ns triangle)
 
-(defn type [] ;; <- arglist goes here
-      ;; your code goes here
+(defn is-valid? [] ;; <- arglist goes here
+  ;; your code goes here
+)
+
+(defn equilateral? [] ;; <- arglist goes here
+  ;; your code goes here
+)
+
+(defn isosceles? [] ;; <- arglist goes here
+  ;; your code goes here
+)
+
+(defn scalene? [] ;; <- arglist goes here
+  ;; your code goes here
 )


Test patch:
diff --git a/exercises/armstrong-numbers/test/armstrong_numbers_test.clj b/exercises/armstrong-numbers/test/armstrong_numbers_test.clj
index a0ae527..682e532 100644
--- a/exercises/armstrong-numbers/test/armstrong_numbers_test.clj
+++ b/exercises/armstrong-numbers/test/armstrong_numbers_test.clj
@@ -2,6 +2,10 @@
   (:require [clojure.test :refer [deftest is testing]]
             [armstrong-numbers :refer [armstrong?]]))
 
+(deftest armstrong-number-0
+  (testing "Zero is an Armstrong number"
+    (is (armstrong? 0))))
+
 (deftest armstrong-number-5
   (testing "Single digit numbers are Armstrong numbers"
     (is (armstrong? 5))))
diff --git a/exercises/bob/test/bob_test.clj b/exercises/bob/test/bob_test.clj
index 2e774eb..eea5bec 100644
--- a/exercises/bob/test/bob_test.clj
+++ b/exercises/bob/test/bob_test.clj
@@ -8,10 +8,19 @@
 (deftest responds-to-shouts
   (is (= "Whoa, chill out!" (bob/response-for "WATCH OUT!"))))
 
+(deftest responds-to-shouting-gibberish
+  (is (= "Whoa, chill out!" (bob/response-for "FCECDFCAAB"))))
+
 (deftest responds-to-questions
   (is (= "Sure."
          (bob/response-for "Does this cryogenic chamber make me look fat?"))))
 
+(deftest responds-to-numeric-question
+  (is (= "Sure." (bob/response-for "You are, what, like 15?"))))
+
+(deftest responds-to-gibberish-question
+  (is (= "Sure." (bob/response-for "fffbbcbeab?"))))
+
 (deftest responds-to-forceful-talking
   (is (= "Whatever." (bob/response-for "Let's go make out behind the gym!"))))
 
@@ -23,27 +32,53 @@
   (is (= "Calm down, I know what I'm doing!"
          (bob/response-for "WHAT THE HELL WERE YOU THINKING?"))))
 
+(deftest responds-to-shouting-numbers
+  (is (= "Whoa, chill out!" (bob/response-for "1, 2, 3 GO!"))))
+
+(deftest responds-to-no-letters
+  (is (= "Whatever." (bob/response-for "1, 2, 3"))))
+
+(deftest responds-to-question-with-no-letters
+  (is (= "Sure." (bob/response-for "4?"))))
+
 (deftest responds-to-shouting-with-special-characters
   (is (= "Whoa, chill out!"
          (bob/response-for "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"))))
 
-(deftest responds-to-shouting-numbers
-  (is (= "Whoa, chill out!" (bob/response-for "1, 2, 3 GO!"))))
-
 (deftest responds-to-shouting-with-no-exclamation-mark
-  (is (= "Whoa, chill out!" (bob/response-for "I HATE YOU"))))
+  (is (= "Whoa, chill out!" (bob/response-for "I HATE THE DMV"))))
 
 (deftest responds-to-statement-containing-question-mark
   (is (= "Whatever." (bob/response-for "Ending with ? means a question."))))
 
+(deftest responds-to-non-letters-with-question
+  (is (= "Sure." (bob/response-for ":) ?"))))
+
+(deftest responds-to-prattling-on
+  (is (= "Sure." (bob/response-for "Wait! Hang on. Are you going to be OK?"))))
+
 (deftest responds-to-silence
   (is (= "Fine. Be that way!" (bob/response-for ""))))
 
 (deftest responds-to-prolonged-silence
   (is (= "Fine. Be that way!" (bob/response-for "    "))))
 
-(deftest responds-to-only-numbers
-  (is (= "Whatever." (bob/response-for "1, 2, 3"))))
+(deftest responds-to-alternate-silence
+  (is (= "Fine. Be that way!" (bob/response-for "\t\t\t\t\t\t\t\t\t\t"))))
 
-(deftest responds-to-number-question
-  (is (= "Sure." (bob/response-for "4?"))))
+(deftest responds-to-multiple-line-question
+  (is (= "Whatever."
+         (bob/response-for "\nDoes this cryogenic chamber make me look fat?\nNo."))))
+
+(deftest responds-to-starting-with-whitespace
+  (is (= "Whatever." (bob/response-for "         hmmmmmmm..."))))
+
+(deftest responds-to-ending-with-whitespace
+  (is (= "Sure." (bob/response-for "Okay if like my  spacebar  quite a bit?   "))))
+
+(deftest responds-to-other-whitespace
+  (is (= "Fine. Be that way!" (bob/response-for "\n\r \t"))))
+
+(deftest responds-to-non-question-ending-with-whitespace
+  (is (= "Whatever."
+         (bob/response-for "This is a statement ending with whitespace      "))))
diff --git a/exercises/leap/test/leap_test.clj b/exercises/leap/test/leap_test.clj
index 2c3fd3b..d5851a5 100644
--- a/exercises/leap/test/leap_test.clj
+++ b/exercises/leap/test/leap_test.clj
@@ -2,14 +2,29 @@
   (:require [clojure.test :refer [deftest is]]
             leap))
 
-(deftest vanilla-leap-year
+(deftest year-not-divisible-by-4
+  (is (not (leap/leap-year? 2015))))
+
+(deftest year-divisible-by-2-but-not-4
+  (is (not (leap/leap-year? 1970))))
+
+(deftest year-divisible-by-4-but-not-100
   (is (leap/leap-year? 1996)))
 
-(deftest any-old-year
-  (is (not (leap/leap-year? 1997))))
+(deftest year-divisible-by-4-and-5
+  (is (leap/leap-year? 1960)))
+
+(deftest year-divisible-by-100-but-not-400
+  (is (not (leap/leap-year? 2100))))
 
-(deftest century
+(deftest year-divisible-by-100-but-not-by-3
   (is (not (leap/leap-year? 1900))))
 
-(deftest exceptional-century
+(deftest year-divisible-by-400
+  (is (leap/leap-year? 2000)))
+
+(deftest year-divisible-by-400-but-not-125
   (is (leap/leap-year? 2400)))
+
+(deftest year-divisible-by-200-but-not-by-400
+  (is (not (leap/leap-year? 1800))))
diff --git a/exercises/reverse-string/test/reverse_string_test.clj b/exercises/reverse-string/test/reverse_string_test.clj
index 35c2023..f80d06a 100644
--- a/exercises/reverse-string/test/reverse_string_test.clj
+++ b/exercises/reverse-string/test/reverse_string_test.clj
@@ -20,6 +20,9 @@
 (deftest palindrome-test
   (is (= "racecar" (reverse-string/reverse-string "racecar"))))
 
+(deftest even-sized-word-test
+  (is (= "reward" (reverse-string/reverse-string "drawer"))))
+
 (deftest long-string-test
   (let [s (reduce str (repeat 1000 "overflow?"))
         rs (reduce str (repeat 1000 "?wolfrevo"))]
diff --git a/exercises/triangle/test/triangle_test.clj b/exercises/triangle/test/triangle_test.clj
index 97ede58..feee656 100644
--- a/exercises/triangle/test/triangle_test.clj
+++ b/exercises/triangle/test/triangle_test.clj
@@ -1,29 +1,51 @@
 (ns triangle-test
-  (:require [clojure.test :refer [deftest is]]
+  (:require [clojure.test :refer [deftest is testing]]
             triangle))
 
-(deftest equilateral-1
-  (is (= :equilateral (triangle/type 2 2 2))))
-
-(deftest equilateral-2
-  (is (= :equilateral (triangle/type 10 10 10))))
-
-(deftest isosceles-1
-  (is (= :isosceles (triangle/type 3 4 4))))
-
-(deftest isosceles-2
-  (is (= :isosceles (triangle/type 4 3 4))))
+(deftest equilateral
+  (testing "equilateral triangle"
+    (testing "all sides are equal"
+      (is (true? (triangle/equilateral? 2 2 2))))
+    (testing "any side is unequal"
+      (is (false? (triangle/equilateral? 2 3 2))))
+    (testing "no sides are equal"
+      (is (false? (triangle/equilateral? 5 4 6))))
+    (testing "all zero sides is not a triangle"
+      (is (false? (triangle/equilateral? 0 0 0))))
+    (testing "sides may be floats"
+      (is (true? (triangle/equilateral? 0.5 0.5 0.5))))))
+
+
+(deftest isosceles
+  (testing "isosceles triangle"
+    (testing "last two sides are equal"
+      (is (true? (triangle/isosceles? 3 4 4))))
+    (testing "first two sides are equal"
+      (is (true? (triangle/isosceles? 4 4 3))))
+    (testing "first and last sides are equal"
+      (is (true? (triangle/isosceles? 4 3 4))))
+    (testing "equilateral triangles are also isosceles"
+      (is (true? (triangle/isosceles? 4 4 4))))
+    (testing "no sides are equal"
+      (is (false? (triangle/isosceles? 2 3 4))))
+    (testing "first triangle inequality violation"
+      (is (false? (triangle/isosceles? 1 1 3))))
+    (testing "second triangle inequality violation"
+      (is (false? (triangle/isosceles? 1 3 1))))
+    (testing "third triangle inequality violation"
+      (is (false? (triangle/isosceles? 3 1 1))))
+    (testing "sides may be floats"
+      (is (true? (triangle/isosceles? 0.5 0.4 0.5))))))
 
 (deftest scalene
-  (is (= :scalene (triangle/type 3 4 5))))
-
-(deftest invalid-1
-  (is (= :illogical (triangle/type 1 1 50))))
-
-;; See discussion at https://github.com/exercism/xerlang/issues/85
-
-(deftest invalid-2
-  (is (= :illogical (triangle/type 1 2 1))))
-
-(deftest invalid-3
-  (is (= :illogical (triangle/type 2 4 2))))
+  (testing "scalene triangle"
+    (testing "no sides are equal"
+      (is (true? (triangle/scalene? 5 4 6))))
+    (testing "all sides are equal"
+      (is (false? (triangle/scalene? 4 4 4))))
+    (testing "two sides are equal"
+      (is (false? (triangle/scalene? 4 4 3))))
+    (testing "may not violate triangle inequality"
+      (is (false? (triangle/scalene? 7 3 2))))
+    (testing "sides may be floats"
+      (is (true? (triangle/scalene? 0.5 0.4 0.6))))))