Skip to content

Commit 7aad279

Browse files
committed
common: Fix Inferno.Active() returning inactive fires
1 parent c14ed43 commit 7aad279

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

common/inferno.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ func (inf Inferno) Active() Inferno {
4242

4343
res.Fires = make([]*Fire, 0, len(inf.Fires))
4444
for _, f := range inf.Fires {
45-
res.Fires = append(res.Fires, f)
45+
if f.IsBurning {
46+
res.Fires = append(res.Fires, f)
47+
}
4648
}
4749

4850
return res

common/inferno_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,37 @@ package common
33
import (
44
"testing"
55

6+
r3 "github.com/golang/geo/r3"
67
assert "github.com/stretchr/testify/assert"
78
)
89

910
func TestInfernoUniqueID(t *testing.T) {
1011
assert.NotEqual(t, NewInferno().UniqueID(), NewInferno().UniqueID(), "UniqueIDs of different infernos should be different")
1112
}
13+
14+
func TestInfernoActive(t *testing.T) {
15+
inf := Inferno{
16+
Fires: []*Fire{
17+
&Fire{
18+
IsBurning: false,
19+
Vector: r3.Vector{X: 1, Y: 2, Z: 3},
20+
},
21+
},
22+
}
23+
24+
assert.Empty(t, inf.Active().Fires, "Inferno should have no active fires")
25+
26+
activeFires := []*Fire{
27+
&Fire{
28+
IsBurning: true,
29+
Vector: r3.Vector{X: 4, Y: 5, Z: 6},
30+
},
31+
&Fire{
32+
IsBurning: true,
33+
Vector: r3.Vector{X: 7, Y: 8, Z: 9},
34+
},
35+
}
36+
inf.Fires = append(inf.Fires, activeFires...)
37+
38+
assert.Equal(t, activeFires, inf.Active().Fires, "Active inferno should contain active fires")
39+
}

0 commit comments

Comments
 (0)