feat: solve day 1 part 1
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Package file provides useful methods for interacting with files
|
||||
package file
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ReadLines(filePath string) []string {
|
||||
lines := []string{}
|
||||
|
||||
file, openErr := os.Open(filePath)
|
||||
|
||||
if openErr != nil {
|
||||
return lines
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
|
||||
for hasLine := scanner.Scan(); hasLine; hasLine = scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
fmt.Println(line)
|
||||
lines = append(lines, line)
|
||||
}
|
||||
|
||||
return lines
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package file_test
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/StevanFreeborn/advent-of-code-2025/internal/file"
|
||||
)
|
||||
|
||||
func TestReadLines(t *testing.T) {
|
||||
expectedLines := []string{
|
||||
"hello",
|
||||
"world",
|
||||
}
|
||||
|
||||
result := file.ReadLines("test.txt")
|
||||
|
||||
if slices.Equal(result, expectedLines) == false {
|
||||
t.Errorf("got %s but expected %s", result, expectedLines)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
hello
|
||||
world
|
||||
Reference in New Issue
Block a user