82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
|
package main
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestGetPositiveNumber1(t *testing.T) {
|
||
|
num := GetPositiveNumber(4)
|
||
|
if num != 4 {
|
||
|
t.Errorf("Number was incorrect, got: {%d}, want: {%d}.", num, 4)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetPositiveNumber2(t *testing.T) {
|
||
|
num := GetPositiveNumber(-4)
|
||
|
if num != 4 {
|
||
|
t.Errorf("Number was incorrect, got: {%d}, want: {%d}.", num, 4)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetPositiveNumber3(t *testing.T) {
|
||
|
num := GetPositiveNumber(0)
|
||
|
if num != 0 {
|
||
|
t.Errorf("Number was incorrect, got: {%d}, want: {%d}.", num, 0)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetDistanceFromPoint1(t *testing.T) {
|
||
|
distance := GetDistanceFromPoint(Point{3, 3})
|
||
|
if distance != 6 {
|
||
|
t.Errorf("Error was incorrect, got: {%d}, want: {%d}.", distance, 6)
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetDistanceFromPoint2(t *testing.T) {
|
||
|
distance := GetDistanceFromPoint(Point{3, -3})
|
||
|
if distance != 6 {
|
||
|
t.Errorf("Distance was incorrect, got: {%d}, want: {%d}.", distance, 6)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestExample1(t *testing.T) {
|
||
|
route1 := "R75,D30,R83,U83,L12,D49,R71,U7,L72"
|
||
|
route2 := "U62,R66,U55,R34,D71,R55,D58,R83"
|
||
|
points1 := GetAllPointsFromRoute(ParseRoute(route1))
|
||
|
points2 := GetAllPointsFromRoute(ParseRoute(route2))
|
||
|
crossed := FindAllCrossedPoints(points1, points2)
|
||
|
distance := GetShortestDistanceFromPoints(crossed)
|
||
|
if distance != 159 {
|
||
|
t.Errorf("Route Distance was incorrect, got: {%d}, want: {%d}.", distance, 159)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestExample2(t *testing.T) {
|
||
|
route1 := "R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51"
|
||
|
route2 := "U98,R91,D20,R16,D67,R40,U7,R15,U6,R7"
|
||
|
points1 := GetAllPointsFromRoute(ParseRoute(route1))
|
||
|
points2 := GetAllPointsFromRoute(ParseRoute(route2))
|
||
|
crossed := FindAllCrossedPoints(points1, points2)
|
||
|
distance := GetShortestDistanceFromPoints(crossed)
|
||
|
if distance != 135 {
|
||
|
t.Errorf("Route Distance was incorrect, got: {%d}, want: {%d}.", distance, 135)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestShortesRoute1(t *testing.T) {
|
||
|
route1 := "R75,D30,R83,U83,L12,D49,R71,U7,L72"
|
||
|
route2 := "U62,R66,U55,R34,D71,R55,D58,R83"
|
||
|
distance := GetShortestRoute(route1, route2)
|
||
|
if distance != 610 {
|
||
|
t.Errorf("Route Distance was incorrect, got: {%d}, want: {%d}.", distance, 610)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestShortesRoute2(t *testing.T) {
|
||
|
route1 := "R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51"
|
||
|
route2 := "U98,R91,D20,R16,D67,R40,U7,R15,U6,R7"
|
||
|
distance := GetShortestRoute(route1, route2)
|
||
|
if distance != 410 {
|
||
|
t.Errorf("Route Distance was incorrect, got: {%d}, want: {%d}.", distance, 410)
|
||
|
}
|
||
|
}
|