• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark / 13642217050

03 Mar 2025 11:02PM CUT coverage: 99.261% (+0.4%) from 98.883%
13642217050

push

github

web-flow
Add more unit tests (#119)

* test entity pool capacity
* test relations panic
* test table match panics
* test register on locked world
* test cache panic
* test storage panics
* test exchange mask panics

3 of 3 new or added lines in 1 file covered. (100.0%)

5772 of 5815 relevant lines covered (99.26%)

34225.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/entity.go
1
package ecs
2

3
import "encoding/json"
4

5
type entityID uint32
6

7
var entityType = typeOf[Entity]()
8
var entitySize = sizeOf(entityType)
9

10
//var wildcard = Entity{1, 0}
11

12
// Entity identifier.
13
type Entity struct {
14
        id  entityID // Entity ID
15
        gen uint32   // Entity generation
16
}
17

18
func newEntity(id entityID) Entity {
8✔
19
        return Entity{id, 0}
8✔
20
}
8✔
21

22
// IsZero returns whether this entity is the reserved zero entity.
23
func (e Entity) IsZero() bool {
55✔
24
        return e.id == 0
55✔
25
}
55✔
26

27
// isWildcard returns whether this entity is the reserved wildcard entity.
28
func (e Entity) isWildcard() bool {
1✔
29
        return e.id == 1
1✔
30
}
1✔
31

32
// MarshalJSON returns a JSON representation of the entity, for serialization purposes.
33
//
34
// The JSON representation of an entity is a two-element array of entity ID and generation.
35
func (e Entity) MarshalJSON() ([]byte, error) {
1✔
36
        arr := [2]uint32{uint32(e.id), e.gen}
1✔
37
        jsonValue, _ := json.Marshal(arr) // Ignore the error, as we can be sure this works.
1✔
38
        return jsonValue, nil
1✔
39
}
1✔
40

41
// UnmarshalJSON into an entity.
42
//
43
// For serialization purposes only. Do not use this to create entities!
44
func (e *Entity) UnmarshalJSON(data []byte) error {
2✔
45
        arr := [2]uint32{}
2✔
46
        if err := json.Unmarshal(data, &arr); err != nil {
3✔
47
                return err
1✔
48
        }
1✔
49
        e.id = entityID(arr[0])
1✔
50
        e.gen = arr[1]
1✔
51

1✔
52
        return nil
1✔
53
}
54

55
func (e Entity) toRelation(id ID, out []RelationID) []RelationID {
35✔
56
        out = out[:0]
35✔
57
        out = append(out, RelationID{
35✔
58
                component: id,
35✔
59
                target:    Entity(e),
35✔
60
        })
35✔
61
        return out
35✔
62
}
35✔
63

64
// entityIndex denotes an entity's location by table and row index.
65
type entityIndex struct {
66
        table tableID
67
        row   uint32
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc