|
| 1 | +// Copyright 2016 The Prometheus Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +package collector |
| 15 | + |
| 16 | +import "testing" |
| 17 | + |
| 18 | +type uintToStringTest struct { |
| 19 | + in uint64 |
| 20 | + out string |
| 21 | +} |
| 22 | + |
| 23 | +var uinttostringtests = []uintToStringTest{ |
| 24 | + // Copied base10 values from strconv's tests: |
| 25 | + {0, "0"}, |
| 26 | + {1, "1"}, |
| 27 | + {12345678, "12345678"}, |
| 28 | + {1<<31 - 1, "2147483647"}, |
| 29 | + {1 << 31, "2147483648"}, |
| 30 | + {1<<31 + 1, "2147483649"}, |
| 31 | + {1<<32 - 1, "4294967295"}, |
| 32 | + {1 << 32, "4294967296"}, |
| 33 | + {1<<32 + 1, "4294967297"}, |
| 34 | + {1 << 50, "1125899906842624"}, |
| 35 | + {1<<63 - 1, "9223372036854775807"}, |
| 36 | + |
| 37 | + // Some values that convert correctly on amd64, but not on i386. |
| 38 | + {0x1bf0c640a, "7500227594"}, |
| 39 | + {0xbee5df75, "3202735989"}, |
| 40 | +} |
| 41 | + |
| 42 | +func TestUintToString(t *testing.T) { |
| 43 | + for _, test := range uinttostringtests { |
| 44 | + is := convertFreeBSDCPUTime(test.in) |
| 45 | + if is != test.out { |
| 46 | + t.Errorf("convertFreeBSDCPUTime(%v) = %v want %v", |
| 47 | + test.in, is, test.out) |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments