From 428ec93860f89400d66c9fece052badf7ef97c29 Mon Sep 17 00:00:00 2001 From: Kharec Date: Mon, 24 Nov 2025 14:05:43 +0100 Subject: [PATCH] refactor: use shared variable for input --- 2020/day01/main_test.go | 12 +++++------ 2020/day02/main_test.go | 24 ++++++++++------------ 2020/day03/main_test.go | 44 +++++++++++++++-------------------------- 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/2020/day01/main_test.go b/2020/day01/main_test.go index faca990..9830f3b 100644 --- a/2020/day01/main_test.go +++ b/2020/day01/main_test.go @@ -2,20 +2,20 @@ package main import "testing" +var testInput = []int{1721, 979, 366, 299, 675, 1456} + func TestPartOne(t *testing.T) { - input := []int{1721, 979, 366, 299, 675, 1456} expected := 514579 - got := PartOne(input) + got := PartOne(testInput) if got != expected { - t.Errorf("PartOne(%v) = %d, want %d", input, got, expected) + t.Errorf("PartOne(%v) = %d, want %d", testInput, got, expected) } } func TestPartTwo(t *testing.T) { - input := []int{1721, 979, 366, 299, 675, 1456} expected := 241861950 - got := PartTwo(input) + got := PartTwo(testInput) if got != expected { - t.Errorf("PartTwo(%v) = %d, want %d", input, got, expected) + t.Errorf("PartTwo(%v) = %d, want %d", testInput, got, expected) } } diff --git a/2020/day02/main_test.go b/2020/day02/main_test.go index fc1f549..94d867e 100644 --- a/2020/day02/main_test.go +++ b/2020/day02/main_test.go @@ -2,28 +2,24 @@ package main import "testing" +var testInput = []string{ + "1-3 a: abcde", + "1-3 b: cdefg", + "2-9 c: ccccccccc", +} + func TestPartOne(t *testing.T) { - input := []string{ - "1-3 a: abcde", - "1-3 b: cdefg", - "2-9 c: ccccccccc", - } expected := 2 - got := PartOne(input) + got := PartOne(testInput) if got != expected { - t.Errorf("PartOne(%v) = %d, want %d", input, got, expected) + t.Errorf("PartOne(%v) = %d, want %d", testInput, got, expected) } } func TestPartTwo(t *testing.T) { - input := []string{ - "1-3 a: abcde", - "1-3 b: cdefg", - "2-9 c: ccccccccc", - } expected := 1 - got := PartTwo(input) + got := PartTwo(testInput) if got != expected { - t.Errorf("PartTwo(%v) = %d, want %d", input, got, expected) + t.Errorf("PartTwo(%v) = %d, want %d", testInput, got, expected) } } diff --git a/2020/day03/main_test.go b/2020/day03/main_test.go index 196962d..c13a358 100644 --- a/2020/day03/main_test.go +++ b/2020/day03/main_test.go @@ -2,43 +2,31 @@ package main import "testing" +var testInput = []string{ + "..##.......", + "#...#...#..", + ".#....#..#.", + "..#.#...#.#", + ".#...##..#.", + "..#.##.....", + ".#.#.#....#", + ".#........#", + "#.##...#...", + "#...##....#", + ".#..#...#.#", +} + func TestPartOne(t *testing.T) { - input := []string{ - "..##.......", - "#...#...#..", - ".#....#..#.", - "..#.#...#.#", - ".#...##..#.", - "..#.##.....", - ".#.#.#....#", - ".#........#", - "#.##...#...", - "#...##....#", - ".#..#...#.#", - } expected := 7 - got := PartOne(input) + got := PartOne(testInput) if got != expected { t.Errorf("PartOne() = %d, want %d", got, expected) } } func TestPartTwo(t *testing.T) { - input := []string{ - "..##.......", - "#...#...#..", - ".#....#..#.", - "..#.#...#.#", - ".#...##..#.", - "..#.##.....", - ".#.#.#....#", - ".#........#", - "#.##...#...", - "#...##....#", - ".#..#...#.#", - } expected := 336 - got := PartTwo(input) + got := PartTwo(testInput) if got != expected { t.Errorf("PartTwo() = %d, want %d", got, expected) }