| 114 | } |
| 115 | |
| 116 | func TestSamplePairJSON(t *testing.T) { |
| 117 | input := []struct { |
| 118 | plain string |
| 119 | value SamplePair |
| 120 | }{ |
| 121 | { |
| 122 | plain: `[1234.567,"123.1"]`, |
| 123 | value: SamplePair{ |
| 124 | Value: 123.1, |
| 125 | Timestamp: 1234567, |
| 126 | }, |
| 127 | }, |
| 128 | } |
| 129 | |
| 130 | for _, test := range input { |
| 131 | b, err := json.Marshal(test.value) |
| 132 | if err != nil { |
| 133 | t.Error(err) |
| 134 | continue |
| 135 | } |
| 136 | |
| 137 | if string(b) != test.plain { |
| 138 | t.Errorf("encoding error: expected %q, got %q", test.plain, b) |
| 139 | continue |
| 140 | } |
| 141 | |
| 142 | var sp SamplePair |
| 143 | err = json.Unmarshal(b, &sp) |
| 144 | if err != nil { |
| 145 | t.Error(err) |
| 146 | continue |
| 147 | } |
| 148 | |
| 149 | if sp != test.value { |
| 150 | t.Errorf("decoding error: expected %v, got %v", test.value, sp) |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | func TestSampleJSON(t *testing.T) { |
| 156 | input := []struct { |