-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_test.go
57 lines (47 loc) · 1.78 KB
/
game_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
48
49
50
51
52
53
54
55
56
57
package dctycoon
import (
"fmt"
"testing"
"time"
"github.com/nzin/dctycoon/supplier"
"github.com/nzin/sws"
"github.com/stretchr/testify/assert"
)
func TestDemandAttribution(t *testing.T) {
quit := false
root := &sws.RootWidget{}
game := NewGame(&quit, root, false)
game.InitGame("siliconvalley", DIFFICULTY_EASY, "noname")
assert.NotEmpty(t, game, "Game created")
assert.Equal(t, 3, len(game.npactors), "3 NPC created")
assert.NotEmpty(t, game.player, "1 player created")
// change time
game.timer.CurrentTime = time.Date(1997, time.Month(01), 01, 0, 0, 0, 0, time.UTC)
// reduce to one opponent
opponent := NewNPDatacenter()
opponent.Init(game.timer, 30000, "siliconvalley", game.trends, "mono_r100_r200.json", "John Doe", true)
game.npactors = make([]*NPDatacenter, 1, 1)
game.npactors[0] = opponent
// reduce demand template to one template
demandtemplate := supplier.DemandTemplateAssetLoad("001_basicwebserver.json")
assert.NotEmpty(t, demandtemplate, "read a basic demand template")
// generate new demand
actors := make([]supplier.Actor, 0, 0)
actors = append(actors, opponent)
actors = append(actors, game.player)
demand := demandtemplate.InstanciateDemand()
serverbundle, _ := demand.FindOffer(actors, game.timer.CurrentTime)
assert.Empty(t, serverbundle, "demand created but not atributed")
// add server in inventory
opponent.NewYearOperations()
assert.Equal(t, 1, len(opponent.GetInventory().Items), "new year passed, we bought some servers")
for i := 0; i < 10; i++ {
game.timer.TimerClock()
}
fmt.Println(opponent.GetInventory().Items[0])
fmt.Println(game.timer.CurrentTime)
fmt.Println(opponent.GetOffers()[0])
serverbundle, _ = demand.FindOffer(actors, game.timer.CurrentTime)
// flaky
// assert.NotEmpty(t, serverbundle, "demand created and attributed")
}