This repository has been archived by the owner on Apr 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
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
10 changed files
with
1,078 additions
and
1,061 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,107 @@ | ||
package concrete_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gonum/graph" | ||
"github.com/gonum/graph/concrete" | ||
) | ||
|
||
// Asserts that out concrete graphs implement the correct interfaces | ||
var _ graph.DirectedGraph = (*concrete.GonumGraph)(nil) | ||
var _ graph.MutableGraph = (*concrete.GonumGraph)(nil) | ||
var _ graph.UndirectedGraph = (*concrete.TileGraph)(nil) | ||
|
||
func TestTileGraph(t *testing.T) { | ||
tg := concrete.NewTileGraph(4, 4, false) | ||
|
||
if tg == nil || tg.String() != "▀▀▀▀\n▀▀▀▀\n▀▀▀▀\n▀▀▀▀" { | ||
t.Fatal("Tile graph not generated correctly") | ||
} | ||
|
||
tg.SetPassability(0, 1, true) | ||
if tg == nil || tg.String() != "▀ ▀▀\n▀▀▀▀\n▀▀▀▀\n▀▀▀▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
tg.SetPassability(0, 1, false) | ||
if tg == nil || tg.String() != "▀▀▀▀\n▀▀▀▀\n▀▀▀▀\n▀▀▀▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
tg.SetPassability(0, 1, true) | ||
if tg == nil || tg.String() != "▀ ▀▀\n▀▀▀▀\n▀▀▀▀\n▀▀▀▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
tg.SetPassability(0, 2, true) | ||
if tg == nil || tg.String() != "▀ ▀\n▀▀▀▀\n▀▀▀▀\n▀▀▀▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
tg.SetPassability(1, 2, true) | ||
if tg == nil || tg.String() != "▀ ▀\n▀▀ ▀\n▀▀▀▀\n▀▀▀▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
tg.SetPassability(2, 2, true) | ||
if tg == nil || tg.String() != "▀ ▀\n▀▀ ▀\n▀▀ ▀\n▀▀▀▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
tg.SetPassability(3, 2, true) | ||
if tg == nil || tg.String() != "▀ ▀\n▀▀ ▀\n▀▀ ▀\n▀▀ ▀" { | ||
t.Fatal("Passability set incorrectly") | ||
} | ||
|
||
if tg2, err := concrete.GenerateTileGraph("▀ ▀\n▀▀ ▀\n▀▀ ▀\n▀▀ ▀"); err != nil { | ||
t.Error("Tile graph errored on interpreting valid template string\n▀ ▀\n▀▀ ▀\n▀▀ ▀\n▀▀ ▀") | ||
} else if tg2.String() != "▀ ▀\n▀▀ ▀\n▀▀ ▀\n▀▀ ▀" { | ||
t.Error("Tile graph failed to generate properly with input string\n▀ ▀\n▀▀ ▀\n▀▀ ▀\n▀▀ ▀") | ||
} | ||
|
||
if tg.CoordsToID(0, 0) != 0 { | ||
t.Error("Coords to ID fails on 0,0") | ||
} else if tg.CoordsToID(3, 3) != 15 { | ||
t.Error("Coords to ID fails on 3,3") | ||
} else if tg.CoordsToID(0, 3) != 3 { | ||
t.Error("Coords to ID fails on 0,3") | ||
} else if tg.CoordsToID(3, 0) != 12 { | ||
t.Error("Coords to ID fails on 3,0") | ||
} | ||
|
||
if r, c := tg.IDToCoords(0); r != 0 || c != 0 { | ||
t.Error("ID to Coords fails on 0,0") | ||
} else if r, c := tg.IDToCoords(15); r != 3 || c != 3 { | ||
t.Error("ID to Coords fails on 3,3") | ||
} else if r, c := tg.IDToCoords(3); r != 0 || c != 3 { | ||
t.Error("ID to Coords fails on 0,3") | ||
} else if r, c := tg.IDToCoords(12); r != 3 || c != 0 { | ||
t.Error("ID to Coords fails on 3,0") | ||
} | ||
|
||
if succ := tg.Neighbors(concrete.GonumNode(0)); succ != nil || len(succ) != 0 { | ||
t.Error("Successors for impassable tile not 0") | ||
} | ||
|
||
if succ := tg.Neighbors(concrete.GonumNode(2)); succ == nil || len(succ) != 2 { | ||
t.Error("Incorrect number of successors for (0,2)") | ||
} else { | ||
for _, s := range succ { | ||
if s.ID() != 1 && s.ID() != 6 { | ||
t.Error("Successor for (0,2) neither (0,1) nor (1,2)") | ||
} | ||
} | ||
} | ||
|
||
if tg.Degree(concrete.GonumNode(2)) != 4 { | ||
t.Error("Degree returns incorrect number for (0,2)") | ||
} | ||
if tg.Degree(concrete.GonumNode(1)) != 2 { | ||
t.Error("Degree returns incorrect number for (0,2)") | ||
} | ||
if tg.Degree(concrete.GonumNode(0)) != 0 { | ||
t.Error("Degree returns incorrect number for impassable tile (0,0)") | ||
} | ||
|
||
} |
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
Oops, something went wrong.