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
33985b9
commit 91e473f
Showing
5 changed files
with
387 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.PHONY: all | ||
all: | ||
go build ./... | ||
~/go/bin/godog |
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,55 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type ExpenseType int | ||
|
||
const ( | ||
Dinner ExpenseType = iota + 1 | ||
Breakfast | ||
CarRental | ||
) | ||
|
||
type Expense struct { | ||
Type ExpenseType | ||
Amount int | ||
} | ||
|
||
func PrintReport(expenses []Expense) { | ||
total := 0 | ||
mealExpenses := 0 | ||
|
||
fmt.Printf("Expenses %s\n", time.Now().Format("2006-01-02")) | ||
|
||
for _, expense := range expenses { | ||
if expense.Type == Dinner || expense.Type == Breakfast { | ||
mealExpenses += expense.Amount | ||
} | ||
|
||
var expenseName string | ||
switch expense.Type { | ||
case Dinner: | ||
expenseName = "Dinner" | ||
case Breakfast: | ||
expenseName = "Breakfast" | ||
case CarRental: | ||
expenseName = "Car Rental" | ||
} | ||
|
||
var mealOverExpensesMarker string | ||
if expense.Type == Dinner && expense.Amount > 5000 || expense.Type == Breakfast && expense.Amount > 1000 { | ||
mealOverExpensesMarker = "X" | ||
} else { | ||
mealOverExpensesMarker = " " | ||
} | ||
|
||
fmt.Printf("%s\t%d\t%s\n", expenseName, expense.Amount, mealOverExpensesMarker) | ||
total += expense.Amount | ||
} | ||
|
||
fmt.Printf("Meal expenses: %d\n", mealExpenses) | ||
fmt.Printf("Total expenses: %d\n", total) | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
module expenses | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/cucumber/godog v0.12.4 | ||
github.com/cucumber/messages-go/v16 v16.0.1 | ||
) | ||
|
||
require ( | ||
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect | ||
github.com/gofrs/uuid v4.0.0+incompatible // indirect | ||
github.com/hashicorp/go-immutable-radix v1.3.0 // indirect | ||
github.com/hashicorp/go-memdb v1.3.0 // indirect | ||
github.com/hashicorp/golang-lru v0.5.4 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
Oops, something went wrong.