Skip to content

Commit

Permalink
Update trinary
Browse files Browse the repository at this point in the history
- Restructure per #84 and #88
- Be explicit in :require from of trinary_test.clj
- Use single-pass loop/recur implementation
  • Loading branch information
yurrriq committed Dec 29, 2015
1 parent 9681aed commit 4c51343
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
15 changes: 0 additions & 15 deletions trinary/example.clj

This file was deleted.

2 changes: 0 additions & 2 deletions trinary/project.clj
@@ -1,6 +1,4 @@
(defproject trinary "0.1.0-SNAPSHOT"
:description "trinary exercise."
:url "https://github.com/exercism/xclojure/tree/master/trinary"
:source-paths [""]
:test-paths [""]
:dependencies [[org.clojure/clojure "1.7.0"]])
10 changes: 10 additions & 0 deletions trinary/src/example.clj
@@ -0,0 +1,10 @@
(ns trinary)

(defn to-decimal [num]
(loop [sum 0, num num]
(if (empty? num)
sum
(let [diff (.compareTo (first num) \0)]
(if (<= 0 diff 2)
(recur (+ (* sum 3) diff) (next num))
0)))))
6 changes: 3 additions & 3 deletions trinary/trinary_test.clj → trinary/test/trinary_test.clj
@@ -1,6 +1,6 @@
(ns trinary-test
(:require [clojure.test :refer :all]
[trinary :refer :all]))
(:require [clojure.test :refer [deftest is testing]]
[trinary :refer [to-decimal]]))

(deftest trinary-1-is-decimal-1
(testing "1 should still be 1"
Expand Down Expand Up @@ -40,4 +40,4 @@

(deftest invalid-input-with-digits-is-decimal-0
(testing "0a1b2c should be 0"
(is (= 0 (to-decimal "0a1b2c")))))
(is (= 0 (to-decimal "0a1b2c")))))

0 comments on commit 4c51343

Please sign in to comment.