10 Commits

Author SHA1 Message Date
4f79d6f1ed Removed useless print statements 2023-08-14 15:09:24 +02:00
346cfe9705 Finally written some good tests for the image writer 2023-08-14 15:08:27 +02:00
94af003adc Added some assets 2023-08-14 15:08:13 +02:00
aec655610a Added files to gitignore 2023-08-14 15:07:10 +02:00
2423645f3a Removed log statement 2023-08-14 14:27:07 +02:00
6e0a1032d1 Figured out that the implementation of turn left
was actually dfs lol
2023-08-13 21:31:47 +02:00
69afaed1bf fixed lil mistake eheh 2023-08-11 14:34:12 +02:00
908e8c14fb Commented out image writer tests cuz i gotta think
of a good way to do them :)
2023-08-11 14:31:51 +02:00
954d44085c Fixed workflows 2023-08-11 14:29:35 +02:00
8a6543cc1e Updated the github workflows 2023-08-11 14:27:24 +02:00
14 changed files with 92 additions and 35 deletions

View File

@ -12,10 +12,18 @@ jobs:
runs-on: "ubuntu-latest"
steps:
# ...
- name: "Build & test"
run: |
echo "done!"
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- uses: "marvinpinto/action-automatic-releases@latest"
with:
@ -23,6 +31,3 @@ jobs:
automatic_release_tag: "latest"
prerelease: true
title: "Development Build"
files: |
LICENSE.txt
*.jar

View File

@ -12,15 +12,20 @@ jobs:
runs-on: "ubuntu-latest"
steps:
# ...
- name: "Build & test"
run: |
echo "done!"
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
LICENSE.txt
*.jar

2
.gitignore vendored
View File

@ -20,3 +20,5 @@
# Go workspace file
go.work
/Session.vim
/maze.png
/maze_sol.png

BIN
assets/real.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

BIN
assets/solved/normal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 987 B

BIN
assets/solved/normal2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
assets/solved/real.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

BIN
assets/solved/trivial.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

View File

@ -1,17 +1,24 @@
package writer
import (
"bytes"
"image/color"
"io"
"maze-solver/maze"
"os"
"testing"
"github.com/mazznoer/colorgrad"
)
const (
OUT_DIR = "./out"
EXPECTED_DIR = "../../assets/solved"
)
func TestImageWriter(t *testing.T) {
pathGradient, err := colorgrad.NewGradient().Colors(color.White).Build()
if err != nil {
panic(err)
if _, err := os.Stat(OUT_DIR); os.IsNotExist(err) {
os.Mkdir(OUT_DIR, 0700)
}
tests := []struct {
@ -24,33 +31,33 @@ func TestImageWriter(t *testing.T) {
}{
{
"Trivial",
"../../out/trivial_sol.png",
"trivial.png",
trivial(),
40, 40,
20, 20,
color.White, color.Black,
colorgrad.Warm(),
},
{
"Bigger",
"../../out/bigger_sol.png",
"Trivial Bigger",
"trivial-bigger.png",
bigger(),
40, 40,
20, 20,
color.White, color.Black,
colorgrad.Warm(),
},
{
"Bigger Staggered",
"../../out/bigger_staggered_sol.png",
"Trivial Bigger Staggered",
"trivial-bigger-staggered.png",
bigger_staggered(),
40, 40,
20, 20,
color.White, color.Black,
pathGradient,
colorgrad.Warm(),
},
{
"Normal",
"../../out/normal_sol.png",
"normal.png",
normal(),
40, 40,
20, 20,
color.White, color.Black,
colorgrad.Warm(),
},
@ -58,7 +65,7 @@ func TestImageWriter(t *testing.T) {
for _, test := range tests {
writer := ImageWriter{
Filename: test.filename,
Filename: OUT_DIR + "/" + test.filename,
Maze: test.m,
CellWidth: test.CellWidth,
CellHeight: test.cellHeight,
@ -71,5 +78,45 @@ func TestImageWriter(t *testing.T) {
if err != nil {
t.Fatalf("%s: couldn't write solution, got following error\n%v", test.name, err)
}
assertEqualFile(t, EXPECTED_DIR+"/"+test.filename, OUT_DIR+"/"+test.filename, test.name)
os.Remove(writer.Filename)
}
os.Remove(OUT_DIR)
}
const chunkSize = 64000
func assertEqualFile(t *testing.T, file1, file2, name string) {
f1, err := os.Open(file1)
if err != nil {
t.Fatal(err)
}
defer f1.Close()
f2, err := os.Open(file2)
if err != nil {
t.Fatal(err)
}
defer f2.Close()
for {
b1 := make([]byte, chunkSize)
_, err1 := f1.Read(b1)
b2 := make([]byte, chunkSize)
_, err2 := f2.Read(b2)
if err1 != nil || err2 != nil {
if err1 == io.EOF && err2 == io.EOF {
return
} else if err1 == io.EOF || err2 == io.EOF {
t.Fatalf("%s: files are not equal. Got %q, wanted %q", name, file1, file2)
}
}
if !bytes.Equal(b1, b2) {
t.Fatalf("%s: files are not equal. Got %q, wanted %q", name, file1, file2)
}
}
}

View File

@ -1,7 +1,6 @@
package writer
import (
"fmt"
"maze-solver/maze"
"maze-solver/utils"
"testing"
@ -69,7 +68,6 @@ func TestStringsWriter(t *testing.T) {
}
for _, test := range tests {
fmt.Printf("----------- %s -----------\n", test.name)
writer := StringsWriter{
PathChar: test.pathChar,
WallChar: test.wallChar,

View File

@ -5,11 +5,11 @@ import (
"maze-solver/utils"
)
type TurnLeftSolver struct {
type DFSSolver struct {
visited map[*maze.Node]bool
}
func (s *TurnLeftSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
func (s *DFSSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
defer utils.Timer("Turn left algorithm", 2)()
current, end := m.Nodes[0], m.Nodes[len(m.Nodes)-1]
@ -54,7 +54,7 @@ func (s *TurnLeftSolver) Solve(m *maze.Maze) *maze.SolvedMaze {
return ret
}
func (s *TurnLeftSolver) wasVisited(node *maze.Node) bool {
func (s *DFSSolver) wasVisited(node *maze.Node) bool {
if node == nil {
return true
}

View File

@ -24,7 +24,7 @@ var TYPES = []string{
func (f *SolverFactory) Get() Solver {
switch *f.Type {
case _TURN_LEFT:
return &TurnLeftSolver{}
return &DFSSolver{}
}
panic(fmt.Sprintf("Unrecognized solver type %q", *f.Type))
}