github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/hash/base32_test.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // This file incorporates work covered by the following copyright and 16 // permission notice: 17 // 18 // Copyright 2016 Attic Labs, Inc. All rights reserved. 19 // Licensed under the Apache License, version 2.0: 20 // http://www.apache.org/licenses/LICENSE-2.0 21 22 package hash 23 24 import ( 25 "testing" 26 27 "github.com/stretchr/testify/assert" 28 ) 29 30 func TestBase32Encode(t *testing.T) { 31 assert := assert.New(t) 32 33 d := make([]byte, ByteLen) 34 assert.Equal("00000000000000000000000000000000", encode(d)) 35 d[19] = 1 36 assert.Equal("00000000000000000000000000000001", encode(d)) 37 d[19] = 10 38 assert.Equal("0000000000000000000000000000000a", encode(d)) 39 d[19] = 20 40 assert.Equal("0000000000000000000000000000000k", encode(d)) 41 d[19] = 31 42 assert.Equal("0000000000000000000000000000000v", encode(d)) 43 d[19] = 32 44 assert.Equal("00000000000000000000000000000010", encode(d)) 45 d[19] = 63 46 assert.Equal("0000000000000000000000000000001v", encode(d)) 47 d[19] = 64 48 assert.Equal("00000000000000000000000000000020", encode(d)) 49 50 // Largest! 51 for i := 0; i < ByteLen; i++ { 52 d[i] = 0xff 53 } 54 assert.Equal("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv", encode(d)) 55 } 56 57 func TestBase32Decode(t *testing.T) { 58 assert := assert.New(t) 59 60 d := make([]byte, ByteLen) 61 assert.Equal(d, decode("00000000000000000000000000000000")) 62 63 d[19] = 1 64 assert.Equal(d, decode("00000000000000000000000000000001")) 65 d[19] = 10 66 assert.Equal(d, decode("0000000000000000000000000000000a")) 67 d[19] = 20 68 assert.Equal(d, decode("0000000000000000000000000000000k")) 69 d[19] = 31 70 assert.Equal(d, decode("0000000000000000000000000000000v")) 71 d[19] = 32 72 assert.Equal(d, decode("00000000000000000000000000000010")) 73 d[19] = 63 74 assert.Equal(d, decode("0000000000000000000000000000001v")) 75 d[19] = 64 76 assert.Equal(d, decode("00000000000000000000000000000020")) 77 78 // Largest! 79 for i := 0; i < ByteLen; i++ { 80 d[i] = 0xff 81 } 82 assert.Equal(d, decode("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")) 83 }