1// Copyright (c) 2017 Couchbase, 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 15package vellum 16 17import ( 18 "fmt" 19 "testing" 20) 21 22func TestEncodeDecodePackSize(t *testing.T) { 23 24 for i := 0; i <= 8; i++ { 25 for j := 0; j <= 8; j++ { 26 got := encodePackSize(i, j) 27 goti, gotj := decodePackSize(got) 28 if goti != i || gotj != j { 29 t.Errorf("failed to round trip %d,%d packed as %b to %d,%d", i, j, got, goti, gotj) 30 } 31 } 32 } 33} 34 35func TestEncodeNumTrans(t *testing.T) { 36 tests := []struct { 37 input int 38 want byte 39 }{ 40 {0, 0}, 41 {5, 5}, 42 {1<<6 - 1, 1<<6 - 1}, 43 {1 << 6, 0}, 44 } 45 46 for _, test := range tests { 47 t.Run(fmt.Sprintf("input %d", test.input), func(t *testing.T) { 48 got := encodeNumTrans(test.input) 49 if got != test.want { 50 t.Errorf("wanted: %d, got: %d", test.want, got) 51 } 52 }) 53 } 54} 55