summaryrefslogtreecommitdiff
path: root/engine/pool/pool_test.go
blob: 4dd0ea56a9f45ecfccf4330e7b640efa08e01e11 (plain)
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
package pool

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestPool_Add(t *testing.T) {
	p := &Pool{
		Max:   10,
		Value: 3,
	}
	p.Add(4)
}

func TestPool_Add_Overflows(t *testing.T) {
	shad := &Pool{
		Max:   5,
		Value: 0,
	}
	dist := &Pool{
		OverflowsTo: shad,
		Max:         5,
		Value:       0,
	}
	dist.Add(8)
	assert.Equal(t, shad.Value, 3)
}

func TestPool_Subtract(t *testing.T) {
	p := &Pool{
		Max:   10,
		Value: 8,
	}
	p.Subtract(6)
	assert.Equal(t, 2, p.Value)
}

func TestPool_Subtract_Empties(t *testing.T) {
	p := &Pool{
		Max:   10,
		Value: 4,
	}
	p.Subtract(8)
	assert.Equal(t, 0, p.Value)
}

func TestPool_Subtract_Flows(t *testing.T) {
	dest := &Pool{
		Value: 0,
		Max:   Infinite,
	}
	p := &Pool{
		SubtractsTo: dest,
		Max:         Infinite,
		Value:       10,
	}
	p.Subtract(8)
	assert.Equal(t, 8, dest.Value)
	assert.Equal(t, 2, p.Value)
}

func TestPool_Subtract_Flows_Empties(t *testing.T) {
	dest := &Pool{
		Value: 0,
		Max:   Infinite,
	}
	p := &Pool{
		SubtractsTo: dest,
		Max:         Infinite,
		Value:       5,
	}
	p.Subtract(8)
	assert.Equal(t, 5, dest.Value)
	assert.Equal(t, 0, p.Value)
}