| OLD | NEW |
| 1 package model | 1 package model |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "encoding/json" | 4 "encoding/json" |
| 5 "errors" | 5 "errors" |
| 6 "math" |
| 6 "strings" | 7 "strings" |
| 7 ) | 8 ) |
| 8 | 9 |
| 9 // FullResult represents "full_results.json". | 10 // FullResult represents "full_results.json". |
| 10 type FullResult struct { | 11 type FullResult struct { |
| 11 Version int `json:"version"` | 12 Version int `json:"version"` |
| 12 Builder string `json:"builder_name"` | 13 Builder string `json:"builder_name"` |
| 13 BuildNumber Number `json:"build_number"` | 14 BuildNumber Number `json:"build_number"` |
| 14 SecondsEpoch int64 `json:"seconds_since_epoch"` | 15 SecondsEpoch int64 `json:"seconds_since_epoch"` |
| 15 Tests FullTest `json:"tests"` | 16 Tests FullTest `json:"tests"` |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 277 } |
| 277 ret.Results = []ResultSummary{{1, shortFailures}} | 278 ret.Results = []ResultSummary{{1, shortFailures}} |
| 278 | 279 |
| 279 if len(l.Bugs) > 0 { | 280 if len(l.Bugs) > 0 { |
| 280 ret.Bugs = make([]string, len(l.Bugs)) | 281 ret.Bugs = make([]string, len(l.Bugs)) |
| 281 copy(ret.Bugs, l.Bugs) | 282 copy(ret.Bugs, l.Bugs) |
| 282 } | 283 } |
| 283 | 284 |
| 284 var time float64 | 285 var time float64 |
| 285 if l.Runtime != nil { | 286 if l.Runtime != nil { |
| 286 » » time = *l.Runtime | 287 » » time = float64(round(*l.Runtime)) |
| 287 } | 288 } |
| 288 ret.Runtimes = []RuntimeSummary{{1, time}} | 289 ret.Runtimes = []RuntimeSummary{{1, time}} |
| 289 | 290 |
| 290 return ret, nil | 291 return ret, nil |
| 291 } | 292 } |
| 292 | 293 |
| 294 func round(f float64) int { |
| 295 if math.Abs(f) < 0.5 { |
| 296 return 0 |
| 297 } |
| 298 return int(f + math.Copysign(0.5, f)) |
| 299 } |
| 300 |
| 293 // MarshalJSON marshals l into JSON. | 301 // MarshalJSON marshals l into JSON. |
| 294 func (l *FullTestLeaf) MarshalJSON() ([]byte, error) { | 302 func (l *FullTestLeaf) MarshalJSON() ([]byte, error) { |
| 295 aux := testResultAux{fullTestLeafAlias: (*fullTestLeafAlias)(l)} | 303 aux := testResultAux{fullTestLeafAlias: (*fullTestLeafAlias)(l)} |
| 296 aux.Actual = strings.Join(l.Actual, " ") | 304 aux.Actual = strings.Join(l.Actual, " ") |
| 297 aux.Expected = strings.Join(l.Expected, " ") | 305 aux.Expected = strings.Join(l.Expected, " ") |
| 298 return json.Marshal(&aux) | 306 return json.Marshal(&aux) |
| 299 } | 307 } |
| 300 | 308 |
| 301 // UnmarshalJSON unmarshals the supplied data into l. | 309 // UnmarshalJSON unmarshals the supplied data into l. |
| 302 func (l *FullTestLeaf) UnmarshalJSON(data []byte) error { | 310 func (l *FullTestLeaf) UnmarshalJSON(data []byte) error { |
| 303 aux := testResultAux{fullTestLeafAlias: (*fullTestLeafAlias)(l)} | 311 aux := testResultAux{fullTestLeafAlias: (*fullTestLeafAlias)(l)} |
| 304 if err := json.Unmarshal(data, &aux); err != nil { | 312 if err := json.Unmarshal(data, &aux); err != nil { |
| 305 return err | 313 return err |
| 306 } | 314 } |
| 307 l.Actual = strings.Split(aux.Actual, " ") | 315 l.Actual = strings.Split(aux.Actual, " ") |
| 308 l.Expected = strings.Split(aux.Expected, " ") | 316 l.Expected = strings.Split(aux.Expected, " ") |
| 309 return nil | 317 return nil |
| 310 } | 318 } |
| 311 | 319 |
| 312 // Times represents "times_ms.json". | 320 // Times represents "times_ms.json". |
| 313 type Times map[string]float64 | 321 type Times map[string]float64 |
| OLD | NEW |