forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e48327
commit ddeff1a
Showing
7 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/target | ||
/classes | ||
/checkouts | ||
profiles.clj | ||
pom.xml | ||
pom.xml.asc | ||
*.jar | ||
*.class | ||
/.lein-* | ||
/.nrepl-port | ||
/.prepl-port | ||
.hgignore | ||
.hg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: all | ||
all: test | ||
|
||
.PHONY: test | ||
test: | ||
lein test | ||
|
||
.PHONY: run | ||
run: | ||
lein run | ||
|
||
.PHONY: clean | ||
clean:: | ||
lein clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# expensereport-clojure | ||
|
||
A Clojure library designed to ... well, that part is up to you. | ||
|
||
## Usage | ||
|
||
FIXME | ||
|
||
## License | ||
|
||
Copyright © 2021 FIXME | ||
|
||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0. | ||
|
||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the Eclipse | ||
Public License, v. 2.0 are satisfied: GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or (at your | ||
option) any later version, with the GNU Classpath Exception which is available | ||
at https://www.gnu.org/software/classpath/license.html. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(defproject expensereport-clojure "0.1.0-SNAPSHOT" | ||
:description "Expense Report example in Clojure" | ||
:dependencies [[org.clojure/clojure "1.10.1"]] | ||
:main expensereport-clojure.core/main | ||
:repl-options {:init-ns expensereport-clojure.core}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(ns expensereport-clojure.core) | ||
|
||
(defn expense [type amount] {:type type :amount amount}) | ||
|
||
(defn print-report | ||
[expenses] | ||
(def total (atom 0)) | ||
(def meal-expenses (atom 0)) | ||
(println "Expenses: " (.toString (java.util.Date.))) | ||
(doall (for [expense (into #{} expenses)] (do | ||
(if (or (= (:type expense) :breakfast) (= (:type expense) :dinner)) (reset! meal-expenses (+ @meal-expenses (:amount expense)))) | ||
(def expense-name (case (:type expense) | ||
:car-rental "Car Rental" | ||
:breakfast "Breakfast" | ||
:dinner "Dinner")) | ||
(def mealOverExpensesMarker (if (or (and (= (:type expense) :breakfast) (>= (:amount expense) 1000)) (and (= (:type expense) :dinner) (>= (:amount expense) 5000))) "X" " ")) | ||
(println expense-name "\t" (:amount expense) "\t" mealOverExpensesMarker) | ||
(reset! total (+ @total (:amount expense)))))) | ||
(println "Meal expenses: " @meal-expenses) | ||
(println "Total expenses: " @total) | ||
) | ||
|
||
(defn main [] | ||
(print-report [(expense :car-rental 100) (expense :breakfast 1000) (expense :breakfast 1001) (expense :dinner 5000) (expense :dinner 5001)]) | ||
) |
7 changes: 7 additions & 0 deletions
7
expensereport-clojure/test/expensereport_clojure/core_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns expensereport-clojure.core-test | ||
(:require [clojure.test :refer :all] | ||
[expensereport-clojure.core :refer :all])) | ||
|
||
(deftest a-test | ||
(testing "FIXME, I fail." | ||
(is (= 1 1)))) |