~xenrox/aoc2019

899f0b2fc5ad1838d431a7984207efd43223a1f5 — Thorben Günther 4 years ago 1a798cc
Add test case for exercise 1.
3 files changed, 126 insertions(+), 3 deletions(-)

A 1/fuel_test.go
A 1/input.txt
M 1/main.go
A 1/fuel_test.go => 1/fuel_test.go +19 -0
@@ 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")
	}
}

A 1/input.txt => 1/input.txt +100 -0
@@ 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

M 1/main.go => 1/main.go +7 -3
@@ 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"))
}