| 187 | } |
| 188 | |
| 189 | func TestMathPrepare(t *testing.T) { |
| 190 | testCases := []struct { |
| 191 | name string |
| 192 | in *Math |
| 193 | wantErr bool |
| 194 | }{ |
| 195 | { |
| 196 | name: "basic math", |
| 197 | in: &Math{ |
| 198 | M: "1 + 3", |
| 199 | W: "4 / 1", |
| 200 | Drift: "1 - 0", |
| 201 | }, |
| 202 | wantErr: false, |
| 203 | }, |
| 204 | { |
| 205 | name: "unknown function", |
| 206 | in: &Math{ |
| 207 | M: "1 + 3", |
| 208 | W: "missing(m)", |
| 209 | Drift: "1 - 0", |
| 210 | }, |
| 211 | wantErr: true, |
| 212 | }, |
| 213 | { |
| 214 | name: "known function", |
| 215 | in: &Math{ |
| 216 | M: "1 + 3", |
| 217 | W: "mean(m)", |
| 218 | Drift: "1 - 0", |
| 219 | }, |
| 220 | wantErr: false, |
| 221 | }, |
| 222 | { |
| 223 | name: "unknown variable", |
| 224 | in: &Math{ |
| 225 | M: "1 + 3", |
| 226 | W: "mean(missing)", |
| 227 | Drift: "1 - 0", |
| 228 | }, |
| 229 | wantErr: true, |
| 230 | }, |
| 231 | { |
| 232 | name: "no data", |
| 233 | in: &Math{ |
| 234 | M: "", |
| 235 | W: "", |
| 236 | Drift: "", |
| 237 | }, |
| 238 | wantErr: true, |
| 239 | }, |
| 240 | { |
| 241 | name: "all good", |
| 242 | in: &Math{ |
| 243 | M: "abs(mean(offset, 30)) + 1.0 * stddev(offset, 30) + 1.0 * stddev(delay, 10) + 1.0 * stddev(freq, 5)", |
| 244 | W: "mean(m, 30) + 4.0 * stddev(m, 30)", |
| 245 | Drift: "mean(freqchangeabs, 29)", |
| 246 | }, |