From 899f0b2fc5ad1838d431a7984207efd43223a1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sat, 21 Dec 2019 00:28:00 +0100 Subject: [PATCH] Add test case for exercise 1. --- 1/fuel_test.go | 19 ++++++++++ 1/input.txt | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 1/main.go | 10 +++-- 3 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 1/fuel_test.go create mode 100644 1/input.txt diff --git a/1/fuel_test.go b/1/fuel_test.go new file mode 100644 index 0000000..6f356a5 --- /dev/null +++ b/1/fuel_test.go @@ -0,0 +1,19 @@ +package main + +import "testing" + +func TestFuel1(t *testing.T) { + t.Parallel() + if calcFuel(12) != 2 { + t.Error("Error") + } + if calcFuel(14) != 2 { + t.Error("Error") + } + if calcFuel(1969) != 654 { + t.Error("Error") + } + if calcFuel(100756) != 33583 { + t.Error("Error") + } +} diff --git a/1/input.txt b/1/input.txt new file mode 100644 index 0000000..2a91d86 --- /dev/null +++ b/1/input.txt @@ -0,0 +1,100 @@ +78207 +89869 +145449 +73634 +78681 +81375 +131482 +126998 +50801 +115839 +77949 +53203 +146099 +56912 +59925 +132631 +115087 +89543 +123234 +108110 +109873 +81923 +124264 +87981 +106554 +147239 +73615 +72609 +129684 +84175 +64915 +98124 +74391 +55211 +120961 +119116 +148275 +89605 +115986 +120547 +50299 +137922 +78906 +145216 +80424 +122610 +61408 +97573 +127533 +116820 +76068 +77400 +117943 +85231 +102442 +62002 +58761 +56479 +98200 +85971 +73985 +88908 +82719 +120604 +83378 +88241 +122574 +76731 +99810 +137548 +102617 +105352 +137585 +83238 +118817 +149419 +107629 +63893 +56049 +70693 +83844 +76413 +87021 +90259 +124289 +102527 +139625 +106607 +120241 +101098 +66142 +96591 +82277 +142297 +116671 +131881 +94861 +79741 +73561 +115214 diff --git a/1/main.go b/1/main.go index ba8eced..7368082 100644 --- a/1/main.go +++ b/1/main.go @@ -10,9 +10,9 @@ func calcFuel(mass int) int { return mass/3 - 2 } -func main() { +func totalFuel(input string) int { var lines []int - lines, err := tools.ScanFileInt("input.txt") + lines, err := tools.ScanFileInt(input) if err != nil { fmt.Println("Error") } @@ -20,5 +20,9 @@ func main() { for _, value := range lines { sum += calcFuel(value) } - fmt.Println(sum) + return sum +} + +func main() { + fmt.Println(totalFuel("input.txt")) } -- 2.44.0