-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
253 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: AoC CI (Lint & Test) | ||
|
||
on: [ push, pull_request ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21.1 | ||
- name: Lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
test: | ||
name: Test | ||
needs: lint | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
version: ["1.18.0", "1.19.0", "1.20.0", "1.21.0", "stable"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: {{matrix.version}} | ||
- name: Build | ||
run: go build -v ./... | ||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// Package aoc provides some utilities to make the Advent of Code solutions easier, faster and shorter to solve | ||
package aoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package aoc | ||
|
||
import "testing" | ||
|
||
func TestBoolToInt(t *testing.T) { | ||
intTrue := BoolToInt(true) | ||
intFalse := BoolToInt(false) | ||
expectedTrue := 1 | ||
expectedFalse := 0 | ||
if intTrue == expectedTrue && intFalse == expectedFalse { | ||
t.Log("Successfully converted a bool value to its int representation") | ||
return | ||
} | ||
t.Errorf("Failed converting a bool value to its int representation (got: true=%d/false=%d, expected: true=%d/false=%d)", intTrue, intFalse, expectedTrue, expectedFalse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/kkrypt0nn/aoc | ||
|
||
go 1.21.1 | ||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package aoc | ||
|
||
import "testing" | ||
|
||
func TestMapSum(t *testing.T) { | ||
theMap := map[int]int{1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10} | ||
mapSum := MapSum(theMap) | ||
expected := 54 | ||
if mapSum == expected { | ||
t.Log("Successfully got the sum of the map") | ||
return | ||
} | ||
t.Errorf("Failed getting the sum of the map (got: %d, expected: %d)", mapSum, expected) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package aoc | ||
|
||
import "testing" | ||
|
||
func TestSliceContainsAll(t *testing.T) { | ||
sliceA := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
sliceB := []int{3, 7, 1} | ||
containsAll := SliceContainsAll(sliceA, sliceB) | ||
if containsAll { | ||
t.Log("Successfully checked if all the elements of slice B are in slice A") | ||
return | ||
} | ||
t.Errorf("Failed checking if all the elements of slice B are in slice A (got: %t, expected: true)", containsAll) | ||
} | ||
|
||
func TestContains(t *testing.T) { | ||
theSlice := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
element := 8 | ||
contains := SliceContains(theSlice, element) | ||
if contains { | ||
t.Log("Successfully checked if the element is contained in the slice") | ||
return | ||
} | ||
t.Errorf("Failed checking if the element is contained in the slice (got: %t, expected: true)", contains) | ||
} | ||
|
||
func TestSliceMax(t *testing.T) { | ||
theSlice := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
sliceMax := SliceMax(theSlice) | ||
expected := 10 | ||
if sliceMax == expected { | ||
t.Log("Successfully got the biggest element in the slice") | ||
return | ||
} | ||
t.Errorf("Failed getting the biggest element in the slice (got: %d, expected: %d)", sliceMax, expected) | ||
} | ||
|
||
func TestSliceMultipleMax(t *testing.T) { | ||
theSlice := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
sliceMax := SliceMultipleMax(theSlice, 2) | ||
expected := []int{9, 10} | ||
if SliceContainsAll(sliceMax, expected) && len(sliceMax) == len(expected) { | ||
t.Log("Successfully got the two biggest numbers in the slice") | ||
return | ||
} | ||
t.Errorf("Failed getting the two biggest numbers in the slice (got: %#v, expected: %#v)", sliceMax, expected) | ||
} | ||
|
||
func TestSliceMin(t *testing.T) { | ||
theSlice := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
sliceMin := SliceMin(theSlice) | ||
expected := -1 | ||
if sliceMin == expected { | ||
t.Log("Successfully got the smallest element in the slice") | ||
return | ||
} | ||
t.Errorf("Failed getting the smallest element in the slice (got: %d, expected: %d)", sliceMin, expected) | ||
} | ||
|
||
func TestSliceMultipleMin(t *testing.T) { | ||
theSlice := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
sliceMin := SliceMultipleMin(theSlice, 2) | ||
expected := []int{-1, 1} | ||
if SliceContainsAll(sliceMin, expected) && len(sliceMin) == len(expected) { | ||
t.Log("Successfully got the two smallest numbers in the slice") | ||
return | ||
} | ||
t.Errorf("Failed getting the two smallest numbers in the slice (got: %#v, expected: %#v)", sliceMin, expected) | ||
} | ||
|
||
func TestSliceSum(t *testing.T) { | ||
theSlice := []int{7, 5, 3, 9, 2, 6, 10, 8, 4, 1, -1} | ||
sliceSum := SliceSum(theSlice) | ||
expected := 54 | ||
if sliceSum == expected { | ||
t.Log("Successfully got the sum of the slice") | ||
return | ||
} | ||
t.Errorf("Failed getting the sum of the slice (got: %d, expected: %d)", sliceSum, expected) | ||
} | ||
|
||
func TestSliceReverse(t *testing.T) { | ||
theSlice := []int{7, 5, 3} | ||
sliceReverse := SliceReverse(theSlice) | ||
elementA := 3 | ||
elementB := 5 | ||
elementC := 7 | ||
if sliceReverse[0] == elementA && sliceReverse[1] == elementB && sliceReverse[2] == elementC { | ||
t.Log("Successfully reversed the slice") | ||
return | ||
} | ||
t.Errorf("Failed reversing the slice (got: %#v, expected: %#v)", sliceReverse, []int{elementA, elementB, elementC}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package aoc | ||
|
||
import "testing" | ||
|
||
func TestReverseString(t *testing.T) { | ||
name := "Krypton" | ||
reversed := ReverseString(name) | ||
expected := "notpyrK" | ||
if reversed == expected { | ||
t.Log("Successfully reversed the string") | ||
return | ||
} | ||
t.Errorf("Failed reversing the string (got: %s, expected: %s)", reversed, expected) | ||
} | ||
|
||
func TestAtoi(t *testing.T) { | ||
stringNumber := "1337" | ||
converted := Atoi(stringNumber) | ||
expected := 1337 | ||
if converted == expected { | ||
t.Log("Successfully converted a string to an integer") | ||
return | ||
} | ||
t.Errorf("Failed converting a string to an integer (got: %d, expected: %d)", converted, expected) | ||
} | ||
|
||
func TestContainsCharacters(t *testing.T) { | ||
sentence := "the quick brown fox jumps over the lazy dog" | ||
characters := "xyz" | ||
contains := ContainsCharacters(sentence, characters) | ||
if contains { | ||
t.Log("Successfully checked if the characters of the substring is contained in the sentence") | ||
return | ||
} | ||
t.Errorf("Failed checking if the characters of the substring is contained in the sentence (got: %t, expected: true)", contains) | ||
} | ||
|
||
func TestContainsExactly(t *testing.T) { | ||
sentence := "thequickbrownfxjmpsvlazydg" | ||
characters := "abcdefghijklmnopqrstuvwxyz" | ||
contains := ContainsExactly(sentence, characters) | ||
if contains { | ||
t.Log("Successfully checked if the characters are in the sentence, and have the same length") | ||
return | ||
} | ||
t.Errorf("Failed checking if the characters are in the sentence, and have the same length (got: %t, expected: true)", contains) | ||
} |