Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/lib
/classes
/autodoc/**
/target/
.nrepl-port
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"]])
46 changes: 46 additions & 0 deletions src/faker/commerce.clj
Original file line number Diff line number Diff line change
@@ -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))
9 changes: 9 additions & 0 deletions src/faker/commerce_data.clj
Original file line number Diff line number Diff line change
@@ -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"])
22 changes: 22 additions & 0 deletions test/faker/commerce_test.clj
Original file line number Diff line number Diff line change
@@ -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))))