Skip to content

Commit

Permalink
CHORE Update address range constructor (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu authored Mar 21, 2024
1 parent 1d156d8 commit 7ddd965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
16 changes: 8 additions & 8 deletions pdu/AddressRange.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func NewAddressRange() AddressRange {
}

// NewAddressRangeWithAddr create new AddressRange.
func NewAddressRangeWithAddr(addr string) (a AddressRange, err error) {
a = NewAddressRange()
a.AddressRange = addr
return
func NewAddressRangeWithAddr(addr string) AddressRange {
ar := NewAddressRange()
ar.AddressRange = addr
return ar
}

// NewAddressRangeWithTonNpi create new AddressRange with ton, npi.
Expand All @@ -27,10 +27,10 @@ func NewAddressRangeWithTonNpi(ton, npi byte) AddressRange {
}

// NewAddressRangeWithTonNpiAddr returns new address with ton, npi, addr string.
func NewAddressRangeWithTonNpiAddr(ton, npi byte, addr string) (a AddressRange, err error) {
a = NewAddressRangeWithTonNpi(ton, npi)
a.AddressRange = addr
return
func NewAddressRangeWithTonNpiAddr(ton, npi byte, addr string) AddressRange {
ar := NewAddressRangeWithTonNpi(ton, npi)
ar.AddressRange = addr
return ar
}

// Unmarshal from buffer.
Expand Down
11 changes: 2 additions & 9 deletions pdu/AddressRange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ import (

func TestAddressRange(t *testing.T) {
t.Run("new", func(t *testing.T) {
a, err := NewAddressRangeWithAddr("abc")
require.NoError(t, err)
a := NewAddressRangeWithAddr("abc")
require.Equal(t, "abc", a.AddressRange)
})

t.Run("newWithAddr", func(t *testing.T) {
_, err := NewAddressRangeWithAddr("12345678901234567890121234567890123456789012")
require.NoError(t, err)
})

t.Run("newTonNpi", func(t *testing.T) {
a := NewAddressRangeWithTonNpi(3, 7)
a.AddressRange = "123456789"
Expand All @@ -27,8 +21,7 @@ func TestAddressRange(t *testing.T) {
})

t.Run("newTonNpiAddr", func(t *testing.T) {
a, err := NewAddressRangeWithTonNpiAddr(3, 7, "123456789")
require.NoError(t, err)
a := NewAddressRangeWithTonNpiAddr(3, 7, "123456789")
require.EqualValues(t, 3, a.Ton)
require.EqualValues(t, 7, a.Npi)
require.Equal(t, "123456789", a.AddressRange)
Expand Down

0 comments on commit 7ddd965

Please sign in to comment.