From 554d9c168d05f6b92d1d917dbb93c275bfeddf72 Mon Sep 17 00:00:00 2001 From: rsquelbut Date: Fri, 1 Feb 2019 23:39:05 +0100 Subject: [PATCH 01/11] configure le projet pour pouvoir Lancer les tests --- .gitignore | 1 + .travis.yml | 2 +- project.clj | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ee508f76..950ca79c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pom.xml .lein-deps-sum .lein-failures .lein-plugins +/.idea/\ diff --git a/.travis.yml b/.travis.yml index 455f3c0e..aaa8fab7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: clojure lein: lein2 script: lein2 midje :config .midje-grading-config.clj jdk: - - openjdk7 + - openjdk11 notifications: email: false webhooks: http://polar-hollows-8825.herokuapp.com/notifications diff --git a/project.clj b/project.clj index a7ba528d..3bc3776f 100644 --- a/project.clj +++ b/project.clj @@ -1,5 +1,6 @@ (defproject structured-data "1.0.0-SNAPSHOT" - :dependencies [[org.clojure/clojure "1.5.1"] + :dependencies [[org.clojure/clojure "1.10.0"] [iloveponies.tests/structured-data "0.1.0-SNAPSHOT"]] - :profiles {:dev {:plugins [[lein-midje "3.1.1"]]}}) + :profiles {:dev {:dependencies [[midje "1.9.5" :exclusions [org.clojure/clojure]]] + :plugins [[lein-midje "3.2.1"]]}}) From 6a6448db82a7cc828fbbfb8d40ae8b3aed2e17a8 Mon Sep 17 00:00:00 2001 From: rsquelbut Date: Fri, 1 Feb 2019 23:40:22 +0100 Subject: [PATCH 02/11] corrige le fichier gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 950ca79c..e1c1d2ff 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ pom.xml .lein-deps-sum .lein-failures .lein-plugins -/.idea/\ +.idea/ From b84c31045634787cf1cfd633d3c3543b83d5d8be Mon Sep 17 00:00:00 2001 From: rsquelbut Date: Sun, 10 Feb 2019 21:12:53 +0100 Subject: [PATCH 03/11] en attendant de faire mieux --- src/structured_data.clj | 46 ++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index ebfe1ce4..95833fee 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -1,16 +1,20 @@ (ns structured-data) (defn do-a-thing [x] - :-) + (let [thing (+ x x)] + (Math/pow thing thing))) (defn spiff [v] - :-) + (let [first (get v 0) + second (get v 2)] + (+ first second))) (defn cutify [v] - :-) + (conj v "<3")) (defn spiff-destructuring [v] - :-) + (let [[a ? b] v] + (+ a b))) (defn point [x y] [x y]) @@ -19,34 +23,48 @@ [bottom-left top-right]) (defn width [rectangle] - :-) + (let [[[x1 ?] [x2 ?]] rectangle] + (- x2 x1))) (defn height [rectangle] - :-) + (let [[[? y1] [? y2]] rectangle] + (- y2 y1))) (defn square? [rectangle] - :-) + (== (height rectangle) (width rectangle))) (defn area [rectangle] - :-) + (* (height rectangle) (width rectangle))) (defn contains-point? [rectangle point] - :-) + (let [[[x1 y1] [x2 y2]] rectangle + [a b] point + left-in (>= a x1) + right-in (<= a x2) + bottom-in (>= b y1) + top-in (<= b y2)] + (and left-in right-in bottom-in top-in) + )) (defn contains-rectangle? [outer inner] - :-) + (let [[bottom-left top-right] inner + bottom-left-in (contains-point? outer bottom-left) + top-right-in (contains-point? outer top-right)] + (and bottom-left-in top-right-in) + )) (defn title-length [book] - :-) + (count (:title book))) (defn author-count [book] - :-) + (count (:authors book))) (defn multiple-authors? [book] - :-) + (> (author-count book) 1)) (defn add-author [book new-author] - :-) + (let [new-authors (conj (:authors book) new-author)] + (assoc book :authors new-authors))) (defn alive? [author] :-) From b3297a2535d4725be882f3c087519323d72220b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Tue, 14 May 2019 11:50:29 +0200 Subject: [PATCH 04/11] add all exercices to monotonic --- .gitignore | 1 + src/structured_data.clj | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index e1c1d2ff..4bcc085a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pom.xml .lein-failures .lein-plugins .idea/ +*.iml diff --git a/src/structured_data.clj b/src/structured_data.clj index 95833fee..e8237884 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -67,22 +67,24 @@ (assoc book :authors new-authors))) (defn alive? [author] - :-) + (not (contains? author :death-year))) (defn element-lengths [collection] - :-) + (map count collection)) (defn second-elements [collection] - :-) + (let [second + (fn [coll] (get coll 1))] + (map second collection))) (defn titles [books] - :-) - -(defn monotonic? [a-seq] - :-) + (map :title books)) (defn stars [n] - :-) + (apply str (repeat n "*"))) + +(defn monotonic? [a-seq] + (or (apply <= a-seq) (apply >= a-seq))) (defn toggle [a-set elem] :-) From f8724351f2fc41517995fc1e2d04e6c5a18d6888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Tue, 14 May 2019 12:05:35 +0200 Subject: [PATCH 05/11] add exercice 20 --- src/structured_data.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index e8237884..06cc5d0f 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -87,7 +87,9 @@ (or (apply <= a-seq) (apply >= a-seq))) (defn toggle [a-set elem] - :-) + (if (contains? a-set elem ) + (disj a-set elem) + (conj a-set elem))) (defn contains-duplicates? [a-seq] :-) From b51408e3e85ca7e935d93eb81c7c61c68dc4781b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Tue, 14 May 2019 15:16:13 +0200 Subject: [PATCH 06/11] add exercices 21 / 22 / 23 --- src/structured_data.clj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index 06cc5d0f..1ea7f803 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -92,13 +92,15 @@ (conj a-set elem))) (defn contains-duplicates? [a-seq] - :-) + (< (count (set a-seq)) + (count a-seq))) (defn old-book->new-book [book] - :-) + (let [authors (set (:authors book))] + (assoc book :authors authors))) (defn has-author? [book author] - :-) + (contains? (:authors book) author)) (defn authors [books] :-) @@ -134,3 +136,5 @@ :-) ; %________% +(comment + (print "coucou")) \ No newline at end of file From cbbff588793a86ae627d72e3f4a4882d09861b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Tue, 14 May 2019 15:58:39 +0200 Subject: [PATCH 07/11] add exercices 24 / 25 / 26 --- src/structured_data.clj | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index 1ea7f803..539110dc 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -87,7 +87,7 @@ (or (apply <= a-seq) (apply >= a-seq))) (defn toggle [a-set elem] - (if (contains? a-set elem ) + (if (contains? a-set elem) (disj a-set elem) (conj a-set elem))) @@ -103,13 +103,16 @@ (contains? (:authors book) author)) (defn authors [books] - :-) + (set (apply concat (map :authors books)))) (defn all-author-names [books] - :-) + (set (map :name (authors books)))) (defn author->string [author] - :-) + (let [life-info + (fn [author] (if (or (:birth-year author) (:death-year author)) + (str " (" (:birth-year author) " - " (:death-year author) ")")))] + (apply str (:name author) (life-info author)))) (defn authors->string [authors] :-) @@ -137,4 +140,17 @@ ; %________% (comment - (print "coucou")) \ No newline at end of file + (def china {:name "China MiƩville", :birth-year 1972}) + (def octavia {:name "Octavia E. Butler" + :birth-year 1947 + :death-year 2006}) + (def friedman {:name "Daniel Friedman" :birth-year 1944}) + (def felleisen {:name "Matthias Felleisen"}) + + (def cities {:title "The City and the City" :authors #{china}}) + (def wild-seed {:title "Wild Seed", :authors #{octavia}}) + (def embassytown {:title "Embassytown", :authors #{china}}) + (def little-schemer {:title "The Little Schemer" + :authors #{friedman, felleisen}}) + + (def books [cities, wild-seed, embassytown, little-schemer])) \ No newline at end of file From 7817c997c885660b6886db5435a0c0b60654a325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Wed, 15 May 2019 15:21:57 +0200 Subject: [PATCH 08/11] add exercices 27 / 28 / 29 --- src/structured_data.clj | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index 539110dc..3717d70d 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -115,13 +115,18 @@ (apply str (:name author) (life-info author)))) (defn authors->string [authors] - :-) + (apply str (interpose ", " (map author->string authors)))) (defn book->string [book] - :-) + (apply str (interpose ", written by " [(:title book), (authors->string (authors [book]))]))) (defn books->string [books] - :-) + (let [print-book-numbers + (fn [library] (cond + (empty? library) "No books. " + (= (count library) 1) "1 book. " + :else (str (count library) " books. ")))] + (apply str (print-book-numbers books), (interpose ". " (map book->string books))))) (defn books-by-author [author books] :-) From 8d09445631d3f68b63160a97c23c74f06443bdf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Wed, 15 May 2019 17:35:27 +0200 Subject: [PATCH 09/11] addlast exercices --- src/structured_data.clj | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index 3717d70d..e4996a58 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -129,33 +129,20 @@ (apply str (print-book-numbers books), (interpose ". " (map book->string books))))) (defn books-by-author [author books] - :-) + (filter (fn [book] (has-author? book author)) books)) (defn author-by-name [name authors] - :-) + (let [results (filter (fn [author] (= name (:name author))) authors)] + (if (empty? results) + nil + (first results))) + ) (defn living-authors [authors] - :-) + (filter (fn [author] (alive? author)) authors)) (defn has-a-living-author? [book] - :-) + (< 0 (count (living-authors (:authors book))))) (defn books-by-living-authors [books] - :-) - -; %________% -(comment - (def china {:name "China MiƩville", :birth-year 1972}) - (def octavia {:name "Octavia E. Butler" - :birth-year 1947 - :death-year 2006}) - (def friedman {:name "Daniel Friedman" :birth-year 1944}) - (def felleisen {:name "Matthias Felleisen"}) - - (def cities {:title "The City and the City" :authors #{china}}) - (def wild-seed {:title "Wild Seed", :authors #{octavia}}) - (def embassytown {:title "Embassytown", :authors #{china}}) - (def little-schemer {:title "The Little Schemer" - :authors #{friedman, felleisen}}) - - (def books [cities, wild-seed, embassytown, little-schemer])) \ No newline at end of file + (filter (fn [current] (has-a-living-author? current)) books)) From db655c3d1b34dbab2545ac9e597d7fb87cb4aed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Wed, 15 May 2019 17:35:44 +0200 Subject: [PATCH 10/11] addlast exercices --- src/structured_data.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index e4996a58..e7813777 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -126,7 +126,7 @@ (empty? library) "No books. " (= (count library) 1) "1 book. " :else (str (count library) " books. ")))] - (apply str (print-book-numbers books), (interpose ". " (map book->string books))))) + (apply str (print-book-numbers books) (interpose ". " (map book->string books))))) (defn books-by-author [author books] (filter (fn [book] (has-author? book author)) books)) From 32df9e30db1eb9d607f008820b5060a7cfdd12f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Squelbut?= Date: Wed, 15 May 2019 18:14:20 +0200 Subject: [PATCH 11/11] fix books->string function --- src/structured_data.clj | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/structured_data.clj b/src/structured_data.clj index e7813777..6021501f 100644 --- a/src/structured_data.clj +++ b/src/structured_data.clj @@ -121,12 +121,10 @@ (apply str (interpose ", written by " [(:title book), (authors->string (authors [book]))]))) (defn books->string [books] - (let [print-book-numbers - (fn [library] (cond - (empty? library) "No books. " - (= (count library) 1) "1 book. " - :else (str (count library) " books. ")))] - (apply str (print-book-numbers books) (interpose ". " (map book->string books))))) + (cond + (empty? books) "No books." + (= (count books) 1) (str "1 book. " (book->string (get books 0)) ".") + :else (str (count books) " books. " (apply str (interpose ". " (map book->string books))) "."))) (defn books-by-author [author books] (filter (fn [book] (has-author? book author)) books)) @@ -146,3 +144,4 @@ (defn books-by-living-authors [books] (filter (fn [current] (has-a-living-author? current)) books)) +