File: dungeon_test.go

package info (click to toggle)
boohu 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 756 kB
  • sloc: makefile: 6
file content (91 lines) | stat: -rw-r--r-- 1,808 bytes parent folder | download | duplicates (2)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main

import (
	"bytes"
	"fmt"
	"testing"
)

var Rounds = 100

func BenchmarkCellularAutomataCaveMap(b *testing.B) {
	for i := 0; i < b.N; i++ {
		g := &game{}
		g.GenCellularAutomataCaveMap(DungeonHeight, DungeonWidth)
	}
}

func TestCellularAutomataCaveMap(t *testing.T) {
	for i := 0; i < Rounds; i++ {
		g := &game{}
		g.GenCellularAutomataCaveMap(DungeonHeight, DungeonWidth)
		if !g.Dungeon.connex() {
			t.Errorf("Not connex:\n%s\n", g.Dungeon.String())
		}
	}
}

func TestCaveMap(t *testing.T) {
	for i := 0; i < Rounds; i++ {
		g := &game{}
		g.GenCaveMap(DungeonHeight, DungeonWidth)
		if !g.Dungeon.connex() {
			t.Errorf("Not connex:\n%s\n", g.Dungeon.String())
		}
	}
}

func TestCaveMapTree(t *testing.T) {
	for i := 0; i < Rounds; i++ {
		g := &game{}
		g.GenCaveMapTree(DungeonHeight, DungeonWidth)
		if !g.Dungeon.connex() {
			t.Errorf("Not connex:\n%s\n", g.Dungeon.String())
		}
	}
}

func TestRuinsMap(t *testing.T) {
	for i := 0; i < Rounds; i++ {
		g := &game{}
		g.GenRuinsMap(DungeonHeight, DungeonWidth)
		if !g.Dungeon.connex() {
			t.Errorf("Not connex:\n%s\n", g.Dungeon.String())
		}
	}
}

func TestBSPMap(t *testing.T) {
	for i := 0; i < Rounds; i++ {
		g := &game{}
		g.GenBSPMap(DungeonHeight, DungeonWidth)
		if !g.Dungeon.connex() {
			t.Errorf("Not connex:\n%s\n", g.Dungeon.String())
		}
	}
}

func (d *dungeon) String() string {
	b := &bytes.Buffer{}
	for i, c := range d.Cells {
		if i > 0 && i%DungeonWidth == 0 {
			fmt.Fprint(b, "\n")
		}
		if c.T == WallCell {
			fmt.Fprint(b, "#")
		} else {
			fmt.Fprint(b, ".")
		}
	}
	return b.String()
}

func TestRoomMap(t *testing.T) {
	for i := 0; i < Rounds; i++ {
		g := &game{}
		g.GenRoomMap(DungeonHeight, DungeonWidth)
		if !g.Dungeon.connex() {
			t.Errorf("Not connex:\n%s\n", g.Dungeon.String())
		}
	}
}