Skip to content

Commit

Permalink
Improve Go version.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhujer committed Mar 19, 2022
1 parent 33985b9 commit 91e473f
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 56 deletions.
2 changes: 1 addition & 1 deletion expensereport-go/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.PHONY: all
all:
go build ./...
~/go/bin/godog
55 changes: 55 additions & 0 deletions expensereport-go/expensereport.go
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)
}
55 changes: 0 additions & 55 deletions expensereport-go/expenses/expensereport.go

This file was deleted.

17 changes: 17 additions & 0 deletions expensereport-go/go.mod
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
)
Loading

0 comments on commit 91e473f

Please sign in to comment.