ducky/devices

Paddy 2015-11-12 Parent:b6494e1a499e

2:426d7e3c4ecd Go to Latest

ducky/devices/vendor/code.google.com/p/go-uuid/uuid/util.go

Start testing our Storers. Set up a file to start testing our Storer implementations, and write a sample test for the happy path of GetDevices--e.g., we expect no errors. This also required us to setup a helper to compare two Device instances and see if they're equal or not, and if not, how they differ. In the future, we'll keep adding test methods to test more logical paths for the interface contract, and to test more of the methods for the interface.

History
paddy@0 1 // Copyright 2011 Google Inc. All rights reserved.
paddy@0 2 // Use of this source code is governed by a BSD-style
paddy@0 3 // license that can be found in the LICENSE file.
paddy@0 4
paddy@0 5 package uuid
paddy@0 6
paddy@0 7 import (
paddy@0 8 "io"
paddy@0 9 )
paddy@0 10
paddy@0 11 // randomBits completely fills slice b with random data.
paddy@0 12 func randomBits(b []byte) {
paddy@0 13 if _, err := io.ReadFull(rander, b); err != nil {
paddy@0 14 panic(err.Error()) // rand should never fail
paddy@0 15 }
paddy@0 16 }
paddy@0 17
paddy@0 18 // xvalues returns the value of a byte as a hexadecimal digit or 255.
paddy@0 19 var xvalues = []byte{
paddy@0 20 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 21 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 22 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 23 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
paddy@0 24 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 25 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 26 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 27 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 28 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 29 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 30 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 31 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 32 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 33 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 34 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 35 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
paddy@0 36 }
paddy@0 37
paddy@0 38 // xtob converts the the first two hex bytes of x into a byte.
paddy@0 39 func xtob(x string) (byte, bool) {
paddy@0 40 b1 := xvalues[x[0]]
paddy@0 41 b2 := xvalues[x[1]]
paddy@0 42 return (b1 << 4) | b2, b1 != 255 && b2 != 255
paddy@0 43 }