-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for internal packages
- Loading branch information
Showing
3 changed files
with
80 additions
and
6 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
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,55 @@ | ||
package inputs | ||
|
||
import ( | ||
"slices" | ||
"testing" | ||
) | ||
|
||
func TestExtractIntPairs(t *testing.T) { | ||
t.Run("empty input", func(t *testing.T) { | ||
input := `` | ||
_, _, err := ExtractIntPairs(input) | ||
|
||
if err == nil { | ||
t.Errorf("expected an error, didnt get one") | ||
} | ||
}) | ||
|
||
t.Run("invalid line", func(t *testing.T) { | ||
input := `123 456 789` | ||
_, _, err := ExtractIntPairs(input) | ||
|
||
if err == nil { | ||
t.Errorf("expected an error, didnt get one") | ||
} | ||
}) | ||
|
||
t.Run("invalid left column", func(t *testing.T) { | ||
input := `abc 123` | ||
_, _, err := ExtractIntPairs(input) | ||
|
||
if err == nil { | ||
t.Errorf("expected an error, didnt get one") | ||
} | ||
}) | ||
|
||
t.Run("invalid right column", func(t *testing.T) { | ||
input := `123 abc` | ||
_, _, err := ExtractIntPairs(input) | ||
|
||
if err == nil { | ||
t.Errorf("expected an error, didnt get one") | ||
} | ||
}) | ||
|
||
t.Run("test slice content", func(t *testing.T) { | ||
input := "111 222\n333 444" | ||
leftWant := []int{111, 333} | ||
rightWant := []int{222, 444} | ||
leftGot, rightGot, _ := ExtractIntPairs(input) | ||
|
||
if !slices.Equal(leftGot, leftWant) || !slices.Equal(rightGot, rightWant) { | ||
t.Errorf("Expected %v, %v, got %v, %v", leftWant, leftGot, rightWant, rightGot) | ||
} | ||
}) | ||
} |
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,25 @@ | ||
package math | ||
|
||
import "testing" | ||
|
||
func TestAbs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input int | ||
want int | ||
}{ | ||
{name: "positive number", input: 7, want: 7}, | ||
{name: "negative number", input: -5, want: 5}, | ||
{name: "zero", input: 0, want: 0}, | ||
{name: "minus zero", input: -0, want: 0}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := Abs(tt.input) | ||
if got != tt.want { | ||
t.Errorf("got %d, want %d", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |