I need to give an output like this:
/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg
But I think my output is a set:
#{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}
Here is my code:
(ns dirdiff.core
(:gen-class))
(require '[clojure.set])
(defn no-prefix [prefix]
(comp (filter #(clojure.string/starts-with? % prefix))
(map #(subs % (count prefix)))))
(defn load-string-set [a file]
(->> file
slurp
clojure.string/split-lines
(into #{} a)))
(defn deleted-files
[prefix-davor prefix-danach davor danach]
; TODO
(disj (clojure.set/difference (load-string-set (no-prefix prefix-davor) davor)
(load-string-set (no-prefix prefix-danach) danach)) "/Fotos/Azoren-2018/buffet/dc-40.jpg"
"/Fotos/Azoren-2018/buffet/dc-41.jpg"
"/Fotos/Azoren-2018/buffet/dc-42.jpg"
"/Fotos/Azoren-2018/buffet/dc-43.jpg"))
(deleted-files "davor" "danach" "resources/davor.txt" "resources/danach.txt")
Here is the test file:
(ns dirdiff.core-test
(:require [clojure.test :refer :all]
[dirdiff.core :refer :all]))
(deftest show-deleted-test
(testing "Find deleted files"
(let [expected (slurp "resources/erwartet.txt")
actual (deleted-files "davor" "danach" "resources/davor.txt" "resources/danach.txt")]
(is
(= expected
actual)
(str "erwartet:\n" expected "\n\nactual:\n" actual)))))
And here is the bash line command window in full version:
cloud9.bewerber2:~/environment/dirdiff $ lein test
lein test dirdiff.core-test
lein test :only dirdiff.core-test/show-deleted-test
FAIL in (show-deleted-test) (core_test.clj:9)
Find deleted files
erwartet:
/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg
actual:
#{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}
expected: (= expected actual)
actual: (not (= "/Fotos/Azoren-2018/buffet\n/Fotos/Azoren-2018/restaurant/dc\n/Fotos/Azoren-2018/restaurant/dc-41.jpg\n/Fotos/Azoren-2018/restaurant/dc-42.jpg\n/Fotos/Azoren-2018/restaurant/dc-43.jpg\n/Fotos/Mallorca-2017/dc-10.jpg\n/Fotos/Mallorca-2017/dc-11.jpg\n/Fotos/Mallorca-2017/dc-19.jpg" #{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}))
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
Tests failed.
I believe the failure is caused because I couldnt give this exact output:
/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg
Any ideas how can I convert that set into this output?
>Solution :
Use sort with clojure.string/join:
(->> #{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}
sort
(clojure.string/join "\n")
println)
Output:
/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg
=> nil