-
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: allow characters to choose what to gather * feat: add math / tests for distane
- Loading branch information
1 parent
66e8e84
commit 4e5d7d6
Showing
11 changed files
with
154 additions
and
14 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
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
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,8 @@ | ||
package math | ||
|
||
func Max(x, y int) int { | ||
if x < y { | ||
return y | ||
} | ||
return x | ||
} |
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,27 @@ | ||
package math | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMax(t *testing.T) { | ||
tests := []struct { | ||
a int | ||
b int | ||
expected int | ||
}{ | ||
{0, 1, 1}, | ||
{0, -1, 0}, | ||
{0, 10, 10}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(fmt.Sprintf("%d,%d", tt.a, tt.b), func(t *testing.T) { | ||
res := Max(tt.a, tt.b) | ||
assert.Equal(t, tt.expected, res) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package models | ||
|
||
import "math" | ||
|
||
// Coords defines X, Y map coordinates as signed integers | ||
type Coords struct { | ||
X int | ||
Y int | ||
} | ||
|
||
// CalculateDistance determines the number of moves (distance) to get | ||
// from one Coords to a second Coords using the Manhattan distance forumla | ||
func CalculateDistance(one, two Coords) int { | ||
return int(math.Abs(float64(one.X-two.X)) + math.Abs(float64(one.Y-two.Y))) | ||
} |
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,27 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCalculateDistance(t *testing.T) { | ||
tests := []struct { | ||
one Coords | ||
two Coords | ||
expected int | ||
}{ | ||
{Coords{0, 0}, Coords{0, 0}, 0}, | ||
{Coords{1, 1}, Coords{0, 0}, 2}, | ||
{Coords{-5, 1}, Coords{0, 0}, 6}, | ||
} | ||
|
||
for n, tt := range tests { | ||
t.Run(fmt.Sprintf("%d", n), func(t *testing.T) { | ||
res := CalculateDistance(tt.one, tt.two) | ||
assert.Equal(t, tt.expected, res) | ||
}) | ||
} | ||
} |
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