Add package level And/Or calls to TopologyManager socketmask abstraction

This commit is contained in:
Kevin Klues 2019-07-18 09:06:51 -07:00
parent 434fd34e0b
commit 0edfd4be35
2 changed files with 26 additions and 0 deletions

View File

@ -171,3 +171,17 @@ func (s *socketMask) GetSockets() []int {
}
return sockets
}
//And is a package level implementation of 'and' between first and masks
func And(first SocketMask, masks ...SocketMask) SocketMask {
s := *first.(*socketMask)
s.And(masks...)
return &s
}
//Or is a package level implementation of 'or' between first and masks
func Or(first SocketMask, masks ...SocketMask) SocketMask {
s := *first.(*socketMask)
s.Or(masks...)
return &s
}

View File

@ -106,6 +106,12 @@ func TestAnd(t *testing.T) {
for _, tc := range tcases {
firstMask, _ := NewSocketMask(tc.firstMaskBit)
secondMask, _ := NewSocketMask(tc.secondMaskBit)
result := And(firstMask, secondMask)
if result.String() != string(tc.andMask) {
t.Errorf("Expected mask to be %v, got %v", tc.andMask, result)
}
firstMask.And(secondMask)
if firstMask.String() != string(tc.andMask) {
t.Errorf("Expected mask to be %v, got %v", tc.andMask, firstMask)
@ -130,6 +136,12 @@ func TestOr(t *testing.T) {
for _, tc := range tcases {
firstMask, _ := NewSocketMask(tc.firstMaskBit)
secondMask, _ := NewSocketMask(tc.secondMaskBit)
result := Or(firstMask, secondMask)
if result.String() != string(tc.orMask) {
t.Errorf("Expected mask to be %v, got %v", tc.orMask, result)
}
firstMask.Or(secondMask)
if firstMask.String() != string(tc.orMask) {
t.Errorf("Expected mask to be %v, got %v", tc.orMask, firstMask)