diff --git a/.gitignore b/.gitignore index bea0b49..3016b53 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /lib /classes /autodoc/** +/target/ +.nrepl-port \ No newline at end of file diff --git a/README.md b/README.md index 751b5e2..cd16389 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ There are several more namespaces for generating: * Domains and emails * Telephone numbers * Text +* Commerce Take a look at the documentation generated with autodoc [here](http://paraseba.github.com/faker) diff --git a/project.clj b/project.clj index 6056cde..25fdec2 100644 --- a/project.clj +++ b/project.clj @@ -2,4 +2,4 @@ :description "Generate fake data, port of ruby faker" :url "http://github.com/paraseba/faker" :license "Eclipse Public License 1.0" - :dependencies [[org.clojure/clojure "1.2.0"]]) + :dependencies [[org.clojure/clojure "1.7.0"]]) diff --git a/src/faker/commerce.clj b/src/faker/commerce.clj new file mode 100644 index 0000000..111e7f4 --- /dev/null +++ b/src/faker/commerce.clj @@ -0,0 +1,46 @@ +(ns faker.commerce + (:require [faker.commerce-data :as d])) + + +(defn product-name + [] + (let [adj (rand-nth (:adjective d/product-name)) + material (rand-nth (:material d/product-name)) + product (rand-nth (:product d/product-name))] + (str adj " " material " " product))) + +(defn price + ([] + (price 100)) + ([upper-bound] + (price 0 upper-bound)) + ([lower-bound upper-bound] + {:pre [(> upper-bound lower-bound)]} + (let [diff (- upper-bound lower-bound) + upper-with-dec (* 100 diff) + picked (rand-int upper-with-dec) + normalized (/ (float picked) 100) + shifted (+ normalized lower-bound) + formatted (format "%.2f" shifted) + numberized (read-string formatted)] + numberized))) + +(defn department + [] + (rand-nth d/department)) + +(defn material + [] + (rand-nth (:material d/product-name))) + +(defn adjective + [] + (rand-nth (:adjective d/product-name))) + +(defn product + [] + (rand-nth (:product d/product-name))) + +(defn color + [] + (rand-nth d/color)) diff --git a/src/faker/commerce_data.clj b/src/faker/commerce_data.clj new file mode 100644 index 0000000..cc6ba7c --- /dev/null +++ b/src/faker/commerce_data.clj @@ -0,0 +1,9 @@ +(ns faker.commerce-data) + +(def product-name {:product ["Chair", "Car", "Computer", "Gloves", "Pants", "Shirt", "Table", "Shoes", "Hat", "Plate", "Knife", "Bottle", "Coat", "Lamp", "Keyboard", "Bag", "Bench", "Clock", "Watch", "Wallet"] + :material ["Steel", "Wooden", "Concrete", "Plastic", "Cotton", "Granite", "Rubber", "Leather", "Silk", "Wool", "Linen", "Marble", "Iron", "Bronze", "Copper", "Aluminum", "Paper"] + :adjective ["Small", "Ergonomic", "Rustic", "Intelligent", "Gorgeous", "Incredible", "Fantastic", "Practical", "Sleek", "Awesome", "Enormous", "Mediocre", "Synergistic", "Heavy Duty", "Lightweight", "Aerodynamic", "Durable"]}) + +(def department ["Books", "Movies", "Music", "Games", "Electronics", "Computers", "Home", "Garden", "Tools", "Grocery", "Health", "Beauty", "Toys", "Kids", "Baby", "Clothing", "Shoes", "Jewelery", "Sports", "Outdoors", "Automotive", "Industrial"]) + +(def color ["Red" "Green" "Blue" "Yellow" "Purple" "Mint green" "Teal" "White" "Black" "Orange" "Pink" "Grey" "Maroon" "Violet" "Turquoise" "Tan" "Sky Blue" "Salmon" "Plum" "Orchid" "Olive" "Magenta" "Lime" "Ivory" "Indigo" "Gold" "Fuchsia" "Cyan" "Azure" "Lavender" "Silver"]) diff --git a/test/faker/commerce_test.clj b/test/faker/commerce_test.clj new file mode 100644 index 0000000..25d244a --- /dev/null +++ b/test/faker/commerce_test.clj @@ -0,0 +1,22 @@ +(ns faker.commerce-test + (:require [faker.commerce :as com] + [clojure.test :refer [deftest is]])) + +(deftest product + (is (com/product-name)) + (is (com/product)) + (is (com/material)) + (is (com/adjective))) + +(deftest color + (is (com/color))) + +(deftest department + (is (com/department))) + +(deftest price + (is (com/price)) + (is (com/price 10)) + (is (com/price 5 10)) + (is (thrown? AssertionError (com/price 10 5)))) +