~willvaughn/kata

b54f87938e44a07e45a0a21f71a30e45ac23b297 — William Vaughn 1 year, 5 months ago 5d77e4d
codewars rgb2hex
A codewars/src/clj/org/willvaughn/codewars/rgb2hex.clj => codewars/src/clj/org/willvaughn/codewars/rgb2hex.clj +10 -0
@@ 0,0 1,10 @@
(ns org.willvaughn.codewars.rgb2hex)

(defn ->hex [n]
  (format "%02X" (min 255 (max 0 n))))

(defn rgb->hex [r g b]
  (->> [r g b]
       (map ->hex)
       (apply str)
       (clojure.string/upper-case)))

A codewars/test/clj/org/willvaughn/codewars/rgb2hex_test.clj => codewars/test/clj/org/willvaughn/codewars/rgb2hex_test.clj +18 -0
@@ 0,0 1,18 @@
(ns org.willvaughn.codewars.rgb2hex-test
  (:require [clojure.test :refer :all]
            [org.willvaughn.codewars.rgb2hex :refer [rgb->hex]]))


(deftest a-test1
         (testing "0 0 0"
                  (is (= "000000" (rgb->hex 0 0 0))))
         (testing "0 0 -20"
                  (is (= "000000" (rgb->hex 0 0 -20))))
         (testing "300 255 255"
                  (is (= "FFFFFF" (rgb->hex 300 255 255))))
         (testing "173 255 47"
                  (is (= "ADFF2F" (rgb->hex 173 255 47))))
         (testing "148 0 211"
                  (is (= "9400D3" (rgb->hex 148 0 211))))
  (testing "212 53 12"
    (is (= "D4350C" (rgb->hex 212 53 12)))))