|
| 1 | +package wms130 |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "gopkg.in/yaml.v3" |
| 7 | +) |
| 8 | + |
| 9 | +func TestUnmarshalYAMLPosition(t *testing.T) { |
| 10 | + |
| 11 | + var tests = []struct { |
| 12 | + positionstring []byte |
| 13 | + expectedposition Position |
| 14 | + }{ |
| 15 | + 0: {positionstring: []byte(`2.52712538742158 50.2128625669452`), expectedposition: Position{2.52712538742158, 50.2128625669452}}, |
| 16 | + 1: {positionstring: []byte(`7.37402550506231 55.7211602557705`), expectedposition: Position{7.37402550506231, 55.7211602557705}}, |
| 17 | + 2: {positionstring: []byte(`7.37402550506231 55.7211602557705 0 1 2 3`), expectedposition: Position{7.37402550506231, 55.7211602557705}}, |
| 18 | + } |
| 19 | + |
| 20 | + for k, test := range tests { |
| 21 | + var pos Position |
| 22 | + err := yaml.Unmarshal(test.positionstring, &pos) |
| 23 | + if err != nil { |
| 24 | + t.Errorf("test: %d, yaml.UnMarshal failed with '%s'\n", k, err) |
| 25 | + } else { |
| 26 | + if pos != test.expectedposition { |
| 27 | + t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedposition, pos) |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func TestMarshalYAMLPosition(t *testing.T) { |
| 34 | + var tests = []struct { |
| 35 | + positionstring []byte |
| 36 | + position Position |
| 37 | + }{ |
| 38 | + 0: {positionstring: []byte("2.52712538742158 50.2128625669452\n"), position: Position{2.52712538742158, 50.2128625669452}}, |
| 39 | + 1: {positionstring: []byte("7.37402550506231 55.7211602557705\n"), position: Position{7.37402550506231, 55.7211602557705}}, |
| 40 | + } |
| 41 | + |
| 42 | + for k, test := range tests { |
| 43 | + pos, err := yaml.Marshal(test.position) |
| 44 | + if err != nil { |
| 45 | + t.Errorf("test: %d, yaml.Marshal failed with '%s'\n", k, err) |
| 46 | + } else { |
| 47 | + if string(pos) != string(test.positionstring) { |
| 48 | + t.Errorf("test: %d, expected: %s,\n got: %s", k, test.positionstring, pos) |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments