Skip to content

Commit

Permalink
Import the old repositories.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhujer committed Aug 14, 2021
1 parent 4fe9593 commit 29ecc2f
Show file tree
Hide file tree
Showing 70 changed files with 12,994 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.iml
.idea/
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,22 @@ The goal is to support the following new feature as best as you can:
5. 🔧 Refactor the code.
6. 🔧 Refactor the test.
7. 👼 Test-drive the new feature.

## Supported Languages
The ExpenseReport example currently exists in the following languages:
- [C](expensereport-c/)
- [C#](expensereport-csharp/)
- [C++](expensereport-cxx/)
- [Go](expensereport-go/)
- [Java](expensereport-java/)
- [JavaScript](expensereport-javascript/)
- [Kotlin](expensereport-kotlin/)
- [Python](expensereport-python/)
- [Rust](expensereport-rust/)
- [TypeScript](expensereport-typescript/)

## Credits
I first encountered the ExpenseReport example during a bootcamp at Equal Experts.
I also have seen the ExpenseReport example being used by Robert "Uncle Bob" C. Martin.
I have tried to research its origins but so far I have failed.
If you know who has first come up with this example, please get in touch with me.
1 change: 1 addition & 0 deletions expensereport-c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.[adios]
53 changes: 53 additions & 0 deletions expensereport-c/ExpenseReport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <time.h>

enum Type {
DINNER,
BREAKFAST,
CAR_RENTAL
};

struct Expense {
enum Type type;
int amount;
};

void printExpenses(struct Expense *expenses[], size_t numExpenses) {
int total = 0;
int mealExpenses = 0;

time_t now;
if (time(&now) == -1)
return;

printf("Expenses %s\n", ctime(&now));

for (size_t i = 0; i < numExpenses; i++) {
struct Expense *expense = expenses[i];

if (expense->type == DINNER || expense->type == BREAKFAST) {
mealExpenses += expense->amount;
}

char *expenseName;
switch (expense->type) {
case DINNER:
expenseName = "Dinner";
break;
case BREAKFAST:
expenseName = "Breakfast";
break;
case CAR_RENTAL:
expenseName = "Car Rental";
break;
}

char *mealOverExpensesMarker = ((expense->type == DINNER && expense->amount > 5000) || (expense->type == BREAKFAST && expense->amount > 1000)) ? "X" : " ";

printf("%s\t%d\t%s\n", expenseName, expense->amount, mealOverExpensesMarker);
total += expense->amount;
}

printf("Meal expenses: %d\n", mealExpenses);
printf("Total expenses: %d\n", total);
}
11 changes: 11 additions & 0 deletions expensereport-c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CPPFLAGS:=-MMD
CFLAGS:=-W -Wall -pedantic -Werror

.PHONY: all
all: ExpenseReport.o

.PHONY: clean
clean::
$(RM) *.[adios]

-include *.d
3 changes: 3 additions & 0 deletions expensereport-c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Expense Report C

Kata for Coding Dojos.
4 changes: 4 additions & 0 deletions expensereport-csharp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin/
obj/
/packages/
.idea
22 changes: 22 additions & 0 deletions expensereport-csharp/expensereport-csharp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "expensereport-csharp", "expensereport-csharp\expensereport-csharp.csproj", "{4D670DD0-5E29-49CE-AFE9-F5C7ACDB89D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "expensereport-ut", "expensereport-ut\expensereport-ut.csproj", "{07C2B482-2F0F-4B66-9F09-9D9505C9466E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4D670DD0-5E29-49CE-AFE9-F5C7ACDB89D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D670DD0-5E29-49CE-AFE9-F5C7ACDB89D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D670DD0-5E29-49CE-AFE9-F5C7ACDB89D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D670DD0-5E29-49CE-AFE9-F5C7ACDB89D0}.Release|Any CPU.Build.0 = Release|Any CPU
{07C2B482-2F0F-4B66-9F09-9D9505C9466E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07C2B482-2F0F-4B66-9F09-9D9505C9466E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07C2B482-2F0F-4B66-9F09-9D9505C9466E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07C2B482-2F0F-4B66-9F09-9D9505C9466E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
62 changes: 62 additions & 0 deletions expensereport-csharp/expensereport-csharp/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;

namespace expensereport_csharp
{
public enum ExpenseType
{
DINNER, BREAKFAST, CAR_RENTAL
}

public class Expense
{
public ExpenseType type;
public int amount;
}

public class ExpenseReport
{
public void PrintReport(List<Expense> expenses)
{
int total = 0;
int mealExpenses = 0;

Console.WriteLine("Expenses " + DateTime.Now);

foreach (Expense expense in expenses)
{
if (expense.type == ExpenseType.DINNER || expense.type == ExpenseType.BREAKFAST)
{
mealExpenses += expense.amount;
}

String expenseName = "";
switch (expense.type)
{
case ExpenseType.DINNER:
expenseName = "Dinner";
break;
case ExpenseType.BREAKFAST:
expenseName = "Breakfast";
break;
case ExpenseType.CAR_RENTAL:
expenseName = "Car Rental";
break;
}

String mealOverExpensesMarker =
expense.type == ExpenseType.DINNER && expense.amount > 5000 ||
expense.type == ExpenseType.BREAKFAST && expense.amount > 1000
? "X"
: " ";

Console.WriteLine(expenseName + "\t" + expense.amount + "\t" + mealOverExpensesMarker);

total += expense.amount;
}

Console.WriteLine("Meal expenses: " + mealExpenses);
Console.WriteLine("Total expenses: " + total);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>expensereport_csharp</RootNamespace>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions expensereport-csharp/expensereport-ut/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using NUnit.Framework;

namespace Tests
{
public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public void Test1()
{
Assert.Pass();
}
}
}
15 changes: 15 additions & 0 deletions expensereport-csharp/expensereport-ut/expensereport-ut.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0"/>
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0"/>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions expensereport-cxx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.[adios]
55 changes: 55 additions & 0 deletions expensereport-cxx/ExpenseReport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <chrono>
#include <iostream>
#include <iterator>
#include <list>

using namespace std;

enum Type
{
BREAKFAST, DINNER, CAR_RENTAL
};

class Expense
{
public:
Type type;
int amount;
};

void printReport(list<Expense> expenses)
{
int total = 0;
int mealExpenses = 0;

auto now = chrono::system_clock::to_time_t(chrono::system_clock::now());
cout << "Expenses " << ctime(&now) << '\n';

for (list<Expense>::iterator expense = expenses.begin(); expense != expenses.end(); ++expense) {
if (expense->type == BREAKFAST || expense->type == DINNER) {
mealExpenses += expense->amount;
}

string expenseName = "";
switch (expense->type) {
case DINNER:
expenseName = "Dinner";
break;
case BREAKFAST:
expenseName = "Breakfast";
break;
case CAR_RENTAL:
expenseName = "Car Rental";
break;
}

string mealOverExpensesMarker = (expense->type == DINNER && expense->amount > 5000) || (expense->type == BREAKFAST && expense->amount > 1000) ? "X" : " ";

cout << expenseName << '\t' << expense->amount << '\t' << mealOverExpensesMarker << '\n';

total += expense->amount;
}

cout << "Meal expenses: " << mealExpenses << '\n';
cout << "Total expenses: " << total << '\n';
}
11 changes: 11 additions & 0 deletions expensereport-cxx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CPPFLAGS:=-MMD
CXXFLAGS:=-W -Wall -pedantic -Werror

.PHONY: all
all: ExpenseReport.o

.PHONY: clean
clean::
$(RM) *.[adios]

-include *.d
3 changes: 3 additions & 0 deletions expensereport-cxx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Expense Report C++

Kata for Coding Dojos.
3 changes: 3 additions & 0 deletions expensereport-go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: all
all:
go build ./...
3 changes: 3 additions & 0 deletions expensereport-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Expense Report Go

Kata for Coding Dojos.
55 changes: 55 additions & 0 deletions expensereport-go/expenses/expensereport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package expenses

import (
"fmt"
"time"
)

type Type int

const (
DINNER Type = iota + 1
BREAKFAST
CAR_RENTAL
)

type Expense struct {
Type Type
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 CAR_RENTAL:
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.Println("Meal expenses: %d\n", mealExpenses)
fmt.Println("Total expenses: %d\n", total)
}
9 changes: 9 additions & 0 deletions expensereport-java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# IntelliJ IDEA
.idea
*.iml

# make
.User.mk

# Maven
target/
Loading

0 comments on commit 29ecc2f

Please sign in to comment.