-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_test.go
47 lines (41 loc) · 937 Bytes
/
level_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2020 Andrew Ekstedt
// This program is licensed under the GNU Affero General
// Public License v3.0. See LICENSE for details.
package main
import (
"bytes"
"testing"
)
func TestLevel(t *testing.T) {
var level = &Level{
Title: "Test",
TimeLimit: 500,
}
// draw a 10x10 border
for y := 0; y < 10; y++ {
for x := 0; x < 10; x++ {
if x == 0 || x == 9 || y == 0 || y == 9 {
level.Tiles[y][x] = Wall
}
}
}
level.Tiles[1][1] = Player
level.Tiles[1][2] = Block
level.Tiles[1][3] = Exit
level.Tiles[1][4] = Teleport
var buf bytes.Buffer
if err := saveLevel(&buf, level); err != nil {
t.Errorf("error saving level: %v", err)
return
}
if l, err := DecodeLevel(buf.Bytes()); err != nil {
t.Errorf("error reading level: %v", err)
if l != nil {
t.Errorf("got non-nil level despite error during decode")
}
} else {
if l == nil {
t.Errorf("got level=nil with err=nil")
}
}
}