-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmmsi_test.go
62 lines (58 loc) · 1.73 KB
/
mmsi_test.go
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
// Copyright (c) 2015, Marios Andreopoulos.
//
// This file is part of aislib.
//
// Aislib is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Aislib is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with aislib. If not, see <http://www.gnu.org/licenses/>.
package aislib
import (
"fmt"
"testing"
)
// I didn't found a MMSI decoder, so this test is verified only by me
func TestDecodeMMSI(t *testing.T) {
cases := []struct {
MMSI uint32
reference string
}{
{227006760, "Ship, France"},
{2573425, "Coastal Station, Norway"},
{25634906, "Group of ships, Malta"},
{842517724, "Diver's radio, Iraq (Republic of)"},
{992351000, "Aids to navigation, United Kingdom of Great Britain and Northern Ireland"},
{1000010000, "Invalid MMSI"},
{972345000, "MOB —Man Overboard Device"},
{970241023, "AIS SART —Search and Rescue Transmitter, Greece"},
{971356034, "Invalid MMSI"},
}
for _, c := range cases {
got := DecodeMMSI(c.MMSI)
if got != c.reference {
fmt.Println("Got : ", got)
fmt.Println("Want: ", c.reference)
t.Errorf("DecodeMMSI(m uint32)")
}
}
}
func BenchmarkDecodeMMSI(b *testing.B) {
for i := 0; i < b.N; i++ {
switch {
case i%116 < 108:
DecodeMMSI(316013198)
case i%116 < 115:
DecodeMMSI(002241076)
default:
DecodeMMSI(992351000)
}
}
}