Started 2022 with go

This commit is contained in:
Karma Riuk
2023-08-02 11:50:29 +02:00
parent 567c8487b5
commit 7098b525f0
26 changed files with 6810 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package main
import (
"bufio"
"fmt"
"log"
"os"
)
type Input struct{}
func input(filename string) *Input {
file, err := os.Open(filename)
check(err, "Couldn't open %q", filename)
defer file.Close()
input := &Input{}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
line := scanner.Text()
}
return input
}
func result(inp *Input, part int8) string {
var res string
if part == 1 {
} else {
}
return res
}
func check(e error, msg string, vals ...any) {
if e != nil {
log.Printf("ERROR: "+msg, vals)
panic(e)
}
}
func main() {
result := result(input("sample1"), 1)
log.Println(result)
fmt.Println(result)
}

View File

@ -0,0 +1,38 @@
package main
import (
"reflect"
"testing"
)
func TestInputSample1(t *testing.T) {
filename := "sample1"
expected := &Input{}
var got *Input = input(filename)
if !reflect.DeepEqual(expected, got) {
t.Errorf("input(%q) = %v, want %v", filename, got, expected)
}
}
func TestResult(t *testing.T) {
tests := []struct {
part int8
filename string
expected string
}{
{1, "sample1", ""},
{1, "input", ""},
// {2, "sample1", ""},
// {2, "input", ""},
}
for _, test := range tests {
var got string = result(input(test.filename), test.part)
if got != test.expected {
t.Errorf("result = %q, want %q", got, test.expected)
}
}
}

3
2022/go/template/go.mod Normal file
View File

@ -0,0 +1,3 @@
module aoc/template
go 1.20